Skip to content

Commit

Permalink
core: impl Value for &mut T where T: Value (tokio-rs#1385)
Browse files Browse the repository at this point in the history
Impl `Value` for `&mut T` where `T: Value`. 

tokio-rs#1378 improve the `tracing::instrument` macro's recording behavior: all
primitive types implementing the `Value` trait will be recorded as
fields of that type instead of `fmt::Debug`. This PR is a prerequisite
for those `&mut` function arguments to achieve that.
  • Loading branch information
Folyd committed May 31, 2021
1 parent 37d55b6 commit 0ccc737
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions tracing-core/src/field.rs
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,19 @@ where
}
}

impl<'a, T: ?Sized> crate::sealed::Sealed for &'a mut T where T: Value + crate::sealed::Sealed + 'a {}

impl<'a, T: ?Sized> Value for &'a mut T
where
T: Value + 'a,
{
fn record(&self, key: &Field, visitor: &mut dyn Visit) {
// Don't use `(*self).record(key, visitor)`, otherwise would
// cause stack overflow due to `unconditional_recursion`.
T::record(self, key, visitor)
}
}

impl<'a> crate::sealed::Sealed for fmt::Arguments<'a> {}

impl<'a> Value for fmt::Arguments<'a> {
Expand Down

0 comments on commit 0ccc737

Please sign in to comment.