From 0ccc7378331440d5d9bb40703cacc0d377a4a771 Mon Sep 17 00:00:00 2001 From: Folyd Date: Tue, 4 May 2021 00:15:24 +0800 Subject: [PATCH] core: impl `Value` for `&mut T` where `T: Value` (#1385) Impl `Value` for `&mut T` where `T: Value`. #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. --- tracing-core/src/field.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/tracing-core/src/field.rs b/tracing-core/src/field.rs index f9da95c99d..e3c2f5782b 100644 --- a/tracing-core/src/field.rs +++ b/tracing-core/src/field.rs @@ -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> {