Trait gtk::Cast
[−]
[src]
pub trait Cast: IsA<Object> { fn upcast<T>(self) -> T
where
Self: IsA<T>,
T: StaticType + UnsafeFrom<ObjectRef> + Wrapper, { ... } fn downcast<T>(self) -> Result<T, Self>
where
Self: Downcast<T>, { ... } fn is<T>(&self) -> bool
where
Self: Downcast<T>, { ... } }
Upcasting and downcasting support.
Provides conversions up and down the class hierarchy tree.
Provided Methods
fn upcast<T>(self) -> T where
Self: IsA<T>,
T: StaticType + UnsafeFrom<ObjectRef> + Wrapper,
Self: IsA<T>,
T: StaticType + UnsafeFrom<ObjectRef> + Wrapper,
Upcasts an object to a superclass or interface T
.
Example
let button = gtk::Button::new(); let widget = button.upcast::<gtk::Widget>();
fn downcast<T>(self) -> Result<T, Self> where
Self: Downcast<T>,
Self: Downcast<T>,
Tries to downcast to a subclass or interface implementor T
.
Returns Ok(T)
if the object is an instance of T
and Err(self)
otherwise.
Example
let button = gtk::Button::new(); let widget = button.upcast::<gtk::Widget>(); assert!(widget.downcast::<gtk::Button>().is_ok());
fn is<T>(&self) -> bool where
Self: Downcast<T>,
Self: Downcast<T>,
Returns true
if the object is an instance of (can be downcast to) T
.