pub struct Writer<'writer> { /* private fields */ }
Expand description

A writer to which formatted representations of spans and events are written.

This type is provided as input to the FormatEvent::format_event and FormatFields::format_fields methods, which will write formatted representations of Events and fields to the Writer.

This type implements the std::fmt::Write trait, allowing it to be used with any function that takes an instance of std::fmt::Write. Additionally, it can be used with the standard library’s std::write! and std::writeln! macros.

Additionally, a Writer may expose additional tracing-specific information to the formatter implementation.

Implementations§

source§

impl<'writer> Writer<'writer>

source

pub fn new(writer: &'writer mut impl Write) -> Self

Create a new Writer from any type that implements fmt::Write.

The returned Writer value may be passed as an argument to methods such as Format::format_event. Since constructing a Writer mutably borrows the underlying fmt::Write instance, that value may be accessed again once the Writer is dropped. For example, if the value implementing fmt::Write is a String, it will contain the formatted output of Format::format_event, which may then be used for other purposes.

source

pub fn by_ref(&mut self) -> Writer<'_>

Return a new Writer that mutably borrows self.

This can be used to temporarily borrow a Writer to pass a new Writer to a function that takes a Writer by value, allowing the original writer to still be used once that function returns.

source

pub fn write_str(&mut self, s: &str) -> Result

Writes a string slice into this Writer, returning whether the write succeeded.

This method can only succeed if the entire string slice was successfully written, and this method will not return until all data has been written or an error occurs.

This is identical to calling the write_str method from the Writer’s std::fmt::Write implementation. However, it is also provided as an inherent method, so that Writers can be used without needing to import the std::fmt::Write trait.

§Errors

This function will return an instance of std::fmt::Error on error.

source

pub fn write_char(&mut self, c: char) -> Result

Writes a char into this writer, returning whether the write succeeded.

A single char may be encoded as more than one byte. This method can only succeed if the entire byte sequence was successfully written, and this method will not return until all data has been written or an error occurs.

This is identical to calling the write_char method from the Writer’s std::fmt::Write implementation. However, it is also provided as an inherent method, so that Writers can be used without needing to import the std::fmt::Write trait.

§Errors

This function will return an instance of std::fmt::Error on error.

source

pub fn write_fmt(&mut self, args: Arguments<'_>) -> Result

Glue for usage of the write! macro with Writers.

This method should generally not be invoked manually, but rather through the write! macro itself.

This is identical to calling the write_fmt method from the Writer’s std::fmt::Write implementation. However, it is also provided as an inherent method, so that Writers can be used with the [write! macro] without needing to import the std::fmt::Write trait.

source

pub fn has_ansi_escapes(&self) -> bool

Returns true if ANSI escape codes may be used to add colors and other formatting when writing to this Writer.

If this returns false, formatters should not emit ANSI escape codes.

Trait Implementations§

source§

impl Debug for Writer<'_>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<'a> MakeVisitor<Writer<'a>> for DefaultFields

§

type Visitor = DefaultVisitor<'a>

The visitor type produced by this MakeVisitor.
source§

fn make_visitor(&self, target: Writer<'a>) -> Self::Visitor

Make a new visitor for the provided target.
source§

impl<'a, F> MakeVisitor<Writer<'a>> for FieldFn<F>
where F: Fn(&mut Writer<'a>, &Field, &dyn Debug) -> Result + Clone,

§

type Visitor = FieldFnVisitor<'a, F>

The visitor type produced by this MakeVisitor.
source§

fn make_visitor(&self, writer: Writer<'a>) -> Self::Visitor

Make a new visitor for the provided target.
source§

impl<'a> MakeVisitor<Writer<'a>> for PrettyFields

§

type Visitor = PrettyVisitor<'a>

The visitor type produced by this MakeVisitor.
source§

fn make_visitor(&self, target: Writer<'a>) -> Self::Visitor

Make a new visitor for the provided target.
source§

impl Write for Writer<'_>

source§

fn write_str(&mut self, s: &str) -> Result

Writes a string slice into this writer, returning whether the write succeeded. Read more
source§

fn write_char(&mut self, c: char) -> Result

Writes a char into this writer, returning whether the write succeeded. Read more
source§

fn write_fmt(&mut self, args: Arguments<'_>) -> Result

Glue for usage of the write! macro with implementors of this trait. Read more

Auto Trait Implementations§

§

impl<'writer> !RefUnwindSafe for Writer<'writer>

§

impl<'writer> !Send for Writer<'writer>

§

impl<'writer> !Sync for Writer<'writer>

§

impl<'writer> Unpin for Writer<'writer>

§

impl<'writer> !UnwindSafe for Writer<'writer>

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more