AnyBox

Struct AnyBox 

Source
pub struct AnyBox<M: SendMarker = ()> { /* private fields */ }
Expand description

A container for any instance works similar to C++’s std::any and is made to replace Arc<dyn Any>. The key difference from Arc<dyn Any> is that small instances (up to 8 bytes) are stored in the AnyBox instance

Implementations§

Source§

impl AnyBox<()>

Source

pub fn new<T: Send + Sized + 'static>(item: T) -> Self

Source§

impl AnyBox<NoSend>

Source

pub fn new_nosend<T: Sized + 'static>(item: T) -> Self

Source§

impl<M: SendMarker> AnyBox<M>

Source

pub fn empty() -> Self

Creates an empty box (initialized with empty tuple) - can be used for delayed initialization. The instance doesn’t require a drop call as the empty tuple instance will be places inte the box’s internal storage, and the tuple instance doesn’t require dropping.

Source

pub fn get_type_id(&self) -> TypeId

Returns a TypeId instance associated with a stored value.

Source

pub fn is_empty(&self) -> bool

Checks whether the instance holds nothing

Source

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

Checks whether the instance holds an instance of a type T

Source

pub fn get<T: Sized + 'static>(&self) -> Option<&T>

Returns a borrow of a stored value if it’s an instance of a type T

Source

pub unsafe fn get_unchecked<T: Sized + 'static>(&self) -> &T

Returns a borrow of a stored value if it’s an instance of a type T

§Safety:

User must be sure that the instance holds a value of T

Source

pub fn get_mut<T: Sized + 'static>(&mut self) -> Option<&mut T>

Source

pub unsafe fn get_mut_unchecked<T: Sized + 'static>(&mut self) -> &mut T

Source

pub fn take<T: Sized + 'static>(self) -> Result<T, Self>

Source

pub unsafe fn take_unchecked<T: Sized + 'static>(self) -> T

Trait Implementations§

Source§

impl<M: Debug + SendMarker> Debug for AnyBox<M>

Source§

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

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

impl Display for AnyBox

Source§

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

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

impl<M: SendMarker> Drop for AnyBox<M>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl<M> Freeze for AnyBox<M>

§

impl<M> RefUnwindSafe for AnyBox<M>
where M: RefUnwindSafe,

§

impl<M> Send for AnyBox<M>
where M: Send,

§

impl<M> Sync for AnyBox<M>
where M: Sync,

§

impl<M> Unpin for AnyBox<M>
where M: Unpin,

§

impl<M> UnwindSafe for AnyBox<M>
where M: UnwindSafe,

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, 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<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. 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.