Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

rust: device: use `kernel::{fmt,prelude::fmt!}`

Reduce coupling to implementation details of the formatting machinery by
avoiding direct use for `core`'s formatting traits and macros.

Signed-off-by: Tamir Duberstein <tamird@gmail.com>
Reviewed-by: Benno Lossin <lossin@kernel.org>
Signed-off-by: Miguel Ojeda <ojeda@kernel.org>

authored by

Tamir Duberstein and committed by
Miguel Ojeda
eb985995 0fe1ca3c

+12 -11
+12 -11
rust/kernel/device/property.rs
··· 11 11 alloc::KVec, 12 12 bindings, 13 13 error::{to_result, Result}, 14 + fmt, 14 15 prelude::*, 15 16 str::{CStr, CString}, 16 17 types::{ARef, Opaque}, ··· 69 68 unsafe { bindings::is_of_node(self.as_raw()) } 70 69 } 71 70 72 - /// Returns an object that implements [`Display`](core::fmt::Display) for 71 + /// Returns an object that implements [`Display`](fmt::Display) for 73 72 /// printing the name of a node. 74 73 /// 75 74 /// This is an alternative to the default `Display` implementation, which 76 75 /// prints the full path. 77 - pub fn display_name(&self) -> impl core::fmt::Display + '_ { 76 + pub fn display_name(&self) -> impl fmt::Display + '_ { 78 77 struct FwNodeDisplayName<'a>(&'a FwNode); 79 78 80 - impl core::fmt::Display for FwNodeDisplayName<'_> { 81 - fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { 79 + impl fmt::Display for FwNodeDisplayName<'_> { 80 + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { 82 81 // SAFETY: `self` is valid by its type invariant. 83 82 let name = unsafe { bindings::fwnode_get_name(self.0.as_raw()) }; 84 83 if name.is_null() { ··· 88 87 // - `fwnode_get_name` returns null or a valid C string. 89 88 // - `name` was checked to be non-null. 90 89 let name = unsafe { CStr::from_char_ptr(name) }; 91 - write!(f, "{name}") 90 + fmt::Display::fmt(name, f) 92 91 } 93 92 } 94 93 ··· 352 351 } 353 352 } 354 353 355 - impl core::fmt::Debug for FwNodeReferenceArgs { 356 - fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { 354 + impl fmt::Debug for FwNodeReferenceArgs { 355 + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { 357 356 write!(f, "{:?}", self.as_slice()) 358 357 } 359 358 } ··· 378 377 Owned(ARef<FwNode>), 379 378 } 380 379 381 - impl core::fmt::Display for FwNode { 382 - fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { 380 + impl fmt::Display for FwNode { 381 + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { 383 382 // The logic here is the same as the one in lib/vsprintf.c 384 383 // (fwnode_full_name_string). 385 384 ··· 414 413 // SAFETY: `fwnode_get_name_prefix` returns null or a 415 414 // valid C string. 416 415 let prefix = unsafe { CStr::from_char_ptr(prefix) }; 417 - write!(f, "{prefix}")?; 416 + fmt::Display::fmt(prefix, f)?; 418 417 } 419 - write!(f, "{}", fwnode.display_name())?; 418 + fmt::Display::fmt(&fwnode.display_name(), f)?; 420 419 } 421 420 422 421 Ok(())