Struct maybe_box::MaybeBox
[−]
[src]
pub struct MaybeBox<T> { /* fields omitted */ }
Hold a value of type T
in the space for a usize
, only boxing it if necessary.
This can be a useful optimization when dealing with C APIs that allow you to pass around some
arbitrary void *
-sized piece of data.
This type is guranteed to be the same size as a usize
.
Methods
impl<T> MaybeBox<T>
[src]
fn new(t: T) -> MaybeBox<T>
Wrap a T
into a MaybeBox<T>
. This will allocate if
size_of::<T>() > size_of::<usize>()
.
fn into_inner(self) -> T
Consume the MaybeBox<T>
and return the inner T
.
fn unpack(self) -> Unpacked<T>
Consume the MaybeBox<T>
and return the inner T
, possibly boxed (if
it was already).
This may be more efficient than calling into_inner
and then boxing
the returned value.
Trait Implementations
impl<T> Drop for MaybeBox<T>
[src]
impl<T> From<T> for MaybeBox<T>
[src]
impl<T> Deref for MaybeBox<T>
[src]
type Target = T
The resulting type after dereferencing
fn deref(&self) -> &T
The method called to dereference a value
impl<T> DerefMut for MaybeBox<T>
[src]
fn deref_mut(&mut self) -> &mut T
The method called to mutably dereference a value
impl<T: Debug> Debug for MaybeBox<T>
[src]
impl<U, T: PartialEq<U>> PartialEq<MaybeBox<U>> for MaybeBox<T>
[src]
fn eq(&self, other: &MaybeBox<U>) -> bool
This method tests for self
and other
values to be equal, and is used by ==
. Read more
fn ne(&self, other: &MaybeBox<U>) -> bool
This method tests for !=
.