Macro gclient::ext::sp_core::defer

macro_rules! defer {
    ( $( $code:tt )* ) => { ... };
}
Expand description

Executes the given code when the current scope is dropped.

Multiple calls to crate::defer! will execute the passed codes in reverse order. This also applies to panic stack unwinding.

ยงExample

use sp_core::defer;

let message = std::cell::RefCell::new("".to_string());
{
	defer!(
		message.borrow_mut().push_str("world!");
	);
	defer!(
		message.borrow_mut().push_str("Hello ");
	);
}
assert_eq!(*message.borrow(), "Hello world!");