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 trait have 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 dyn Serializer) -> Result {
serializer.emit_i64(key, self.0)
}
}See also KV for formatting both the key and value.
Required Methods§
Implementations on Foreign Types§
Source§impl Value for SocketAddr
Available on crate feature std only.
impl Value for SocketAddr
Available on crate feature
std only.Implementors§
impl<E> Value for ErrorRef<'_, E>where
E: 'static + StdError,
Available on
has_std_error only.impl<E> Value for ErrorValue<E>where
E: 'static + StdError,
Available on
has_std_error only.impl<F> Value for PushFnValue<F>
impl<T> Value for Serde<T>
Available on crate feature
nested-values only.