rust: Implement Display for Box
Subsystems (2)
PATCH v3 1/1 rust: Implement Display for Box
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.
---
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/[email protected]
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/[email protected]
rust/kernel/alloc/kbox.rs | 10 ++++++++++ 1 file changed, 10 insertions(+)
rust/kernel/alloc/kbox.rs +10 -0
@@ -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 ,
Signature · 1 line
2.34.1
Quoted 27 lines · Guangbo Cui
Currently
impl Displayis missing forBox<T, A>, as a result, things like usingBox<..>directly as an operand inpr_info!()are impossible, which is less ergonomic compared toBoxin Rust std.Therefore add
impl DisplayforBox.Suggested-by Boqun Feng <[email protected]>Signed-off-by Guangbo Cui <[email protected]>---
Changes in v3:
- Updatefmtimplementation to clarify that it does not call itself infinitely.
- Link to v2: https://lore.kernel.org/rust-for-linux/[email protected]
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/[email protected]rust/kernel/alloc/kbox.rs | 10 ++++++++++ 1 file changed, 10 insertions(+)rust/kernel/alloc/kbox.rs +0
-0
rust/kernel/alloc/kbox.rs fn deref_mut(&mut self) -> &mut T { · line 436
Quoted 10 lines
rust/kernel/alloc/kbox.rs +7
-0@@ -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,
rust/kernel/alloc/kbox.rs fn deref_mut(&mut self) -> &mut T { · line 440
Quoted 4 lines
rust/kernel/alloc/kbox.rs +3
-0+ } +} +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,
Quoted 5 lines
rust/kernel/alloc/kbox.rs +0
-0where T: ?Sized + fmt::Debug,Signature · 1 line
2.34.1
Quoted 41 lines · Danilo Krummrich
Quoted 27 lines · Guangbo Cui
Currently
impl Displayis missing forBox<T, A>, as a result, things like usingBox<..>directly as an operand inpr_info!()are impossible, which is less ergonomic compared toBoxin Rust std.Therefore add
impl DisplayforBox.Suggested-by Boqun Feng <[email protected]>Signed-off-by Guangbo Cui <[email protected]>---
Changes in v3:
- Updatefmtimplementation to clarify that it does not call itself infinitely.
- Link to v2: https://lore.kernel.org/rust-for-linux/[email protected]
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/[email protected]rust/kernel/alloc/kbox.rs | 10 ++++++++++ 1 file changed, 10 insertions(+)rust/kernel/alloc/kbox.rs +0
-0rust/kernel/alloc/kbox.rs fn deref_mut(&mut self) -> &mut T { · line 436
Quoted 10 lines
rust/kernel/alloc/kbox.rs +7
-0@@ -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,
Quoted 6 lines
rust/kernel/alloc/kbox.rs fn deref_mut(&mut self) -> &mut T { · line 440
Quoted 4 lines
rust/kernel/alloc/kbox.rs +3
-0+ } +} +impl <T ,A > fmt::Debug for Box <T ,A >please also change it for
Debugin a separate patch, as requested in [1].
Thanks dakr, I forgot it last week. Fix it in v4.
Quoted 12 lines
With that,
Acked-by Danilo Krummrich <[email protected]>[1] https://lore.kernel.org/all/[email protected]/
Quoted 5 lines
rust/kernel/alloc/kbox.rs +0
-0where T: ?Sized + fmt::Debug,Signature · 1 line
2.34.1