glib::object

Trait CastNone

Source
pub trait CastNone: Sized {
    type Inner;

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

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

§Warning

Inevitably this trait will discard information 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§

Required Methods§

Source

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

Source

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

Source

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

Source

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

Source

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

Source

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

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl<I: ObjectType + Sized> CastNone for Option<I>

Source§

type Inner = I

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Implementors§