[][src]Struct phantomdrop::PhantomDrop

pub struct PhantomDrop<T, F: FnOnce(T)>(_);

When dropped, the included function is ran with the argument held by the structure.

Notes

If both the function and the value are zero-sized (unique non-capturing closures are ZSTs), this wrapper will also be zero-sized.

Implementations

impl<F> PhantomDrop<(), F> where
    F: FnOnce(()), 
[src]

pub fn defer(fun: F) -> Self[src]

Defer a function to run when this guard is dropped.

impl<T, F> PhantomDrop<T, F> where
    F: FnOnce(T), 
[src]

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

Defer a function to run on this stored value when this guard is

pub fn into_inner(self) -> T[src]

Consume the instance into its held type without running the drop closure.

pub fn forget(self)[src]

Consume this instance without running the drop closure.

Notes

This largely has the same behaviour of core::mem::forget, however this method is preferable for instances of PhantomDrop, as it properly calls destructors for both its value and its function if needed.

pub fn as_mut(&mut self) -> &mut T[src]

Get a mutable reference to the held type.

pub fn as_ref(&self) -> &T[src]

Get a reference to the held type.

pub fn neutralise(self) -> PhantomDrop<T, fn(_: T)>[src]

Replace the function to be ran on drop with a no-op.

impl<T: 'static> PhantomDrop<T, Box<dyn FnOnce(T)>>[src]

pub fn boxed(self) -> PhantomDrop<T, Box<dyn FnOnce(T)>>[src]

Box the closure in this instance on to the heap.

pub fn neutralise_boxed(&mut self)[src]

Replace the function to be ran on drop with a no-op in place on the heap.

impl<T> PhantomDrop<T, fn(_: T)>[src]

pub fn neutralise_in_place(&mut self)[src]

Replace the function to be ran on drop with a no-op in place with no allocations.

Trait Implementations

impl<T: Clone, F: Clone + FnOnce(T)> Clone for PhantomDrop<T, F>[src]

impl<T: Debug, F: Debug + FnOnce(T)> Debug for PhantomDrop<T, F>[src]

impl<T, F> Drop for PhantomDrop<T, F> where
    F: FnOnce(T), 
[src]

Auto Trait Implementations

impl<T, F> RefUnwindSafe for PhantomDrop<T, F> where
    F: RefUnwindSafe,
    T: RefUnwindSafe
[src]

impl<T, F> Send for PhantomDrop<T, F> where
    F: Send,
    T: Send
[src]

impl<T, F> Sync for PhantomDrop<T, F> where
    F: Sync,
    T: Sync
[src]

impl<T, F> Unpin for PhantomDrop<T, F> where
    F: Unpin,
    T: Unpin
[src]

impl<T, F> UnwindSafe for PhantomDrop<T, F> where
    F: UnwindSafe,
    T: UnwindSafe
[src]

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> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

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.