[][src]Struct ondrop::OnDrop

pub struct OnDrop<F: FnOnce()>(_);

Calls the wrapped closure when dropped.

That's it.

Examples

Test that Box does in fact drop its contents:

let mut drops = 0;
let boxed = Box::new(OnDrop::new(|| {
    drops += 1;
}));

drop(boxed);

assert_eq!(drops, 1);

Methods

impl<F: FnOnce()> OnDrop<F>[src]

pub fn new(f: F) -> Self[src]

Creates a new OnDrop from a closure.

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

Unwraps the closure without calling it.

Examples

let dropper = OnDrop::new(|| panic!());
dropper.into_inner(); // no panic

Trait Implementations

impl<F: Clone + FnOnce()> Clone for OnDrop<F>[src]

impl<F: Debug + FnOnce()> Debug for OnDrop<F>[src]

impl<F: Default + FnOnce()> Default for OnDrop<F>[src]

impl<F: FnOnce()> Drop for OnDrop<F>[src]

impl<F: Eq + FnOnce()> Eq for OnDrop<F>[src]

impl<F: Hash + FnOnce()> Hash for OnDrop<F>[src]

impl<F: Ord + FnOnce()> Ord for OnDrop<F>[src]

impl<F: PartialEq + FnOnce()> PartialEq<OnDrop<F>> for OnDrop<F>[src]

impl<F: PartialOrd + FnOnce()> PartialOrd<OnDrop<F>> for OnDrop<F>[src]

impl<F: FnOnce()> StructuralEq for OnDrop<F>[src]

impl<F: FnOnce()> StructuralPartialEq for OnDrop<F>[src]

Auto Trait Implementations

impl<F> RefUnwindSafe for OnDrop<F> where
    F: RefUnwindSafe

impl<F> Send for OnDrop<F> where
    F: Send

impl<F> Sync for OnDrop<F> where
    F: Sync

impl<F> Unpin for OnDrop<F> where
    F: Unpin

impl<F> UnwindSafe for OnDrop<F> where
    F: UnwindSafe

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.