]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
rust: alloc: implement Display for Box
authorGuangbo Cui <2407018371@qq.com>
Mon, 11 Nov 2024 13:40:41 +0000 (21:40 +0800)
committerMiguel Ojeda <ojeda@kernel.org>
Tue, 17 Dec 2024 23:54:31 +0000 (00:54 +0100)
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>
rust/kernel/alloc/kbox.rs

index 9ce414361c2c6dd8eea09b11041f6c307cbc7864..6beb976580262e3dd5ccfecaaaf61f4bbcbecccf 100644 (file)
@@ -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,