pub trait Format: Send + Sync {
// Required method
fn write_record<W: Write + ?Sized>(
&self,
record: &Record<'_>,
writer: &mut W,
) -> Result;
}Expand description
A record-to-bytes serializer.
Implementors should write exactly one logical “line” (or one logical document) per call. The included sinks add no extra separators between records; formatters that produce line-oriented output are expected to emit their own trailing newline.
Required Methods§
Sourcefn write_record<W: Write + ?Sized>(
&self,
record: &Record<'_>,
writer: &mut W,
) -> Result
fn write_record<W: Write + ?Sized>( &self, record: &Record<'_>, writer: &mut W, ) -> Result
Write the record to writer using a core::fmt::Write sink.
core::fmt::Write is used (instead of std::io::Write) so that
formatters compile under no_std and can be used to format
into a String or fixed-size buffer.
§Errors
Returns core::fmt::Error if the underlying writer rejects a
write.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.
Implementations on Foreign Types§
Source§impl<T: Format + ?Sized> Format for &T
Helper adapter that lets &dyn Format be used as Format.
impl<T: Format + ?Sized> Format for &T
Helper adapter that lets &dyn Format be used as Format.
Implementors§
impl Format for HumanFormat
Available on crate feature
human only.impl Format for JsonFormat
Available on crate feature
json only.impl Format for LogfmtFormat
Available on crate feature
logfmt only.