Skip to content

Commit 1486554

Browse files
committed
rust: str: simplify KUnit tests format! macro
Simplify the `format!` macro used in the tests by using `CString::try_from_fmt` and directly `unwrap()`ing. This will allow us to change both `unwrap()`s here in order to showcase the `?` operator support now that the tests are KUnit ones. Reviewed-by: David Gow <davidgow@google.com> Acked-by: Danilo Krummrich <dakr@kernel.org> [ Split from the next commit as suggested by Tamir. - Miguel ] Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
1 parent 028df91 commit 1486554

File tree

1 file changed

+1
-17
lines changed

1 file changed

+1
-17
lines changed

rust/kernel/str.rs

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -576,25 +576,9 @@ macro_rules! c_str {
576576
mod tests {
577577
use super::*;
578578

579-
struct String(CString);
580-
581-
impl String {
582-
fn from_fmt(args: fmt::Arguments<'_>) -> Self {
583-
String(CString::try_from_fmt(args).unwrap())
584-
}
585-
}
586-
587-
impl Deref for String {
588-
type Target = str;
589-
590-
fn deref(&self) -> &str {
591-
self.0.to_str().unwrap()
592-
}
593-
}
594-
595579
macro_rules! format {
596580
($($f:tt)*) => ({
597-
&*String::from_fmt(::kernel::fmt!($($f)*))
581+
CString::try_from_fmt(::kernel::fmt!($($f)*)).unwrap().to_str().unwrap()
598582
})
599583
}
600584

0 commit comments

Comments
 (0)