Skip to content

Commit

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

As seen here tokio-rs#2512 and tokio-rs#2223. Previously pr'ed here tokio-rs#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  tokio-rs#2512
Closes tokio-rs#2223

Co-authored-by: Cephas Storm <cephas.storm@borisfx.com>
Co-authored-by: Eliza Weisman <eliza@buoyant.io>
  • Loading branch information
3 people authored and kaffarell committed Nov 10, 2023
1 parent 0f008c2 commit 9143b53
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 @@ -422,7 +422,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 9143b53

Please sign in to comment.