mirror of
https://github.com/chatmail/core.git
synced 2026-04-17 13:36:30 +03:00
add function to convert NULL-able c-string to Option<String>
This commit is contained in:
committed by
Floris Bruynooghe
parent
bb08b39c71
commit
0108b4724e
@@ -735,6 +735,14 @@ pub fn to_string_lossy(s: *const libc::c_char) -> String {
|
||||
cstr.to_string_lossy().to_string()
|
||||
}
|
||||
|
||||
pub fn to_opt_string_lossy(s: *const libc::c_char) -> Option<String> {
|
||||
if s.is_null() {
|
||||
return None;
|
||||
}
|
||||
|
||||
Some(to_string_lossy(s))
|
||||
}
|
||||
|
||||
pub fn as_str<'a>(s: *const libc::c_char) -> &'a str {
|
||||
as_str_safe(s).unwrap_or_else(|err| panic!("{}", err))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user