From: Danilo Krummrich <dakr@kernel.org>
To: Guangbo Cui <2407018371@qq.com>
Cc: "Miguel Ojeda" <ojeda@kernel.org>,
"Alex Gaynor" <alex.gaynor@gmail.com>,
"Boqun Feng" <boqun.feng@gmail.com>,
"Gary Guo" <gary@garyguo.net>,
"Björn Roy Baron" <bjorn3_gh@protonmail.com>,
"Benno Lossin" <benno.lossin@proton.me>,
"Andreas Hindborg" <a.hindborg@kernel.org>,
"Alice Ryhl" <aliceryhl@google.com>,
"Trevor Gross" <tmgross@umich.edu>,
rust-for-linux@vger.kernel.org
Subject: Re: [PATCH v3] rust: Implement Display for Box
Date: Sun, 3 Nov 2024 21:46:40 +0100 [thread overview]
Message-ID: <ZyfhMKAjFgEm6rTO@pollux.localdomain> (raw)
In-Reply-To: <tencent_CC0134B8E94CCD93D347DAB9ACAB48652F09@qq.com>
On Tue, Oct 29, 2024 at 10:28:38PM +0800, Guangbo Cui wrote:
> Currently `impl Display` is missing for `Box<T, A>`, as a result,
> things like using `Box<..>` directly as an operand in `pr_info!()`
> are impossible, which is less ergonomic compared to `Box` in Rust
> std.
>
> Therefore add `impl Display` for `Box`.
>
> Suggested-by: Boqun Feng <boqun.feng@gmail.com>
> Link: https://github.com/Rust-for-Linux/linux/issues/1126
> Signed-off-by: Guangbo Cui <2407018371@qq.com>
> ---
> Changes in v3:
> - Update `fmt` implementation to clarify that it does not call itself infinitely.
> - Link to v2: https://lore.kernel.org/rust-for-linux/tencent_F71CE9D125A8C6191D8CF95B3A4F3BB2F506@qq.com
> Changes in v2:
> - Add missing tag: Suggested-by.
> - Update the patch title and the changelogs.
> - Link to v1: https://lore.kernel.org/rust-for-linux/tencent_CA5A5D6268F0D1419BAFA6AFB4EB5A37920A@qq.com
>
> rust/kernel/alloc/kbox.rs | 10 ++++++++++
> 1 file changed, 10 insertions(+)
>
> diff --git a/rust/kernel/alloc/kbox.rs b/rust/kernel/alloc/kbox.rs
> index d69c32496..a496a866d 100644
> --- a/rust/kernel/alloc/kbox.rs
> +++ b/rust/kernel/alloc/kbox.rs
> @@ -427,6 +427,16 @@ fn deref_mut(&mut self) -> &mut T {
> }
> }
>
> +impl<T, A> fmt::Display for Box<T, A>
> +where
> + T: ?Sized + fmt::Display,
> + A: Allocator,
> +{
> + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
> + <T as fmt::Display>::fmt(&**self, f)
Since you went with this variant,
> + }
> +}
> +
> impl<T, A> fmt::Debug for Box<T, A>
please also change it for `Debug` in a separate patch, as requested in [1].
With that,
Acked-by: Danilo Krummrich <dakr@kernel.org>
[1] https://lore.kernel.org/all/a335869c-6bc4-49c1-b6a8-1c4ca4e98b20@kernel.org/
> where
> T: ?Sized + fmt::Debug,
> --
> 2.34.1
>
next prev parent reply other threads:[~2024-11-03 20:46 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-10-29 14:28 [PATCH v3] rust: Implement Display for Box Guangbo Cui
2024-11-03 20:46 ` Danilo Krummrich [this message]
2024-11-04 14:10 ` Guangbo Cui
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=ZyfhMKAjFgEm6rTO@pollux.localdomain \
--to=dakr@kernel.org \
--cc=2407018371@qq.com \
--cc=a.hindborg@kernel.org \
--cc=alex.gaynor@gmail.com \
--cc=aliceryhl@google.com \
--cc=benno.lossin@proton.me \
--cc=bjorn3_gh@protonmail.com \
--cc=boqun.feng@gmail.com \
--cc=gary@garyguo.net \
--cc=ojeda@kernel.org \
--cc=rust-for-linux@vger.kernel.org \
--cc=tmgross@umich.edu \
/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).