[−][src]Trait stakker_log::Visitable
This trait allows a stakker::LogVisitor
to visit various
fundamental Rust types and collections.
This allows all of those types to be used as values in the logging
macros. It does this by mapping them to the fixed set of kv_*
methods available on the stakker::LogVisitor
. Most fundamental
Rust types, plus map-like and array-like collections have a
straightforward mapping. Integer types larger than 64-bits are
output as strings. Option
is handled by including the key-value
pair for Some
, or omitting it for None
.
For other types which must be formatted as a string, construct a
std::fmt::Arguments
instance using format_args!
first, and
then visit that. For your own complex types which need structured
output, you should write your own Visitable
implementation.
For example:
var1.visit("key1", visitor); // Handle according to type
var2.visit("key2", visitor);
format_args!("{}", var3).visit("key3", visitor); // Display formatting
format_args!("{:?}", var4).visit("key4", visitor); // Debug formatting