AnyView

Struct AnyView 

Source
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

Source

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.

Source

pub fn is<T: 'static>(&self) -> bool

Checks if the contained view is of type T.

Source

pub fn type_id(&self) -> TypeId

Returns the TypeId of the contained view.

Source

pub fn name(&self) -> &'static str

Returns the type name of the contained view.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Trait Implementations§

Source§

impl Debug for AnyView

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for AnyView

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl View for AnyView

Source§

fn body(self, env: &Environment) -> impl View

Build this view and return the content. Read more

Auto Trait Implementations§

§

impl Freeze for AnyView

§

impl !RefUnwindSafe for AnyView

§

impl !Send for AnyView

§

impl !Sync for AnyView

§

impl Unpin for AnyView

§

impl !UnwindSafe for AnyView

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> IdentifiableExt for T

Source§

fn use_id<F, Id>(self, f: F) -> UseId<Self, F>
where F: Fn(&Self) -> Id, Id: Ord + Hash,

Wraps the value in a UseId with the provided identification function.
Source§

fn self_id(self) -> SelfId<Self>

Wraps the value in a SelfId, making the value serve as its own identifier.
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<V> IntoView for V
where V: View,

Source§

type Output = V

The resulting View type after conversion.
Source§

fn into_view(self, _env: &Environment) -> <V as IntoView>::Output

Converts the implementing type into a View. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.