diff options
author | Guangbo Cui <2407018371@qq.com> | 2024-11-11 16:40:41 +0300 |
---|---|---|
committer | Miguel Ojeda <ojeda@kernel.org> | 2024-12-18 02:54:31 +0300 |
commit | 21e08aa59a9a0b665b051a8919ec80a872807cfb (patch) | |
tree | b82e3b4ea9287af6026f50be6078c6d7dc484088 /rust/kernel | |
parent | 2dde1c8b04a5c415912bc3ffa8b677eb364dbcb7 (diff) | |
download | linux-21e08aa59a9a0b665b051a8919ec80a872807cfb.tar.xz |
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 <dakr@kernel.org>
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>
Reviewed-by: Alice Ryhl <aliceryhl@google.com>
Link: https://lore.kernel.org/r/tencent_2AD25C6A6898D3A598CBA54BB6AF59BB900A@qq.com
[ Reworded title. - Miguel ]
Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
Diffstat (limited to 'rust/kernel')
-rw-r--r-- | rust/kernel/alloc/kbox.rs | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/rust/kernel/alloc/kbox.rs b/rust/kernel/alloc/kbox.rs index 9ce414361c2c..6beb97658026 100644 --- a/rust/kernel/alloc/kbox.rs +++ b/rust/kernel/alloc/kbox.rs @@ -427,6 +427,16 @@ where } } +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, |