rust: Implement Display for Box
Subsystems (2)
A message that is not in the archive (sent off-list or not yet received): [email protected]
PATCH v4 1/2 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.
--- 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 11 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]>
PATCH v4 2/2 rust: align Debug implementation for Box with Display
In reply to a message not in the archiveEnsure consistency between Debug and Display for Box by updating Debug to match the new Display style.
--- rust/kernel/alloc/kbox.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
rust/kernel/alloc/kbox.rs +1 -1
@@ -443,7 +443,7 @@ impl<T, A> fmt::Debug for Box<T, A> A: Allocator, { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - fmt::Debug::fmt(&**self, f) + <T as fmt::Debug >::fmt (&**self, f) } }
Signature · 1 line
2.34.1
Re: [PATCH v4 2/2] rust: align Debug implementation for Box with Display
Quoted 6 lines · Guangbo Cui
Ensure consistency between
DebugandDisplayforBoxby updatingDebugto match the newDisplaystyle.Acked-by Danilo Krummrich <[email protected]>Signed-off-by Guangbo Cui <[email protected]>
Re: [PATCH v4 2/2] rust: align Debug implementation for Box with Display
In reply to Guangbo CuiQuoted 4 lines · Guangbo Cui
Ensure consistency between
DebugandDisplayforBoxby updatingDebugto match the newDisplaystyle.Acked-by Danilo Krummrich <[email protected]>
The ACK was for patch 1 -- this patch I haven't seen before obviously.
However, you can keep it. For both:
Quoted 21 lines
Signed-off-by Guangbo Cui <[email protected]>--- rust/kernel/alloc/kbox.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)rust/kernel/alloc/kbox.rs +1
-1@@ -443,7 +443,7 @@ impl<T, A> fmt::Debug for Box<T, A> A: Allocator, { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - fmt::Debug::fmt(&**self, f) + <T as fmt::Debug >::fmt (&**self, f) } }Signature · 1 line
2.34.1