Skip to content

Commit

Permalink
subscriber: use struct update syntax when constructing from self (#…
Browse files Browse the repository at this point in the history
…1289)

This backports #1289 from `master`.

This PR aims to remove a lot of initializer boilerplate code by adopting
the`struct update syntax.  If the [RFC 2528]  gets merged and
implemented, we can remove more. 😸

[RFC 2528]: rust-lang/rfcs#2528
  • Loading branch information
Folyd authored and hawkw committed Mar 12, 2021
1 parent 6f9b537 commit 5181226
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 39 deletions.
42 changes: 9 additions & 33 deletions tracing-subscriber/src/fmt/fmt_layer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -279,11 +279,8 @@ where
/// [time]: #method.without_time
pub fn with_span_events(self, kind: FmtSpan) -> Self {
Layer {
fmt_event: self.fmt_event,
fmt_fields: self.fmt_fields,
fmt_span: self.fmt_span.with_kind(kind),
make_writer: self.make_writer,
_inner: self._inner,
..self
}
}

Expand All @@ -293,32 +290,23 @@ where
pub fn with_ansi(self, ansi: bool) -> Layer<S, N, format::Format<L, T>, W> {
Layer {
fmt_event: self.fmt_event.with_ansi(ansi),
fmt_fields: self.fmt_fields,
fmt_span: self.fmt_span,
make_writer: self.make_writer,
_inner: self._inner,
..self
}
}

/// Sets whether or not an event's target is displayed.
pub fn with_target(self, display_target: bool) -> Layer<S, N, format::Format<L, T>, W> {
Layer {
fmt_event: self.fmt_event.with_target(display_target),
fmt_fields: self.fmt_fields,
fmt_span: self.fmt_span,
make_writer: self.make_writer,
_inner: self._inner,
..self
}
}

/// Sets whether or not an event's level is displayed.
pub fn with_level(self, display_level: bool) -> Layer<S, N, format::Format<L, T>, W> {
Layer {
fmt_event: self.fmt_event.with_level(display_level),
fmt_fields: self.fmt_fields,
fmt_span: self.fmt_span,
make_writer: self.make_writer,
_inner: self._inner,
..self
}
}

Expand All @@ -329,10 +317,7 @@ where
pub fn with_thread_ids(self, display_thread_ids: bool) -> Layer<S, N, format::Format<L, T>, W> {
Layer {
fmt_event: self.fmt_event.with_thread_ids(display_thread_ids),
fmt_fields: self.fmt_fields,
fmt_span: self.fmt_span,
make_writer: self.make_writer,
_inner: self._inner,
..self
}
}

Expand All @@ -346,10 +331,7 @@ where
) -> Layer<S, N, format::Format<L, T>, W> {
Layer {
fmt_event: self.fmt_event.with_thread_names(display_thread_names),
fmt_fields: self.fmt_fields,
fmt_span: self.fmt_span,
make_writer: self.make_writer,
_inner: self._inner,
..self
}
}

Expand Down Expand Up @@ -422,9 +404,7 @@ impl<S, T, W> Layer<S, format::JsonFields, format::Format<format::Json, T>, W> {
Layer {
fmt_event: self.fmt_event.flatten_event(flatten_event),
fmt_fields: format::JsonFields::new(),
fmt_span: self.fmt_span,
make_writer: self.make_writer,
_inner: self._inner,
..self
}
}

Expand All @@ -439,9 +419,7 @@ impl<S, T, W> Layer<S, format::JsonFields, format::Format<format::Json, T>, W> {
Layer {
fmt_event: self.fmt_event.with_current_span(display_current_span),
fmt_fields: format::JsonFields::new(),
fmt_span: self.fmt_span,
make_writer: self.make_writer,
_inner: self._inner,
..self
}
}

Expand All @@ -456,9 +434,7 @@ impl<S, T, W> Layer<S, format::JsonFields, format::Format<format::Json, T>, W> {
Layer {
fmt_event: self.fmt_event.with_span_list(display_span_list),
fmt_fields: format::JsonFields::new(),
fmt_span: self.fmt_span,
make_writer: self.make_writer,
_inner: self._inner,
..self
}
}
}
Expand Down
12 changes: 6 additions & 6 deletions tracing-subscriber/src/fmt/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -643,8 +643,8 @@ where
/// [time]: #method.without_time
pub fn with_span_events(self, kind: format::FmtSpan) -> Self {
SubscriberBuilder {
filter: self.filter,
inner: self.inner.with_span_events(kind),
..self
}
}

Expand All @@ -653,8 +653,8 @@ where
#[cfg_attr(docsrs, doc(cfg(feature = "ansi")))]
pub fn with_ansi(self, ansi: bool) -> SubscriberBuilder<N, format::Format<L, T>, F, W> {
SubscriberBuilder {
filter: self.filter,
inner: self.inner.with_ansi(ansi),
..self
}
}

Expand All @@ -664,8 +664,8 @@ where
display_target: bool,
) -> SubscriberBuilder<N, format::Format<L, T>, F, W> {
SubscriberBuilder {
filter: self.filter,
inner: self.inner.with_target(display_target),
..self
}
}

Expand All @@ -675,8 +675,8 @@ where
display_level: bool,
) -> SubscriberBuilder<N, format::Format<L, T>, F, W> {
SubscriberBuilder {
filter: self.filter,
inner: self.inner.with_level(display_level),
..self
}
}

Expand All @@ -689,8 +689,8 @@ where
display_thread_names: bool,
) -> SubscriberBuilder<N, format::Format<L, T>, F, W> {
SubscriberBuilder {
filter: self.filter,
inner: self.inner.with_thread_names(display_thread_names),
..self
}
}

Expand All @@ -703,8 +703,8 @@ where
display_thread_ids: bool,
) -> SubscriberBuilder<N, format::Format<L, T>, F, W> {
SubscriberBuilder {
filter: self.filter,
inner: self.inner.with_thread_ids(display_thread_ids),
..self
}
}

Expand Down

0 comments on commit 5181226

Please sign in to comment.