[][src]Struct vptr::ThinBox

#[repr(transparent)]
pub struct ThinBox<Trait: ?Sized + 'static>(_, _);

A Box of a trait with a size of size_of::<usize>

The ThinBox can be created from a Box which implement the HasVPtr

trait Shape { fn area(&self) -> f32; }
#[vptr(Shape)]
#[derive(Default)]
struct Rectangle { w: f32, h : f32 }
impl Shape for Rectangle { fn area(&self) -> f32 { self.w * self.h } }

let r = Box::new(Rectangle { w: 5., h: 10., ..Default::default() });
let thin = ThinBox::from_box(r);
assert_eq!(thin.area(), 50.);

The size is the size of a pointer

assert_eq!(mem::size_of::<ThinBox<dyn Trait>>(), mem::size_of::<usize>());
assert_eq!(mem::size_of::<Option<ThinBox<dyn Trait>>>(), mem::size_of::<usize>());

Methods

impl<Trait: ?Sized + 'static> ThinBox<Trait>[src]

pub fn from_box<T: HasVPtr<Trait>>(f: Box<T>) -> Self[src]

Creates a ThinBox from a Box

pub fn into_box(b: ThinBox<Trait>) -> Box<Trait>[src]

Conver the ThinBox into a Box

pub fn as_thin_ref(b: &ThinBox<Trait>) -> ThinRef<Trait>[src]

As a ThinRef

pub fn as_thin_ref_mut(b: &mut ThinBox<Trait>) -> ThinRefMut<Trait>[src]

As a ThinRefMut

Trait Implementations

impl<Trait: ?Sized + 'static> Drop for ThinBox<Trait>[src]

impl<Trait: ?Sized + 'static> Deref for ThinBox<Trait>[src]

type Target = Trait

The resulting type after dereferencing.

impl<Trait: ?Sized + 'static> DerefMut for ThinBox<Trait>[src]

Auto Trait Implementations

impl<Trait> !Send for ThinBox<Trait>

impl<Trait> !Sync for ThinBox<Trait>

impl<Trait: ?Sized> Unpin for ThinBox<Trait>

impl<Trait: ?Sized> RefUnwindSafe for ThinBox<Trait> where
    Trait: RefUnwindSafe

impl<Trait: ?Sized> UnwindSafe for ThinBox<Trait> where
    Trait: RefUnwindSafe

Blanket Implementations

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]