Skip to main content

Format

Trait Format 

Source
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§

Source

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.

Source§

fn write_record<W: Write + ?Sized>( &self, record: &Record<'_>, writer: &mut W, ) -> Result

Source§

impl<T: Format + ?Sized> Format for Box<T>

Available on crate feature std only.
Source§

fn write_record<W: Write + ?Sized>( &self, record: &Record<'_>, writer: &mut W, ) -> Result

Source§

impl<T: Format + ?Sized> Format for Arc<T>

Available on crate feature std only.
Source§

fn write_record<W: Write + ?Sized>( &self, record: &Record<'_>, writer: &mut W, ) -> Result

Implementors§

Source§

impl Format for HumanFormat

Available on crate feature human only.
Source§

impl Format for JsonFormat

Available on crate feature json only.
Source§

impl Format for LogfmtFormat

Available on crate feature logfmt only.