[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20230208045742.6b07ea09.gary@garyguo.net>
Date: Wed, 8 Feb 2023 04:57:42 +0000
From: Gary Guo <gary@...yguo.net>
To: Boqun Feng <boqun.feng@...il.com>
Cc: linux-kernel@...r.kernel.org, rust-for-linux@...r.kernel.org,
Miguel Ojeda <ojeda@...nel.org>,
Alex Gaynor <alex.gaynor@...il.com>,
Wedson Almeida Filho <wedsonaf@...il.com>,
Björn Roy Baron <bjorn3_gh@...tonmail.com>,
Vincenzo Palazzo <vincenzopalazzodev@...il.com>,
Will Deacon <will@...nel.org>,
Peter Zijlstra <peterz@...radead.org>,
Mark Rutland <mark.rutland@....com>,
Greg Kroah-Hartman <gregkh@...uxfoundation.org>,
Sergio González Collado
<sergio.collado@...il.com>, Finn Behrens <fin@...ntec.com>
Subject: Re: [PATCH v2 1/2] rust: sync: impl {Debug,Display} for
{Unique,}Arc
On Tue, 7 Feb 2023 10:52:15 -0800
Boqun Feng <boqun.feng@...il.com> wrote:
> This allows printing the inner data of `Arc` and its friends if the
> inner data implements `Display` or `Debug`. It's useful for logging and
> debugging purpose.
>
> Signed-off-by: Boqun Feng <boqun.feng@...il.com>
> Reviwed-by: Vincenzo Palazzo <vincenzopalazzodev@...il.com>
Reviewed-by: Gary Guo <gary@...yguo.net>
> ---
> rust/kernel/sync/arc.rs | 25 +++++++++++++++++++++++++
> 1 file changed, 25 insertions(+)
>
> diff --git a/rust/kernel/sync/arc.rs b/rust/kernel/sync/arc.rs
> index 519a6ec43644..e6176d9b5b29 100644
> --- a/rust/kernel/sync/arc.rs
> +++ b/rust/kernel/sync/arc.rs
> @@ -22,6 +22,7 @@ use crate::{
> };
> use alloc::boxed::Box;
> use core::{
> + fmt,
> marker::{PhantomData, Unsize},
> mem::{ManuallyDrop, MaybeUninit},
> ops::{Deref, DerefMut},
> @@ -522,3 +523,27 @@ impl<T: ?Sized> DerefMut for UniqueArc<T> {
> unsafe { &mut self.inner.ptr.as_mut().data }
> }
> }
> +
> +impl<T: fmt::Display + ?Sized> fmt::Display for UniqueArc<T> {
> + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
> + fmt::Display::fmt(self.deref(), f)
> + }
> +}
> +
> +impl<T: fmt::Display + ?Sized> fmt::Display for Arc<T> {
> + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
> + fmt::Display::fmt(self.deref(), f)
> + }
> +}
> +
> +impl<T: fmt::Debug + ?Sized> fmt::Debug for UniqueArc<T> {
> + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
> + fmt::Debug::fmt(self.deref(), f)
> + }
> +}
> +
> +impl<T: fmt::Debug + ?Sized> fmt::Debug for Arc<T> {
> + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
> + fmt::Debug::fmt(self.deref(), f)
> + }
> +}
Powered by blists - more mailing lists