File tree Expand file tree Collapse file tree 2 files changed +34
-0
lines changed
crates/kernel_cmdline/src Expand file tree Collapse file tree 2 files changed +34
-0
lines changed Original file line number Diff line number Diff line change @@ -51,6 +51,13 @@ impl<'a> Iterator for CmdlineIter<'a> {
5151}
5252
5353impl < ' a > Cmdline < ' a > {
54+ /// Creates a new empty owned `Cmdline`.
55+ ///
56+ /// This is equivalent to `Cmdline::default()` but makes ownership explicit.
57+ pub fn new ( ) -> Cmdline < ' static > {
58+ Cmdline :: default ( )
59+ }
60+
5461 /// Reads the kernel command line from `/proc/cmdline`.
5562 ///
5663 /// Returns an error if the file cannot be read or if there are I/O issues.
@@ -609,6 +616,16 @@ mod tests {
609616 assert_eq ! ( kargs. iter( ) . next( ) , None ) ;
610617 }
611618
619+ #[ test]
620+ fn test_cmdline_new ( ) {
621+ let kargs = Cmdline :: new ( ) ;
622+ assert_eq ! ( kargs. iter( ) . next( ) , None ) ;
623+ assert ! ( kargs. is_owned( ) ) ;
624+
625+ // Verify we can store it in a 'static context
626+ let _static_kargs: Cmdline < ' static > = Cmdline :: new ( ) ;
627+ }
628+
612629 #[ test]
613630 fn test_kargs_iter_utf8 ( ) {
614631 let kargs = Cmdline :: from ( b"foo=bar,bar2 \xff baz=fuz bad=oh\xff no wiz" ) ;
Original file line number Diff line number Diff line change @@ -50,6 +50,13 @@ impl<'a> Iterator for CmdlineIter<'a> {
5050}
5151
5252impl < ' a > Cmdline < ' a > {
53+ /// Creates a new empty owned `Cmdline`.
54+ ///
55+ /// This is equivalent to `Cmdline::default()` but makes ownership explicit.
56+ pub fn new ( ) -> Cmdline < ' static > {
57+ Cmdline :: default ( )
58+ }
59+
5360 /// Reads the kernel command line from `/proc/cmdline`.
5461 ///
5562 /// Returns an error if:
@@ -550,6 +557,16 @@ mod tests {
550557 assert_eq ! ( kargs. iter( ) . next( ) , None ) ;
551558 }
552559
560+ #[ test]
561+ fn test_cmdline_new ( ) {
562+ let kargs = Cmdline :: new ( ) ;
563+ assert_eq ! ( kargs. iter( ) . next( ) , None ) ;
564+ assert ! ( kargs. is_owned( ) ) ;
565+
566+ // Verify we can store it in a 'static context
567+ let _static_kargs: Cmdline < ' static > = Cmdline :: new ( ) ;
568+ }
569+
553570 #[ test]
554571 fn test_kargs_simple_from_string ( ) {
555572 let kargs = Cmdline :: from ( "foo=bar,bar2 baz=fuz wiz" . to_string ( ) ) ;
You can’t perform that action at this time.
0 commit comments