[][src]Struct simple_on_shutdown::OnShutdownCallback

pub struct OnShutdownCallback(_);

Simple type that holds a closure (callback). The closure gets invoked during drop(). This works also fine with applications that do gracefully shutdown via signals, like SIGTERM.

Create this type via on_shutdown!(println!("foobar")) or on_shutdown!({e1; e2; e3; println!("foobar")}). See on_shutdown and on_shutdown_move for more info.

This crate uses the log crate on the debug level.

IMPORTANT: Use this on the top level of your main() or whatever your current runtimes main function is! The code gets executed when the context it lives in gets dropped. This can be called multiple times (at least with stable Rust 1.48.0) without problem.

Example:

use simple_on_shutdown::on_shutdown;

fn main() {
    // some code ...

    // Important that the returned value of the macro lives through
    // the whole lifetime of main(). It gets dropped in the end.
    on_shutdown!(println!("shut down with success"));

    // can be used multiple times
    on_shutdown!(println!("shut down with success"));
    on_shutdown!({println!("blocks also work")});
    // some code ...
}

Trait Implementations

impl Drop for OnShutdownCallback[src]

pub fn drop(&mut self)[src]

Executes the specified callback.

Auto Trait Implementations

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.