From: Boqun Feng <boqun.feng@gmail.com>
To: linux-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org
Cc: "Miguel Ojeda" <ojeda@kernel.org>,
"Alex Gaynor" <alex.gaynor@gmail.com>,
"Wedson Almeida Filho" <wedsonaf@gmail.com>,
"Boqun Feng" <boqun.feng@gmail.com>,
"Gary Guo" <gary@garyguo.net>,
"Björn Roy Baron" <bjorn3_gh@protonmail.com>,
"Vincenzo Palazzo" <vincenzopalazzodev@gmail.com>,
"Will Deacon" <will@kernel.org>,
"Peter Zijlstra" <peterz@infradead.org>,
"Mark Rutland" <mark.rutland@arm.com>,
"Greg Kroah-Hartman" <gregkh@linuxfoundation.org>,
"Sergio González Collado" <sergio.collado@gmail.com>,
"Finn Behrens" <fin@nyantec.com>
Subject: [PATCH v2 1/2] rust: sync: impl {Debug,Display} for {Unique,}Arc
Date: Tue, 7 Feb 2023 10:52:15 -0800 [thread overview]
Message-ID: <20230207185216.1314638-2-boqun.feng@gmail.com> (raw)
In-Reply-To: <20230207185216.1314638-1-boqun.feng@gmail.com>
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@gmail.com>
Reviwed-by: Vincenzo Palazzo <vincenzopalazzodev@gmail.com>
---
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)
+ }
+}
--
2.39.1
next prev parent reply other threads:[~2023-02-07 18:52 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-02-07 18:52 [PATCH v2 0/2] rust: sync: Arc: Implement Debug and Display Boqun Feng
2023-02-07 18:52 ` Boqun Feng [this message]
2023-02-07 19:03 ` [PATCH v2 1/2] rust: sync: impl {Debug,Display} for {Unique,}Arc Carlos Bilbao
2023-02-07 20:27 ` Vincenzo Palazzo
2023-02-07 20:45 ` Vincenzo Palazzo
2023-02-07 20:54 ` Boqun Feng
2023-02-08 4:57 ` Gary Guo
2023-02-08 10:00 ` Andreas Hindborg
2023-02-08 13:43 ` Björn Roy Baron
2023-02-07 18:52 ` [PATCH v2 2/2] sample: rust: print: Add sampe code for Arc printing Boqun Feng
2023-02-08 4:57 ` Gary Guo
2023-02-08 10:01 ` Andreas Hindborg
2023-02-08 15:19 ` Miguel Ojeda
2023-02-08 16:33 ` Boqun Feng
2023-02-08 16:56 ` Miguel Ojeda
2023-02-08 16:58 ` Boqun Feng
2023-04-10 2:53 ` [PATCH v2 0/2] rust: sync: Arc: Implement Debug and Display Miguel Ojeda
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230207185216.1314638-2-boqun.feng@gmail.com \
--to=boqun.feng@gmail.com \
--cc=alex.gaynor@gmail.com \
--cc=bjorn3_gh@protonmail.com \
--cc=fin@nyantec.com \
--cc=gary@garyguo.net \
--cc=gregkh@linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=ojeda@kernel.org \
--cc=peterz@infradead.org \
--cc=rust-for-linux@vger.kernel.org \
--cc=sergio.collado@gmail.com \
--cc=vincenzopalazzodev@gmail.com \
--cc=wedsonaf@gmail.com \
--cc=will@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).