]> git.ipfire.org Git - thirdparty/kernel/linux.git/commit
rust: support formatting of foreign types
authorTamir Duberstein <tamird@gmail.com>
Sat, 18 Oct 2025 19:16:36 +0000 (15:16 -0400)
committerMiguel Ojeda <ojeda@kernel.org>
Wed, 22 Oct 2025 05:15:31 +0000 (07:15 +0200)
commitc5cf01ba8dfe9c0f631ace6f64ec436303783000
tree39db5b3b956b1ca76dbc940162ff84c9a88388c1
parent1dcd763ba1f62c1305a03bc7d5bd1d44c20a4f5e
rust: support formatting of foreign types

Introduce a `fmt!` macro which wraps all arguments in
`kernel::fmt::Adapter` and a `kernel::fmt::Display` trait. This enables
formatting of foreign types (like `core::ffi::CStr`) that do not
implement `core::fmt::Display` due to concerns around lossy conversions
which do not apply in the kernel.

Suggested-by: Alice Ryhl <aliceryhl@google.com>
Link: https://rust-for-linux.zulipchat.com/#narrow/channel/288089-General/topic/Custom.20formatting/with/516476467
Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Reviewed-by: Alice Ryhl <aliceryhl@google.com>
Acked-by: Danilo Krummrich <dakr@kernel.org>
Reviewed-by: Benno Lossin <lossin@kernel.org>
Signed-off-by: Tamir Duberstein <tamird@gmail.com>
Link: https://patch.msgid.link/20251018-cstr-core-v18-15-9378a54385f8@gmail.com
Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
rust/kernel/fmt.rs
rust/kernel/prelude.rs
rust/macros/fmt.rs [new file with mode: 0644]
rust/macros/lib.rs
rust/macros/quote.rs