pub struct RunOnDrop<T, F> where
    F: FnOnce(T), 
{ /* private fields */ }
Available on crate feature on_drop only.
Expand description

A wrapper type that runs a closure at the end of the scope.

This takes both a value and a closure(that takes the value as a parameter), allowing you to access the value before the closure runs.

Example

use core_extensions::RunOnDrop;

fn main() { 
    let mut guard = RunOnDrop::new("Hello".to_string(), |string|{
        assert_eq!(string, "Hello, world!");
    });

    assert_eq!(guard.get(), "Hello");
     
    guard.get_mut().push_str(", world!");
}   

Implementations

Constructs this RunOnDrop.

Reborrows the wrapped value.

Reborrows the wrapped value mutably.

Extracts the wrapped value, preventing the closure from running at the end of the scope.

Trait Implementations

Executes the destructor for this type. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Available on crate feature phantom only.

Gets a PhantomData<Self>. Read more

Available on crate feature phantom only.

Gets a PhantomData<fn() -> Self>, a covariant PhantomData.

Available on crate feature phantom only.

Gets a PhantomData<fn(Self)>, a contravariant PhantomData.

Available on crate feature phantom only.

Gets a PhantomData<fn(Self) -> Self>, an invariant PhantomData.

Available on crate feature phantom only.

Gets a PhantomData<Self>. Read more

Available on crate feature phantom only.

Constructs a PhantomData<fn() -> T>, a covariant PhantomData. Read more

Available on crate feature phantom only.

Gets a PhantomData<fn(Self)>, a contravariant PhantomData. Read more

Available on crate feature phantom only.

Gets a PhantomData<fn(Self) -> Self>, an invariant PhantomData. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Available on crate feature callable only.

For calling CallRef::ref_call_, with the ability to specify the types of the arguments.. Read more

Available on crate feature callable only.

For calling CallMut::mut_call_, with the ability to specify the types of the arguments.. Read more

Available on crate feature callable only.

For calling CallInto::into_call_, with the ability to specify the types of the arguments.. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.