Skip to content

Commit 232e456

Browse files
committed
Add valuable capture to __tracing_capture_value!
1 parent 6aacd42 commit 232e456

File tree

2 files changed

+63
-28
lines changed

2 files changed

+63
-28
lines changed

tracing/src/lib.rs

Lines changed: 61 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -970,8 +970,7 @@ pub use self::span::Span;
970970
pub use tracing_attributes::instrument;
971971

972972
#[macro_use]
973-
#[doc(hidden)]
974-
pub mod macros;
973+
mod macros;
975974

976975
pub mod collect;
977976
pub mod dispatch;
@@ -1178,6 +1177,66 @@ pub mod __macro_support {
11781177
}
11791178
}
11801179
}
1180+
1181+
pub mod __tracing_capture_value_by {
1182+
/// Autoref specialization level 0 for `__tracing_capture_value!`
1183+
///
1184+
/// /!\ WARNING: This is *not* a stable API! /!\
1185+
/// This type, and all code contained in the `__macro_support` module, is
1186+
/// a *private* API of `tracing`. It is exposed publicly because it is used
1187+
/// by the `tracing` macros, but it is not part of the stable versioned API.
1188+
/// Breaking changes to this module may occur in small-numbered versions
1189+
/// without warning.
1190+
#[cfg(all(tracing_unstable, feature = "valuable"))]
1191+
pub trait TracingCaptureValueByValuable {
1192+
fn __tracing_capture_value(&self) -> &dyn crate::field::Value;
1193+
}
1194+
1195+
#[cfg(all(tracing_unstable, feature = "valuable"))]
1196+
impl<T: valuable::Valuable> TracingCaptureValueByValuable for T {
1197+
fn __tracing_capture_value(&self) -> valuable::Value<'_> {
1198+
crate::field::valuable(self)
1199+
}
1200+
}
1201+
1202+
/// Autoref specialization level 1 for `__tracing_capture_value!`
1203+
///
1204+
/// /!\ WARNING: This is *not* a stable API! /!\
1205+
/// This type, and all code contained in the `__macro_support` module, is
1206+
/// a *private* API of `tracing`. It is exposed publicly because it is used
1207+
/// by the `tracing` macros, but it is not part of the stable versioned API.
1208+
/// Breaking changes to this module may occur in small-numbered versions
1209+
/// without warning.
1210+
#[cfg(not(all(tracing_unstable, feature = "valuable")))]
1211+
pub trait TracingCaptureValueByValue {
1212+
fn __tracing_capture_value(&self) -> &dyn crate::field::Value;
1213+
}
1214+
1215+
#[cfg(not(all(tracing_unstable, feature = "valuable")))]
1216+
impl<T: crate::field::Value> TracingCaptureValueByValue for &T {
1217+
fn __tracing_capture_value(&self) -> &dyn crate::field::Value {
1218+
self
1219+
}
1220+
}
1221+
1222+
/// Autoref specialization level 2 for `__tracing_capture_value!`
1223+
///
1224+
/// /!\ WARNING: This is *not* a stable API! /!\
1225+
/// This type, and all code contained in the `__macro_support` module, is
1226+
/// a *private* API of `tracing`. It is exposed publicly because it is used
1227+
/// by the `tracing` macros, but it is not part of the stable versioned API.
1228+
/// Breaking changes to this module may occur in small-numbered versions
1229+
/// without warning.
1230+
pub trait TracingCaptureValueByDebug {
1231+
fn __tracing_capture_value(&self) -> &dyn crate::field::Value;
1232+
}
1233+
1234+
impl<T: core::fmt::Debug> TracingCaptureValueByDebug for &&T {
1235+
fn __tracing_capture_value(&self) -> &dyn crate::field::Value {
1236+
crate::field::debug_ref(self)
1237+
}
1238+
}
1239+
}
11811240
}
11821241

11831242
mod sealed {

tracing/src/macros.rs

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2282,37 +2282,13 @@ macro_rules! fieldset {
22822282

22832283
}
22842284

2285-
// autoref specialization level 0
2286-
#[doc(hidden)]
2287-
pub trait TracingCaptureValueByValue {
2288-
fn __tracing_capture_value(&self) -> &dyn crate::field::Value;
2289-
}
2290-
2291-
impl<T: crate::field::Value> TracingCaptureValueByValue for T {
2292-
fn __tracing_capture_value(&self) -> &dyn crate::field::Value {
2293-
self
2294-
}
2295-
}
2296-
2297-
// autoref specialization level 1
2298-
#[doc(hidden)]
2299-
pub trait TracingCaptureValueByDebug {
2300-
fn __tracing_capture_value(&self) -> &dyn crate::field::Value;
2301-
}
2302-
2303-
impl<T: core::fmt::Debug> TracingCaptureValueByDebug for &T {
2304-
fn __tracing_capture_value(&self) -> &dyn crate::field::Value {
2305-
crate::field::debug_ref(self)
2306-
}
2307-
}
2308-
23092285
#[doc(hidden)]
23102286
#[macro_export]
23112287
macro_rules! __tracing_capture_value {
23122288
($e:expr) => {{
23132289
#[allow(unused_imports)]
2314-
use $crate::macros::{TracingCaptureValueByDebug, TracingCaptureValueByValue};
2315-
(&$e).__tracing_capture_value()
2290+
use $crate::__macro_support::__tracing_capture_value_by::*;
2291+
(&&$e).__tracing_capture_value()
23162292
}};
23172293
}
23182294

0 commit comments

Comments
 (0)