pub struct AnyView(/* private fields */);Expand description
A type-erased wrapper for a View.
This allows storing and passing around different view types uniformly.
Implementations§
Source§impl AnyView
impl AnyView
Sourcepub fn new<V: View>(view: V) -> Self
pub fn new<V: View>(view: V) -> Self
Creates a new AnyView from any type that implements View.
If the provided view is already an AnyView, it will be unwrapped
to avoid unnecessary nesting.
Sourcepub fn stretch_axis(&self) -> StretchAxis
pub fn stretch_axis(&self) -> StretchAxis
Returns the stretch axis of the contained view.
This delegates to the View::stretch_axis() method of the wrapped view,
which for native views returns their layout stretch behavior.
Sourcepub unsafe fn downcast_unchecked<T: 'static>(self) -> Box<T>
pub unsafe fn downcast_unchecked<T: 'static>(self) -> Box<T>
Downcasts AnyView to a concrete view type without any runtime checks.
§Safety
Calling this method with the incorrect type is undefined behavior.
Sourcepub const unsafe fn downcast_ref_unchecked<T: 'static>(&self) -> &T
pub const unsafe fn downcast_ref_unchecked<T: 'static>(&self) -> &T
Returns a reference to the contained view without any runtime checks.
§Safety
Calling this method with the incorrect type is undefined behavior.
Sourcepub const unsafe fn downcast_mut_unchecked<T: 'static>(&mut self) -> &mut T
pub const unsafe fn downcast_mut_unchecked<T: 'static>(&mut self) -> &mut T
Returns a mutable reference to the contained view without any runtime checks.
§Safety
Calling this method with the incorrect type is undefined behavior.
Sourcepub fn downcast<T: 'static>(self) -> Result<Box<T>, Self>
pub fn downcast<T: 'static>(self) -> Result<Box<T>, Self>
Attempts to downcast AnyView to a concrete view type.
Returns Ok with the boxed value if the types match, or
Err with the original AnyView if the types don’t match.
§Errors
Returns Err(Self) if the contained type does not match T.
Sourcepub fn downcast_ref<T: 'static>(&self) -> Option<&T>
pub fn downcast_ref<T: 'static>(&self) -> Option<&T>
Attempts to get a reference to the contained view of a specific type.
Returns Some if the types match, or None if they don’t.
Sourcepub fn downcast_mut<T: 'static>(&mut self) -> Option<&mut T>
pub fn downcast_mut<T: 'static>(&mut self) -> Option<&mut T>
Attempts to get a mutable reference to the contained view of a specific type.
Returns Some if the types match, or None if they don’t.