pub struct StackAny<const N: usize> { /* private fields */ }
Expand description
A convertible type that owns a stack allocation of N
size.
Implementations§
Source§impl<const N: usize> StackAny<N>
impl<const N: usize> StackAny<N>
Sourcepub fn try_new<T>(value: T) -> Option<Self>where
T: Any,
pub fn try_new<T>(value: T) -> Option<Self>where
T: Any,
Allocates N-size memory on the stack and then places value
into it.
Returns None if T
size is larger than N.
§Examples
let five = stack_any::StackAny::<{ std::mem::size_of::<i32>() }>::try_new(5);
Sourcepub fn downcast_ref<T>(&self) -> Option<&T>where
T: Any,
pub fn downcast_ref<T>(&self) -> Option<&T>where
T: Any,
Attempt to return reference to the inner value as a concrete type.
Returns None if T
is not equal to contained value type.
§Examples
let five = stack_any::stack_any!(i32, 5);
assert_eq!(five.downcast_ref::<i32>(), Some(&5));
assert_eq!(five.downcast_ref::<i64>(), None);
Sourcepub fn downcast_mut<T>(&mut self) -> Option<&mut T>where
T: Any,
pub fn downcast_mut<T>(&mut self) -> Option<&mut T>where
T: Any,
Attempt to return mutable reference to the inner value as a concrete type.
Returns None if T
is not equal to contained value type.
§Examples
let mut five = stack_any::stack_any!(i32, 5);
assert_eq!(five.downcast_mut::<i32>(), Some(&mut 5));
assert_eq!(five.downcast_mut::<i64>(), None);
Trait Implementations§
Auto Trait Implementations§
impl<const N: usize> Freeze for StackAny<N>
impl<const N: usize> RefUnwindSafe for StackAny<N>
impl<const N: usize> Send for StackAny<N>
impl<const N: usize> Sync for StackAny<N>
impl<const N: usize> Unpin for StackAny<N>
impl<const N: usize> UnwindSafe for StackAny<N>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more