Skip to content

Commit

Permalink
glib: Implement IntoGlibPtr for Option<T>
Browse files Browse the repository at this point in the history
  • Loading branch information
sdroege committed Dec 12, 2022
1 parent b0098e2 commit d593895
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions glib/src/translate.rs
Expand Up @@ -579,6 +579,15 @@ pub trait IntoGlibPtr<P: Ptr> {
unsafe fn into_glib_ptr(self) -> P;
}

impl<P: Ptr, T: IntoGlibPtr<P>> IntoGlibPtr<P> for Option<T> {
#[inline]
unsafe fn into_glib_ptr(self) -> P {
self.map_or(Ptr::from::<()>(ptr::null_mut()), |s| {
IntoGlibPtr::into_glib_ptr(s)
})
}
}

impl GlibPtrDefault for str {
type GlibType = *mut c_char;
}
Expand Down

0 comments on commit d593895

Please sign in to comment.