Skip to content

Commit 32884eb

Browse files
kaifastromaicephas-storm-bfxhawkw
authored andcommitted
subscriber: make format::Writer::new() public (#2680)
## 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]>
1 parent f97bc6f commit 32884eb

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

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

0 commit comments

Comments
 (0)