Macro inventory::submit

source ·
macro_rules! submit {
    ($($value:tt)*) => { ... };
}
Expand description

Enter an element into the plugin registry corresponding to its type.

This call may be in the same crate that defines the type, or downstream in any crate that depends on that crate.

This macro does not “run” anything so place it outside of any function body. In particular, note that all submit! invocations across all source files linked into your application all take effect simultaneously. A submit! invocation is not a statement that needs to be called from main in order to execute.

§Examples

Put submit! invocations outside of any function body.

inventory::submit! {
    Flag::new('v', "verbose")
}

Do not try to invoke submit! from inside of a function body as it does not do what you want.

// Do not do this.
fn submit_flags(has_verbose_flag: bool) {
    if has_verbose_flag {
        inventory::submit! {
            Flag::new('v', "verbose")
        }
    }
}

Refer to the crate level documentation for a complete example of instantiating and iterating a plugin registry.