Skip to content

Commit 3cc1064

Browse files
sdroegebilelmoussaoui
authored andcommitted
glib: Implement IntoGlibPtr for Option<T>
1 parent 419f13f commit 3cc1064

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

glib/src/translate.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -579,6 +579,15 @@ pub trait IntoGlibPtr<P: Ptr> {
579579
unsafe fn into_glib_ptr(self) -> P;
580580
}
581581

582+
impl<P: Ptr, T: IntoGlibPtr<P>> IntoGlibPtr<P> for Option<T> {
583+
#[inline]
584+
unsafe fn into_glib_ptr(self) -> P {
585+
self.map_or(Ptr::from::<()>(ptr::null_mut()), |s| {
586+
IntoGlibPtr::into_glib_ptr(s)
587+
})
588+
}
589+
}
590+
582591
impl GlibPtrDefault for str {
583592
type GlibType = *mut c_char;
584593
}

0 commit comments

Comments
 (0)