Trait gstreamer_base::Cast[][src]

pub trait Cast: IsA<Object> {
    fn upcast<T>(self) -> T
    where
        Self: IsA<T>,
        T: StaticType + UnsafeFrom<ObjectRef> + Wrapper
, { ... }
fn upcast_ref<T>(&self) -> &T
    where
        Self: IsA<T>,
        T: StaticType + UnsafeFrom<ObjectRef> + Wrapper
, { ... }
fn downcast<T>(self) -> Result<T, Self>
    where
        Self: Downcast<T>
, { ... }
fn downcast_ref<T>(&self) -> Option<&T>
    where
        Self: Downcast<T>
, { ... }
fn is<T>(&self) -> bool
    where
        T: StaticType
, { ... }
fn dynamic_cast<T>(self) -> Result<T, Self>
    where
        T: StaticType + UnsafeFrom<ObjectRef> + Wrapper
, { ... }
fn dynamic_cast_ref<T>(&self) -> Option<&T>
    where
        T: StaticType + UnsafeFrom<ObjectRef> + Wrapper
, { ... } }

Upcasting and downcasting support.

Provides conversions up and down the class hierarchy tree.

Provided Methods

Upcasts an object to a superclass or interface T.

NOTE: This statically checks at compile-time if casting is possible. It is not always known at compile-time, whether a specific object implements an interface or not, in which case upcast would fail to compile. dynamic_cast can be used in these circumstances, which is checking the types at runtime.

Example

This example is not tested
let button = gtk::Button::new();
let widget = button.upcast::<gtk::Widget>();
Important traits for &'a mut R

Upcasts an object to a reference of its superclass or interface T.

NOTE: This statically checks at compile-time if casting is possible. It is not always known at compile-time, whether a specific object implements an interface or not, in which case upcast would fail to compile. dynamic_cast can be used in these circumstances, which is checking the types at runtime.

Example

This example is not tested
let button = gtk::Button::new();
let widget = button.upcast_ref::<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.

NOTE: This statically checks at compile-time if casting is possible. It is not always known at compile-time, whether a specific object implements an interface or not, in which case upcast would fail to compile. dynamic_cast can be used in these circumstances, which is checking the types at runtime.

Example

This example is not tested
let button = gtk::Button::new();
let widget = button.upcast::<gtk::Widget>();
assert!(widget.downcast::<gtk::Button>().is_ok());

Tries to downcast to a reference of its subclass or interface implementor T.

Returns Some(T) if the object is an instance of T and None otherwise.

NOTE: This statically checks at compile-time if casting is possible. It is not always known at compile-time, whether a specific object implements an interface or not, in which case upcast would fail to compile. dynamic_cast can be used in these circumstances, which is checking the types at runtime.

Example

This example is not tested
let button = gtk::Button::new();
let widget = button.upcast::<gtk::Widget>();
assert!(widget.downcast_ref::<gtk::Button>().is_some());

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

Tries to cast to an object of type T. This handles upcasting, downcasting and casting between interface and interface implementors. All checks are performed at runtime, while downcast and upcast will do many checks at compile-time already.

It is not always known at compile-time, whether a specific object implements an interface or not, and checking as to be performed at runtime.

Returns Ok(T) if the object is an instance of T and Err(self) otherwise.

Example

This example is not tested
let button = gtk::Button::new();
let widget = button.dynamic_cast::<gtk::Widget>();
assert!(widget.is_ok());
let widget = widget.unwrap();
assert!(widget.dynamic_cast::<gtk::Button>().is_ok());

Tries to cast to reference to an object of type T. This handles upcasting, downcasting and casting between interface and interface implementors. All checks are performed at runtime, while downcast and upcast will do many checks at compile-time already.

It is not always known at compile-time, whether a specific object implements an interface or not, and checking as to be performed at runtime.

Returns Some(T) if the object is an instance of T and None otherwise.

Example

This example is not tested
let button = gtk::Button::new();
let widget = button.dynamic_cast_ref::<gtk::Widget>();
assert!(widget.is_some());
let widget = widget.unwrap();
assert!(widget.dynamic_cast_ref::<gtk::Button>().is_some());

Implementors