🛈 Note: This is pre-release documentation for the upcoming tracing 0.2.0 ecosystem.

For the release documentation, please see docs.rs, instead.

tracing_subscriber::fmt::format

Struct Writer

Source
pub struct Writer<'writer> { /* private fields */ }
Available on crate features fmt and std only.
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

Source§

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,

Source§

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

Source§

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> Freeze for Writer<'writer>

§

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>,

Source§

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>,

Source§

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> WithCollector for T

Source§

fn with_collector<C>(self, collector: C) -> WithDispatch<Self>
where C: Into<Dispatch>,

Attaches the provided collector to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_collector(self) -> WithDispatch<Self>

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