Skip to content

Commit 9143b53

Browse files
kaifastromaicephas-storm-bfxhawkw
authored andcommitted
subscriber: make format::Writer::new() public (tokio-rs#2680)
## 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 <[email protected]> Co-authored-by: Eliza Weisman <[email protected]>
1 parent 0f008c2 commit 9143b53

File tree

1 file changed

+13
-1
lines changed
  • tracing-subscriber/src/fmt/format

1 file changed

+13
-1
lines changed

tracing-subscriber/src/fmt/format/mod.rs

+13-1
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,19 @@ impl<'writer> Writer<'writer> {
422422
// We may not want to do that if we choose to expose specialized
423423
// constructors instead (e.g. `from_string` that stores whether the string
424424
// is empty...?)
425-
pub(crate) fn new(writer: &'writer mut impl fmt::Write) -> Self {
425+
//(@kaifastromai) I suppose having dedicated constructors may have certain benefits
426+
// but I am not privy to the larger direction of tracing/subscriber.
427+
/// Create a new [`Writer`] from any type that implements [`fmt::Write`].
428+
///
429+
/// The returned `Writer` value may be passed as an argument to methods
430+
/// such as [`Format::format_event`]. Since constructing a `Writer`
431+
/// mutably borrows the underlying [`fmt::Write`] instance, that value may
432+
/// be accessed again once the `Writer` is dropped. For example, if the
433+
/// value implementing [`fmt::Write`] is a [`String`], it will contain
434+
/// the formatted output of [`Format::format_event`], which may then be
435+
/// used for other purposes.
436+
#[must_use]
437+
pub fn new(writer: &'writer mut impl fmt::Write) -> Self {
426438
Self {
427439
writer: writer as &mut dyn fmt::Write,
428440
is_ansi: false,

0 commit comments

Comments
 (0)