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<M: SendMarker> AnyBox<M>
impl<M: SendMarker> AnyBox<M>
Sourcepub fn empty() -> Self
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.
Sourcepub fn get_type_id(&self) -> TypeId
pub fn get_type_id(&self) -> TypeId
Returns a TypeId
instance associated with a stored value.
Sourcepub fn is<T: Sized + 'static>(&self) -> bool
pub fn is<T: Sized + 'static>(&self) -> bool
Checks whether the instance holds an instance of a type T
Sourcepub fn get<T: Sized + 'static>(&self) -> Option<&T>
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
Sourcepub unsafe fn get_unchecked<T: Sized + 'static>(&self) -> &T
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