mirror of
https://github.com/chatmail/core.git
synced 2026-05-02 04:46:29 +03:00
Add .strdup() method to Option<AsRef<str>>
We already have a .strdup() method on AsRef<str>, this adds this method also to an option of this. In case the option is None a NULL pointer is returned. This is done by using a new trait, as the type system otherwise considers such an implementation conflicting with the existing one.
This commit is contained in:
committed by
holger krekel
parent
2977ceb459
commit
e2f1ea1444
@@ -3227,7 +3227,7 @@ pub unsafe extern "C" fn dc_lot_get_text1(lot: *mut dc_lot_t) -> *mut libc::c_ch
|
||||
}
|
||||
|
||||
let lot = &*lot;
|
||||
strdup_opt(lot.get_text1())
|
||||
lot.get_text1().strdup()
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
@@ -3238,7 +3238,7 @@ pub unsafe extern "C" fn dc_lot_get_text2(lot: *mut dc_lot_t) -> *mut libc::c_ch
|
||||
}
|
||||
|
||||
let lot = &*lot;
|
||||
strdup_opt(lot.get_text2())
|
||||
lot.get_text2().strdup()
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
@@ -3323,13 +3323,6 @@ impl<T: Default, E: std::fmt::Display> ResultExt<T, E> for Result<T, E> {
|
||||
}
|
||||
}
|
||||
|
||||
unsafe fn strdup_opt(s: Option<impl AsRef<str>>) -> *mut libc::c_char {
|
||||
match s {
|
||||
Some(s) => s.as_ref().strdup(),
|
||||
None => ptr::null_mut(),
|
||||
}
|
||||
}
|
||||
|
||||
trait ResultNullableExt<T> {
|
||||
fn into_raw(self) -> *mut T;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user