[−][src]Struct simple_on_shutdown::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]
Auto Trait Implementations
impl !RefUnwindSafe for OnShutdownCallback
[src]
impl !Send for OnShutdownCallback
[src]
impl !Sync for OnShutdownCallback
[src]
impl Unpin for OnShutdownCallback
[src]
impl !UnwindSafe for OnShutdownCallback
[src]
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,