[][src]Struct thinbox::ThinBox

pub struct ThinBox<T: ?Sized> { /* fields omitted */ }

A consistently-sized pointer type for heap allocation.

See the crate documentation for an example using ThinBox.

Implementations

impl<T: ?Sized> ThinBox<T>[src]

pub fn unsize<U: Unsize<T>>(value: U) -> Self[src]

Creates a new ThinBox by unsizing a value and placing it on the heap.

pub unsafe fn from_raw(raw: *mut ()) -> Self[src]

Recovers ThinBox ownership of a boxed pointee.

Along with into_raw, this function provides one of the core operations which makes ThinBox useful for interoperation with foreign functions.

Safety

  • raw must be result of Box::<U>::into_raw as *mut () or ThinBox::<U>::into_raw where U safe to transmute into T.
  • The alignment requirements of T must not be more strict than those of U.
  • It must be generally safe to dereference raw, keeping in mind that raw does not actually point to () and does not necessarily even point to a U.

The first requirement implies that:

Furthermore, support for Box::<U>::into_raw is not guaranteed to be preserved across major versions of thinbox.

pub fn into_raw(thin: Self) -> *mut ()[src]

Converts the ThinBox to a single-pointer-sized representation.

Along with from_raw, this function provides one of the core operations which makes ThinBox useful for interoperation with foreign functions.

Notes

It is not safe to dereference this representation. The type of the pointee depends not only on T but also on whether or not T is Sized.

pub fn as_ptr(thin: &Self) -> *mut T[src]

Obtains a raw pointer to the boxed value.

The pointee remains owned by the ThinBox. If you wish to relinquish ownership, use into_raw or leak.

Notes

This method returns a raw mutable pointer, which is dangerous to use. However ThinBox is guaranteed to never store an internal reference to its owned value so dereferencing this pointer does not necessarily cause undefined behavior.

pub fn leak<'a>(thin: Self) -> &'a mut T[src]

Leaks the contained value in a manner similar to Box::leak.

Unlike Box::leak, if T is unsized it is not valid to pass the returned reference to Box::from_raw or ThinBox::from_raw.

To restore a ThinBox from the reference produced by this function use unleak.

pub unsafe fn unleak(leaked: &mut T) -> Self[src]

Restores a ThinBox from a reference created by leak.

Safety

  • If T is Sized, this method behaves as-if from_raw was invoked on leaked.
  • If T is unsized, leaked must have been produced by calling ThinBox::<T>::leak. Any difference in the ThinBox type signatures involved will result in undefined behavior in all but the most contrived of cases.

pub unsafe fn transmute_into<U>(thin: Self, dest: *mut U)[src]

Moves the owned value into dest by transmuting it into the Sized type U.

Notes

  • The value pointed to by dest, if any, is not dropped.
  • The owned value of the ThinBox does not need to be properly aligned as a U.

Safety

Immediate undefined behavior occurs if U is larger in size than the owned value or if dest is not valid for writes. Otherwise any undefined behavior is deferred to later operations which dereference dest and thereby observe the result of the transmutation.

impl<T> ThinBox<T>[src]

pub fn new(value: T) -> Self[src]

Creates a new ThinBox by moving a Sized value to the heap.

Notes

Doing this passes up your opportunity to coerce the value to an unsized type, thereby defeating most of the usefulness of ThinBox. Instead, you should consider using Box unless you are constrained by some other code which requires instances of ThinBox.

pub fn from_box(boxed: Box<T>) -> Self[src]

Converts a Sized Box into a ThinBox.

Notes

This operation is zero-cost. 💸

pub fn into_box(thin: Self) -> Box<T>[src]

Converts a Sized ThinBox into a Box.

Notes

This operation is zero-cost. 💸

pub fn into_inner(thin: Self) -> T[src]

Moves the owned value out of a Sized ThinBox.

Trait Implementations

impl<T: ?Sized> AsMut<T> for ThinBox<T>[src]

impl<T: ?Sized> AsRef<T> for ThinBox<T>[src]

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

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

impl<T: Clone> Clone for ThinBox<T>[src]

impl<T: Debug + ?Sized> Debug for ThinBox<T>[src]

impl<T: ?Sized> Deref for ThinBox<T>[src]

type Target = T

The resulting type after dereferencing.

impl<T: ?Sized> DerefMut for ThinBox<T>[src]

impl<T: Display + ?Sized> Display for ThinBox<T>[src]

impl<T: ?Sized> Drop for ThinBox<T>[src]

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

impl<T: Hash + ?Sized> Hash for ThinBox<T>[src]

impl<T: ?Sized> Pointer for ThinBox<T>[src]

impl<T: Send + ?Sized> Send for ThinBox<T>[src]

impl<T: Sync + ?Sized> Sync for ThinBox<T>[src]

impl<T: UnwindSafe + ?Sized> UnwindSafe for ThinBox<T>[src]

Auto Trait Implementations

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

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

Blanket Implementations

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

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

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

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

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

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

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T> ToString for T where
    T: Display + ?Sized
[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.