Skip to content

Commit 21e08aa

Browse files
JCKeepojeda
authored andcommitted
rust: alloc: 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`. Acked-by: Danilo Krummrich <[email protected]> Suggested-by: Boqun Feng <[email protected]> Link: #1126 Signed-off-by: Guangbo Cui <[email protected]> Reviewed-by: Alice Ryhl <[email protected]> Link: https://lore.kernel.org/r/[email protected] [ Reworded title. - Miguel ] Signed-off-by: Miguel Ojeda <[email protected]>
1 parent 2dde1c8 commit 21e08aa

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

rust/kernel/alloc/kbox.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -427,6 +427,16 @@ where
427427
}
428428
}
429429

430+
impl<T, A> fmt::Display for Box<T, A>
431+
where
432+
T: ?Sized + fmt::Display,
433+
A: Allocator,
434+
{
435+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
436+
<T as fmt::Display>::fmt(&**self, f)
437+
}
438+
}
439+
430440
impl<T, A> fmt::Debug for Box<T, A>
431441
where
432442
T: ?Sized + fmt::Debug,

0 commit comments

Comments
 (0)