* [PATCH v3] rust: Implement Display for Box
@ 2024-10-29 14:28 Guangbo Cui
2024-11-03 20:46 ` Danilo Krummrich
0 siblings, 1 reply; 3+ messages in thread
From: Guangbo Cui @ 2024-10-29 14:28 UTC (permalink / raw)
To: Miguel Ojeda, Alex Gaynor
Cc: Boqun Feng, Gary Guo, Björn Roy Baron, Benno Lossin,
Andreas Hindborg, Alice Ryhl, Trevor Gross, rust-for-linux,
Danilo Krummrich, Guangbo Cui
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)
+ }
+}
+
impl<T, A> fmt::Debug for Box<T, A>
where
T: ?Sized + fmt::Debug,
--
2.34.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH v3] rust: Implement Display for Box
2024-10-29 14:28 [PATCH v3] rust: Implement Display for Box Guangbo Cui
@ 2024-11-03 20:46 ` Danilo Krummrich
2024-11-04 14:10 ` Guangbo Cui
0 siblings, 1 reply; 3+ messages in thread
From: Danilo Krummrich @ 2024-11-03 20:46 UTC (permalink / raw)
To: Guangbo Cui
Cc: Miguel Ojeda, Alex Gaynor, Boqun Feng, Gary Guo,
Björn Roy Baron, Benno Lossin, Andreas Hindborg, Alice Ryhl,
Trevor Gross, rust-for-linux
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
>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH v3] rust: Implement Display for Box
2024-11-03 20:46 ` Danilo Krummrich
@ 2024-11-04 14:10 ` Guangbo Cui
0 siblings, 0 replies; 3+ messages in thread
From: Guangbo Cui @ 2024-11-04 14:10 UTC (permalink / raw)
To: Danilo Krummrich
Cc: Miguel Ojeda, Alex Gaynor, Boqun Feng, Gary Guo,
Björn Roy Baron, Benno Lossin, Andreas Hindborg, Alice Ryhl,
Trevor Gross, rust-for-linux
On Sun, Nov 03, 2024 at 09:46:40PM +0100, Danilo Krummrich wrote:
> 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].
Thanks dakr, I forgot it last week. Fix it in v4.
>
> 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
> >
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2024-11-04 14:10 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-10-29 14:28 [PATCH v3] rust: Implement Display for Box Guangbo Cui
2024-11-03 20:46 ` Danilo Krummrich
2024-11-04 14:10 ` Guangbo Cui
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).