Struct ThinBox

struct ThinBox<T: ?Sized> { ... }

ThinBox.

A thin pointer for heap allocation, regardless of T.

Examples

#![feature(thin_box)]
use std::boxed::ThinBox;

let five = ThinBox::new(5);
let thin_slice = ThinBox::<[i32]>::new_unsize([1, 2, 3, 4]);

let size_of_ptr = size_of::<*const ()>();
assert_eq!(size_of_ptr, size_of_val(&five));
assert_eq!(size_of_ptr, size_of_val(&thin_slice));

Implementations

impl<Dyn: ?Sized> ThinBox<Dyn>

fn new_unsize<T>(value: T) -> Self
where
    T: Unsize<Dyn>

Moves a type to the heap with its Metadata stored in the heap allocation instead of on the stack.

Examples

#![feature(thin_box)]
use std::boxed::ThinBox;

let thin_slice = ThinBox::<[i32]>::new_unsize([1, 2, 3, 4]);

impl<T> ThinBox<T>

fn new(value: T) -> Self

Moves a type to the heap with its Metadata stored in the heap allocation instead of on the stack.

Examples

#![feature(thin_box)]
use std::boxed::ThinBox;

let five = ThinBox::new(5);
fn try_new(value: T) -> Result<Self, AllocError>

Moves a type to the heap with its Metadata stored in the heap allocation instead of on the stack. Returns an error if allocation fails, instead of aborting.

Examples

#![feature(allocator_api)]
#![feature(thin_box)]
use std::boxed::ThinBox;

let five = ThinBox::try_new(5)?;
# Ok::<(), std::alloc::AllocError>(())

impl<P, T> Receiver for ThinBox<T>

impl<T> Any for ThinBox<T>

fn type_id(self: &Self) -> TypeId

impl<T> Borrow for ThinBox<T>

fn borrow(self: &Self) -> &T

impl<T> BorrowMut for ThinBox<T>

fn borrow_mut(self: &mut Self) -> &mut T

impl<T> Freeze for ThinBox<T>

impl<T> From for ThinBox<T>

fn from(t: T) -> T

Returns the argument unchanged.

impl<T> RefUnwindSafe for ThinBox<T>

impl<T> ToString for ThinBox<T>

fn to_string(self: &Self) -> String

impl<T> Unpin for ThinBox<T>

impl<T> UnsafeUnpin for ThinBox<T>

impl<T> UnwindSafe for ThinBox<T>

impl<T, U> Into for ThinBox<T>

fn into(self: Self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of [From]<T> for U chooses to do.

impl<T, U> TryFrom for ThinBox<T>

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

impl<T, U> TryInto for ThinBox<T>

fn try_into(self: Self) -> Result<U, <U as TryFrom<T>>::Error>

impl<T: ?Sized + Debug> Debug for ThinBox<T>

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

impl<T: ?Sized + Display> Display for ThinBox<T>

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

impl<T: ?Sized + Error> Error for ThinBox<T>

fn source(self: &Self) -> Option<&dyn Error + 'static>

impl<T: ?Sized + Send> Send for ThinBox<T>

impl<T: ?Sized + Sync> Sync for ThinBox<T>

impl<T: ?Sized> Deref for ThinBox<T>

fn deref(self: &Self) -> &T

impl<T: ?Sized> DerefMut for ThinBox<T>

fn deref_mut(self: &mut Self) -> &mut T

impl<T: ?Sized> Drop for ThinBox<T>

fn drop(self: &mut Self)