Struct slog::ser::PushLazy [] [src]

pub struct PushLazy<F>(pub F);

A newtype for non-return based lazy values

It's more natural for closures used as lazy values to return Serialize implementing type, 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.

Unfortunately, as one struct can implement many different closure traits, a newtype has to be used to prevent ambiguity.

Generally this method should be used only if it avoids a big allocation of Serialize-implementing type in performance-critical logging statement.

TODO: Can PushLazy be avoided?

Trait Implementations

impl<F> Serialize for PushLazy<F> where F: 'static + for<'c, 'd> Fn(&'c Record<'d>, ValueSerializer<'c>) -> Result<()Error>

Serialize self into Serializer Read more

impl<F> SyncSerialize for PushLazy<F> where F: 'static + Sync + Send + for<'c, 'd> Fn(&'c Record<'d>, ValueSerializer<'c>) -> Result<()Error>