Macro slog_extlog::impl_value_wrapper
[−]
[src]
macro_rules! impl_value_wrapper { ($new:ident, ?($inner:tt)*) => { ... }; ($new:ident, ($inner:tt)*) => { ... }; }
Generate a slog::Value trait implementation for a type we don't
own but which implements std::fmt::Display or std::fmt::Debug.
This allows using types from third-party crates as values in external logs. The macro defines
a new wrapper type to be used in external logs, which does implement slog::Value.
For example, if you want to use the (fictional) foo crate and log errors from it, then write:
ⓘThis example is not tested
#[macro_use] extern crate slog_extlog; extern crate foo; impl_value_wrapper!(FooError, foo::Error);
Then anywhere you want to log a foo::Error, you can instead use FooError(foo::Error) - the
logged value will use foo:Error's impl of Display.
For a type which implements Debug but not Display, then you can use a ? character:
ⓘThis example is not tested
impl_value_wrapper!(FooInternal, ?foo::InternalType);
Note: this macro can be deprecated once default impl is available and
this issue is fixed.