pub trait Value {
// Required method
fn serialize(
&self,
record: &Record<'_>,
key: Key,
serializer: &mut dyn Serializer,
) -> Result;
}
Expand description
Value that can be serialized
Types that implement this type implement custom serialization in the
structured part of the log macros. Without an implementation of Value
for
your type you must emit using either the ?
“debug”, #?
“pretty-debug”,
%
“display”, #%
“alternate display” or SerdeValue
(if you have the nested-values
feature enabled) formatters.
§Example
use slog::{Key, Value, Record, Result, Serializer};
struct MyNewType(i64);
impl Value for MyNewType {
fn serialize(&self, _rec: &Record, key: Key, serializer: &mut Serializer) -> Result {
serializer.emit_i64(key, self.0)
}
}
See also KV
for formatting both the key and value.