pub trait CastNone: Sized {
    type Inner;

    // Required methods
    fn and_downcast<T>(self) -> Option<T>
       where T: ObjectType,
             Self::Inner: CanDowncast<T>;
    fn and_downcast_ref<T>(&self) -> Option<&T>
       where T: ObjectType,
             Self::Inner: CanDowncast<T>;
    fn and_upcast<T>(self) -> Option<T>
       where T: ObjectType,
             Self::Inner: IsA<T>;
    fn and_upcast_ref<T>(&self) -> Option<&T>
       where T: ObjectType,
             Self::Inner: IsA<T>;
    fn and_dynamic_cast<T>(self) -> Result<T, Self>
       where T: ObjectType;
    fn and_dynamic_cast_ref<T>(&self) -> Option<&T>
       where T: ObjectType;
}
Expand description

Convenience trait mirroring Cast, implemented on Option<Object> types.

Warning

Inveitably this trait will discard informations about a downcast failure: you don’t know if the object was not of the expected type, or if it was None. If you need to handle the downcast error, use Cast over a glib::Object.

Example

let widget: Option<Widget> = list_item.child();

// Without using `CastNone`
let label = widget.unwrap().downcast::<gtk::Label>().unwrap();

// Using `CastNone` we can avoid the first `unwrap()` call
let label = widget.and_downcast::<gtk::Label>().unwrap();

Required Associated Types§

type Inner

Required Methods§

fn and_downcast<T>(self) -> Option<T>where T: ObjectType, Self::Inner: CanDowncast<T>,

fn and_downcast_ref<T>(&self) -> Option<&T>where T: ObjectType, Self::Inner: CanDowncast<T>,

fn and_upcast<T>(self) -> Option<T>where T: ObjectType, Self::Inner: IsA<T>,

fn and_upcast_ref<T>(&self) -> Option<&T>where T: ObjectType, Self::Inner: IsA<T>,

fn and_dynamic_cast<T>(self) -> Result<T, Self>where T: ObjectType,

fn and_dynamic_cast_ref<T>(&self) -> Option<&T>where T: ObjectType,

Implementors§

§

impl<I> CastNone for Option<I>where I: ObjectType,

§

type Inner = I