rust: Implement Display for Box
Subsystems (2)
PATCH v5 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 6 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.
Quoted 6 lines
Therefore add
impl DisplayforBox.Acked-by Danilo Krummrich <[email protected]>Suggested-by Boqun Feng <[email protected]>Signed-off-by Guangbo Cui <[email protected]>
PATCH v5 2/2 rust: align Debug implementation for Box with Display
In reply to Guangbo CuiEnsure 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 v5 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]>
Miguel Ojeda
AppliedQuoted 6 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.
Quoted 6 lines
Therefore add
impl DisplayforBox.Acked-by Danilo Krummrich <[email protected]>Suggested-by Boqun Feng <[email protected]>Signed-off-by Guangbo Cui <[email protected]>
Applied series to rust-next -- thanks everyone!
[ Reworded title. - Miguel ]
[ Reworded title. - Miguel ]
Cheers,
Miguel