Skip to content

Commit

Permalink
Add example for CastNone
Browse files Browse the repository at this point in the history
  • Loading branch information
ranfdev committed Dec 1, 2022
1 parent f248128 commit 0a35378
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions glib/src/object.rs
Expand Up @@ -290,6 +290,17 @@ impl<T: ObjectType> Cast for T {}

// rustdoc-stripper-ignore-next
/// Convenience trait mirroring `Cast`, implemented on `Option<Object>` types.
///
/// # Example
/// ```ignore
/// let widget: Option<Widget> = list_item.child();
///
/// // Without using `CastNone`
/// let label: gtk::Label = widget.unwrap().downcast().unwrap();
///
/// // Using `CastNone` we can avoid the first `unwrap()` call
/// let label: gtk::Label = widget.downcast().unwrap();
/// ````
pub trait CastNone: Sized {
type Inner;
fn downcast<T: ObjectType>(self) -> Result<T, Self>
Expand Down

0 comments on commit 0a35378

Please sign in to comment.