Skip to content

Commit

Permalink
subscriber: make format::Writer::new() public (#2680)
Browse files Browse the repository at this point in the history
## Motivation

As seen here #2512 and #2223. Previously pr'ed here #2525, but no progress has
been made there for quite some. I have applied the suggested changes. Not sure
the formatting of the doc is sufficient or otherwise correct

## Solution

Make the `format::Writer::new()` function public. I don't see any obvious
trade-offs, but I am not familiar with the larger direction of
tracing/subscriber, so I may be wrong.

Closes  #2512
Closes #2223

Co-authored-by: Cephas Storm <[email protected]>
Co-authored-by: Eliza Weisman <[email protected]>
  • Loading branch information
3 people committed Oct 12, 2023
1 parent f8c0002 commit 71b5b2c
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion tracing-subscriber/src/fmt/format/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,19 @@ impl<'writer> Writer<'writer> {
// We may not want to do that if we choose to expose specialized
// constructors instead (e.g. `from_string` that stores whether the string
// is empty...?)
pub(crate) fn new(writer: &'writer mut impl fmt::Write) -> Self {
//(@kaifastromai) I suppose having dedicated constructors may have certain benefits
// but I am not privy to the larger direction of tracing/subscriber.
/// 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.
#[must_use]
pub fn new(writer: &'writer mut impl fmt::Write) -> Self {
Self {
writer: writer as &mut dyn fmt::Write,
is_ansi: false,
Expand Down

0 comments on commit 71b5b2c

Please sign in to comment.