Struct slog::PushFnValue
[−]
[src]
pub struct PushFnValue<F>(pub F) where F: 'static + for<'c, 'd> Fn(&'c Record<'d>, PushFnSerializer<'c>) -> Result;
Lazy Value
that writes to Serializer
It's more natural for closures used as lazy values to return type
implementing Serialize
, but sometimes that forces an allocation (eg.
Strings)
In some cases it might make sense for another closure form to be used - one taking a serializer as an argument, which avoids lifetimes / allocation issues.
Generally this method should be used if it avoids a big allocation of
Serialize
-implementing type in performance-critical logging statement.
#[macro_use] extern crate slog; use slog::{PushFnValue, Logger, Discard}; fn main() { let _root = Logger::root(Discard, o!( )); info!(_root, "foo"; "writer_closure" => PushFnValue(|_ , s| { let generated_string = format!("{}", 1); s.serialize(generated_string.as_str()) })); }