template_child: Add a try_get Method
This is a version of get without unwrap.
@@ -1293,17 +1293,20 @@ where
{
#[track_caller]
pub fn get(&self) -> T {
- unsafe {
- Option::<T>::from_glib_none(self.ptr)
+ self.try_get()
.expect("Failed to retrieve template child. Please check that it has been bound.")
}
- }
/// Determines if the child has been bound. This is primarily
/// useful for implementing the [`Buildable`][`crate::Buildable`] interface.
pub fn is_bound(&self) -> bool {
!self.ptr.is_null()
}
+
+ /// Returns Some(child) if the widget has been bound.
+ pub fn try_get(&self) -> Option<T> {
+ unsafe { Option::<T>::from_glib_none(self.ptr) }
+ }
}
pub trait CompositeTemplate: WidgetImpl {
