Skip to content

Commit f2a1e4f

Browse files
committed
kernel_cmdline: Derive Default for Cmdline
Signed-off-by: John Eckersberg <[email protected]>
1 parent 28d20f5 commit f2a1e4f

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

crates/kernel_cmdline/src/bytes.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use anyhow::Result;
1414
/// Wraps the raw command line bytes and provides methods for parsing and iterating
1515
/// over individual parameters. Uses copy-on-write semantics to avoid unnecessary
1616
/// allocations when working with borrowed data.
17-
#[derive(Debug)]
17+
#[derive(Debug, Default)]
1818
pub struct Cmdline<'a>(Cow<'a, [u8]>);
1919

2020
impl<'a, T: AsRef<[u8]> + ?Sized> From<&'a T> for Cmdline<'a> {
@@ -539,6 +539,12 @@ mod tests {
539539
assert!(kargs.find("nothing").is_none());
540540
}
541541

542+
#[test]
543+
fn test_cmdline_default() {
544+
let kargs: Cmdline = Default::default();
545+
assert_eq!(kargs.iter().next(), None);
546+
}
547+
542548
#[test]
543549
fn test_kargs_iter_utf8() {
544550
let kargs = Cmdline::from(b"foo=bar,bar2 \xff baz=fuz bad=oh\xffno wiz");

crates/kernel_cmdline/src/utf8.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use anyhow::Result;
1414
/// Wraps the raw command line bytes and provides methods for parsing and iterating
1515
/// over individual parameters. Uses copy-on-write semantics to avoid unnecessary
1616
/// allocations when working with borrowed data.
17-
#[derive(Debug)]
17+
#[derive(Debug, Default)]
1818
pub struct Cmdline<'a>(bytes::Cmdline<'a>);
1919

2020
impl<'a, T: AsRef<str> + ?Sized> From<&'a T> for Cmdline<'a> {
@@ -494,6 +494,12 @@ mod tests {
494494
assert!(kargs.find("nothing").is_none());
495495
}
496496

497+
#[test]
498+
fn test_cmdline_default() {
499+
let kargs: Cmdline = Default::default();
500+
assert_eq!(kargs.iter().next(), None);
501+
}
502+
497503
#[test]
498504
fn test_kargs_simple_from_string() {
499505
let kargs = Cmdline::from("foo=bar,bar2 baz=fuz wiz".to_string());

0 commit comments

Comments
 (0)