diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:11:38 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:13:23 +0000 |
commit | 20431706a863f92cb37dc512fef6e48d192aaf2c (patch) | |
tree | 2867f13f5fd5437ba628c67d7f87309ccadcd286 /vendor/tracing-subscriber-0.3.3/src/field/debug.rs | |
parent | Releasing progress-linux version 1.65.0+dfsg1-2~progress7.99u1. (diff) | |
download | rustc-20431706a863f92cb37dc512fef6e48d192aaf2c.tar.xz rustc-20431706a863f92cb37dc512fef6e48d192aaf2c.zip |
Merging upstream version 1.66.0+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/tracing-subscriber-0.3.3/src/field/debug.rs')
-rw-r--r-- | vendor/tracing-subscriber-0.3.3/src/field/debug.rs | 111 |
1 files changed, 111 insertions, 0 deletions
diff --git a/vendor/tracing-subscriber-0.3.3/src/field/debug.rs b/vendor/tracing-subscriber-0.3.3/src/field/debug.rs new file mode 100644 index 000000000..cc67d29fe --- /dev/null +++ b/vendor/tracing-subscriber-0.3.3/src/field/debug.rs @@ -0,0 +1,111 @@ +//! `MakeVisitor` wrappers for working with `fmt::Debug` fields. +use super::{MakeVisitor, VisitFmt, VisitOutput}; +use tracing_core::field::{Field, Visit}; + +use core::fmt; + +/// A visitor wrapper that ensures any `fmt::Debug` fields are formatted using +/// the alternate (`:#`) formatter. +#[derive(Debug, Clone)] +pub struct Alt<V>(V); + +// TODO(eliza): When `error` as a primitive type is stable, add a +// `DisplayErrors` wrapper... + +// === impl Alt === +// +impl<V> Alt<V> { + /// Wraps the provided visitor so that any `fmt::Debug` fields are formatted + /// using the alternative (`:#`) formatter. + pub fn new(inner: V) -> Self { + Alt(inner) + } +} + +impl<T, V> MakeVisitor<T> for Alt<V> +where + V: MakeVisitor<T>, +{ + type Visitor = Alt<V::Visitor>; + + #[inline] + fn make_visitor(&self, target: T) -> Self::Visitor { + Alt(self.0.make_visitor(target)) + } +} + +impl<V> Visit for Alt<V> +where + V: Visit, +{ + #[inline] + fn record_f64(&mut self, field: &Field, value: f64) { + self.0.record_f64(field, value) + } + + #[inline] + fn record_i64(&mut self, field: &Field, value: i64) { + self.0.record_i64(field, value) + } + + #[inline] + fn record_u64(&mut self, field: &Field, value: u64) { + self.0.record_u64(field, value) + } + + #[inline] + fn record_bool(&mut self, field: &Field, value: bool) { + self.0.record_bool(field, value) + } + + /// Visit a string value. + fn record_str(&mut self, field: &Field, value: &str) { + self.0.record_str(field, value) + } + + // TODO(eliza): add RecordError when stable + // fn record_error(&mut self, field: &Field, value: &(dyn std::error::Error + 'static)) { + // self.record_debug(field, &format_args!("{}", value)) + // } + + #[inline] + fn record_debug(&mut self, field: &Field, value: &dyn fmt::Debug) { + self.0.record_debug(field, &format_args!("{:#?}", value)) + } +} + +impl<V, O> VisitOutput<O> for Alt<V> +where + V: VisitOutput<O>, +{ + #[inline] + fn finish(self) -> O { + self.0.finish() + } +} + +feature! { + #![feature = "std"] + use super::VisitWrite; + use std::io; + + impl<V> VisitWrite for Alt<V> + where + V: VisitWrite, + { + #[inline] + fn writer(&mut self) -> &mut dyn io::Write { + self.0.writer() + } + } +} + +impl<V> VisitFmt for Alt<V> +where + V: VisitFmt, +{ + #[inline] + fn writer(&mut self) -> &mut dyn fmt::Write { + self.0.writer() + } +} |