[][src]Struct core_extensions::utils::RunOnDrop

pub struct RunOnDrop<T, F> where
    F: FnOnce(T), 
{ /* fields omitted */ }

A wrapper type to run a closure at the end of the scope.

This allows construction with an explicitly captured value, so that it can be used before the end of the scope.

use core_extensions::utils::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

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

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

Constructs this RunOnDrop.

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

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

Reborrows the wrapped value.

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

Reborrows the wrapped value mutably.

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

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

Trait Implementations

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

Auto Trait Implementations

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

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

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

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

impl<T, F> UnwindSafe for RunOnDrop<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, 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 error type returned when the conversion fails.

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.