[][src]Union high_mem_utils::Catch

pub union Catch<'a, T> {
    // some fields omitted
}

An union type that can be leaked or sealed(owned),useful when you want to give temporal global access to a particular value.

Methods

impl<'a, T> Catch<'a, T>[src]

pub fn new(a: Box<T>) -> Self[src]

Creates a new Catch with a leak, you can lately get the underlying value and consume the Catch with the seal method.

pub fn leaked(&self) -> &&'a mut T[src]

Returns a a reference to the leaked field,'cause the only ways for construct this union returns a leaked one,for warranty never transmute stack to heap data,this method does not use transmute implicitly.

pub fn seal(self) -> Box<T>[src]

Consumes the Catch and gets the inner Box<T>,preventing the memory leak.

This does a call to transmute but,as the only ways to construct this union gives you a leaked one this never trigger undefined behavior by itself.

pub fn leak(self) -> &'a mut T[src]

Consumes the Catch and returns a mutable reference pointing to leaked data.

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

Creates a new Catch from a mutable reference to T,without checking if T is in the heap.

Safety

This function should only be used with data returned by the leak method from a safely constructed Catch or with data returned by Box::leak(t) otherwise this will trigger undefined behavior if the seal method is called.

impl<'a, T: Default> Catch<'a, T>[src]

pub fn take(&mut self) -> Box<T>[src]

Takes the sealed data and leaves T::default in their place,useful when you want to use the sealed value but you don't have ownership of the Catch.

Auto Trait Implementations

impl<'a, T> RefUnwindSafe for Catch<'a, T> where
    T: RefUnwindSafe

impl<'a, T> Send for Catch<'a, T> where
    T: Send

impl<'a, T> Sync for Catch<'a, T> where
    T: Sync

impl<'a, T> Unpin for Catch<'a, T>

impl<'a, T> !UnwindSafe for Catch<'a, 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<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.