decl_extension

Macro decl_extension 

Source
macro_rules! decl_extension {
    (
		$( #[ $attr:meta ] )*
		$vis:vis struct $ext_name:ident ($inner:ty);
		$(
			impl $ext_name_impl:ident {
				$(
					$impls:tt
				)*
			}
		)*
	) => { ... };
    (
		$( #[ $attr:meta ] )*
		$vis:vis struct $ext_name:ident;
	) => { ... };
}
Expand description

Macro for declaring an extension that usable with Extensions.

The extension will be an unit wrapper struct that implements Extension, Deref and DerefMut. The wrapped type is given by the user.

ยงExample

decl_extension! {
    /// Some test extension
    struct TestExt(String);
}

The Extension trait provides hooks that are called when starting, committing or rolling back a transaction. These can be implemented with the macro as well:

decl_extension! {
    /// Some test extension
    struct TestExtWithCallback(String);

    impl TestExtWithCallback {
        fn start_transaction(&mut self, ty: TransactionType) {
            // do something cool
        }

        // The other methods `commit_transaction` and `rollback_transaction` can also
        // be implemented in the same way.
    }
}