[go: up one dir, main page]

Trait glib::object::Cast [] [src]

pub trait Cast: IsA<Object> {
    fn upcast<T>(self) -> T where T: StaticType + UnsafeFrom<ObjectRef> + Wrapper, Self: IsA<T> { ... }
    fn downcast<T>(self) -> Result<T, Self> where Self: Sized + 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

Upcasts an object to a superclass or interface T.

Example

let button = gtk::Button::new();
let widget = button.upcast::<gtk::Widget>();

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());

Returns true if the object is an instance of (can be downcast to) T.

Implementors