Skip to content

Commit

Permalink
Add valuable capture to __tracing_capture_value!
Browse files Browse the repository at this point in the history
  • Loading branch information
CAD97 committed Mar 18, 2022
1 parent 9830f1f commit 1fc27ff
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 28 deletions.
42 changes: 40 additions & 2 deletions tracing/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -964,8 +964,7 @@ pub use self::span::Span;
pub use tracing_attributes::instrument;

#[macro_use]
#[doc(hidden)]
pub mod macros;
mod macros;

pub mod collect;
pub mod dispatch;
Expand Down Expand Up @@ -1110,6 +1109,45 @@ pub mod __macro_support {
.finish()
}
}

pub mod __tracing_capture_value_by {
// autoref specialization level 0
#[cfg(all(tracing_unstable, feature = "valuable"))]
pub trait TracingCaptureValueByValuable {
fn __tracing_capture_value(&self) -> &dyn crate::field::Value;
}

#[cfg(all(tracing_unstable, feature = "valuable"))]
impl<T: valuable::Valuable> TracingCaptureValueByValuable for T {
fn __tracing_capture_value(&self) -> valuable::Value<'_> {
crate::field::valuable(self)
}
}

// autoref specialization level 1
#[cfg(not(all(tracing_unstable, feature = "valuable")))]
pub trait TracingCaptureValueByValue {
fn __tracing_capture_value(&self) -> &dyn crate::field::Value;
}

#[cfg(not(all(tracing_unstable, feature = "valuable")))]
impl<T: crate::field::Value> TracingCaptureValueByValue for &T {
fn __tracing_capture_value(&self) -> &dyn crate::field::Value {
self
}
}

// autoref specialization level 2
pub trait TracingCaptureValueByDebug {
fn __tracing_capture_value(&self) -> &dyn crate::field::Value;
}

impl<T: core::fmt::Debug> TracingCaptureValueByDebug for &&T {
fn __tracing_capture_value(&self) -> &dyn crate::field::Value {
crate::field::debug_ref(self)
}
}
}
}

mod sealed {
Expand Down
28 changes: 2 additions & 26 deletions tracing/src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2134,37 +2134,13 @@ macro_rules! fieldset {

}

// autoref specialization level 0
#[doc(hidden)]
pub trait TracingCaptureValueByValue {
fn __tracing_capture_value(&self) -> &dyn crate::field::Value;
}

impl<T: crate::field::Value> TracingCaptureValueByValue for T {
fn __tracing_capture_value(&self) -> &dyn crate::field::Value {
self
}
}

// autoref specialization level 1
#[doc(hidden)]
pub trait TracingCaptureValueByDebug {
fn __tracing_capture_value(&self) -> &dyn crate::field::Value;
}

impl<T: core::fmt::Debug> TracingCaptureValueByDebug for &T {
fn __tracing_capture_value(&self) -> &dyn crate::field::Value {
crate::field::debug_ref(self)
}
}

#[doc(hidden)]
#[macro_export]
macro_rules! __tracing_capture_value {
($e:expr) => {{
#[allow(unused_imports)]
use $crate::macros::{TracingCaptureValueByDebug, TracingCaptureValueByValue};
(&$e).__tracing_capture_value()
use $crate::__macro_support::__tracing_capture_value_by::*;
(&&$e).__tracing_capture_value()
}};
}

Expand Down

0 comments on commit 1fc27ff

Please sign in to comment.