[][src]Macro libimagutil::generate_option_logging_extension

macro_rules! generate_option_logging_extension {
    {
        $name: ident,
        $map_name: ident,
        $map_str_name: ident,
        $closure: expr
    } => { ... };
}

This macro is used to generate extensions for the Option<T> type which only have sideeffects.

This macro is then used to generate debug/info/log/warning/etc extensions.

It is exported, so other crates can use it to generate more specific extensions for Option<T> types

Parameters

The documentation for the parameters of the macro follow.

$name

name of the trait to generate

$map_name

Name of the function which is generated to call the closure with.

This function gets &T from Option<T> and can now build the argument for $closure. So, this function can, for example, |e| format!("Look here: {:?}", e), the Option gets fed to $closure.

$map_str_name

Name of the function which is generated to call the closure with.

This function gets simply a &str which gets fed to the $closure later. So it can be used to foo().$map_str_name("Something happened")

$closure

The closure which should be called when mapping.

This closure can now do things, but the return value of the closure is discarded. So, this closure can be used for its sideeffects (logging for example) only.

An example would be: |element| debug!("Element: {:?}", element).