Struct ThinBox

pub struct ThinBox<T: ?Sized> { pub(in ::boxed::thin) ptr: WithOpaqueHeader, pub(in ::boxed::thin) _marker: PhantomData<T> }

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

Fields

ptr: WithOpaqueHeader
_marker: PhantomData<T>

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<T: ?Sized> ThinBox<T>

fn meta(&self) -> <T as Pointee>::Metadata
fn data(&self) -> *mut u8
fn with_header(&self) -> &WithHeader<<T as Pointee>::Metadata>

Trait Implementations

impl<T> From<T> for ThinBox<T>

fn from(value: T) -> Self

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

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

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

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

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

fn source(&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>

type Target = T;
fn deref(&self) -> &T

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

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

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

fn drop(&mut self)

Auto Trait Implementations

impl<T> Freeze for ThinBox<T> where PhantomData<T>: Freeze, T: ?Sized,

impl<T> RefUnwindSafe for ThinBox<T> where PhantomData<T>: RefUnwindSafe, T: ?Sized,

impl<T> Unpin for ThinBox<T> where PhantomData<T>: Unpin, T: ?Sized,

impl<T> UnsafeUnpin for ThinBox<T> where PhantomData<T>: UnsafeUnpin, T: ?Sized,

impl<T> UnwindSafe for ThinBox<T> where PhantomData<T>: UnwindSafe, T: ?Sized,

Blanket Implementations

impl<P, T> Receiver for ThinBox<T> where P: Deref<Target = T> + ?Sized, T: ?Sized,

type Target = T;

impl<T> Any for ThinBox<T> where T: 'static + ?Sized,

fn type_id(&self) -> TypeId

impl<T> Borrow<T> for ThinBox<T> where T: ?Sized,

fn borrow(&self) -> &T

impl<T> BorrowMut<T> for ThinBox<T> where T: ?Sized,

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

impl<T> From<T> for ThinBox<T>

fn from(t: T) -> T

Returns the argument unchanged.

impl<T> From<never> for ThinBox<T>

fn from(t: never) -> T

impl<T> SizeHint for ThinBox<T> where T: ?Sized,

fn lower_bound(&self) -> usize
fn upper_bound(&self) -> Option<usize>

impl<T> SizedTypeProperties for ThinBox<T>

impl<T> ToString for ThinBox<T> where T: Display + ?Sized,

fn to_string(&self) -> String

impl<T, U> Into<U> for ThinBox<T> where U: From<T>,

fn into(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<U> for ThinBox<T> where U: Into<T>,

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

impl<T, U> TryInto<U> for ThinBox<T> where U: TryFrom<T>,

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