Struct StackAny

Source
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>

Source

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);
Source

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);
Source

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);
Source

pub fn downcast<T>(self) -> Option<T>
where T: Any,

Attempt to downcast the stack to 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::<i32>(), Some(5));

Trait Implementations§

Source§

impl<const N: usize> Debug for StackAny<N>

Source§

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

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

impl<const N: usize> Drop for StackAny<N>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

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> 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, 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.