AnyView

Trait AnyView 

Source
pub trait AnyView {
    // Required methods
    fn as_any(&self) -> &(dyn Any + 'static);
    fn as_any_mut(&mut self) -> &mut (dyn Any + 'static);
    fn as_boxed_any(self: Box<Self>) -> Box<dyn Any>;
}
Expand description

A view that can be downcasted to its concrete type.

This trait is automatically implemented for any T: View.

Required Methods§

Source

fn as_any(&self) -> &(dyn Any + 'static)

Downcast self to a Any.

Source

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Downcast self to a mutable Any.

Source

fn as_boxed_any(self: Box<Self>) -> Box<dyn Any>

Returns a boxed any from a boxed self.

Can be used before Box::downcast().

§Examples
let boxed: Box<dyn View> = Box::new(TextView::new("text"));
let text: Box<TextView> = boxed.as_boxed_any().downcast().unwrap();

Implementations§

Source§

impl dyn AnyView

Source

pub fn downcast_ref<T>(&self) -> Option<&T>
where T: Any,

Attempts to downcast self to a concrete type.

Source

pub fn downcast_mut<T>(&mut self) -> Option<&mut T>
where T: Any,

Attempts to downcast self to a concrete type.

Source

pub fn downcast<T>(self: Box<dyn AnyView>) -> Result<Box<T>, Box<dyn AnyView>>
where T: Any,

Attempts to downcast Box<Self> to a concrete type.

Source

pub fn is<T>(&mut self) -> bool
where T: Any,

Checks if this view is of type T.

Implementors§

Source§

impl<T> AnyView for T
where T: View,