[−][src]Struct no_alloc::BoxS
A box that exists entirely on the stack.
Implementations
impl<T, M> BoxS<T, M> where
M: Memory,
[src]
M: Memory,
pub fn new(x: T) -> Self
[src]
Acquires memory on the stack and places x
into it.
The acquired memory is backed by M
. If the size or alignment of T
is greater than that of M
the box cannot be constructed. This will
reuslt in a compile fail.
If T
is zero-sized then no memory is required; M
may also be zero
sized in this case.
Examples
Creating a boxed value:
use no_alloc::BoxS; let boxed: BoxS<isize, [usize; 1]> = BoxS::new(0);
Creating a boxed ZST (zero-sized type):
use no_alloc::BoxS; let boxed: BoxS<(), [usize; 0]> = BoxS::new(());
Failing to create a boxed value due to size error (this results in a compile error):
use no_alloc::BoxS; let _impossible = BoxS::<isize, [u8; 0]>::new(0);
Failing to create a boxed value due to alignment error (this results in a compile error):
use core::mem::size_of; use no_alloc::BoxS; let _impossible = BoxS::<isize, [u8; size_of::<isize>()]>::new(0);
Coercing to a boxed DST (dynamically-sized type) (requires the
coerce_unsized
feature):
use core::any::Any; use no_alloc::BoxS; let boxed: BoxS<dyn Any, [usize; 1]> = BoxS::new(0_isize);
impl<M> BoxS<dyn Any + 'static, M> where
M: Memory,
[src]
M: Memory,
pub fn downcast<T>(self) -> Result<BoxS<T, M>, Self> where
T: Any,
[src]
T: Any,
Attempts to downcast the box to a concrete type.
Examples
use core::any::Any; use core::fmt; use no_alloc::{BoxS, Memory}; fn write_if_str<W: fmt::Write, M: Memory>( mut wtr: W, boxed: BoxS<dyn Any + 'static, M> ) -> fmt::Result { if let Ok(s) = boxed.downcast::<&str>() { wtr.write_str(&s)?; } Ok(()) }
impl<M> BoxS<dyn Any + Send + 'static, M> where
M: Memory,
[src]
M: Memory,
pub fn downcast<T>(self) -> Result<BoxS<T, M>, Self> where
T: Any,
[src]
T: Any,
Attempts to downcast the box to a concrete type.
Examples
use core::any::Any; use core::fmt; use no_alloc::{BoxS, Memory}; fn write_if_str<W: fmt::Write, M: Memory>( mut wtr: W, boxed: BoxS<dyn Any + Send + 'static, M> ) -> fmt::Result { if let Ok(s) = boxed.downcast::<&str>() { wtr.write_str(&s)?; } Ok(()) }
Trait Implementations
impl<T: ?Sized, M> Debug for BoxS<T, M> where
T: Debug,
M: Memory,
[src]
T: Debug,
M: Memory,
impl<T, M> Deref for BoxS<T, M> where
T: ?Sized,
M: Memory,
[src]
T: ?Sized,
M: Memory,
impl<T, M> DerefMut for BoxS<T, M> where
T: ?Sized,
M: Memory,
[src]
T: ?Sized,
M: Memory,
impl<T: ?Sized, M> Display for BoxS<T, M> where
T: Display,
M: Memory,
[src]
T: Display,
M: Memory,
impl<T, M> Drop for BoxS<T, M> where
T: ?Sized,
M: Memory,
[src]
T: ?Sized,
M: Memory,
impl<T, M> Pointer for BoxS<T, M> where
T: ?Sized,
M: Memory,
[src]
T: ?Sized,
M: Memory,
impl<T: ?Sized, M> Send for BoxS<T, M> where
T: Send,
M: Memory,
[src]
T: Send,
M: Memory,
impl<T: ?Sized, M> Sync for BoxS<T, M> where
T: Sync,
M: Memory,
[src]
T: Sync,
M: Memory,
Auto Trait Implementations
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,