@@ -16,7 +16,7 @@ use serde::{Deserialize, Serialize};
1616/// Wraps the raw command line bytes and provides methods for parsing and iterating
1717/// over individual parameters. Uses copy-on-write semantics to avoid unnecessary
1818/// allocations when working with borrowed data.
19- #[ derive( Clone , Debug , Default , PartialEq , Eq , Serialize , Deserialize ) ]
19+ #[ derive( Clone , Debug , Default , Serialize , Deserialize ) ]
2020pub struct Cmdline < ' a > ( Cow < ' a , [ u8 ] > ) ;
2121
2222/// An owned Cmdline. Alias for `Cmdline<'static>`.
@@ -374,6 +374,21 @@ impl<'a, 'other> Extend<Parameter<'other>> for Cmdline<'a> {
374374 }
375375}
376376
377+ impl PartialEq for Cmdline < ' _ > {
378+ fn eq ( & self , other : & Self ) -> bool {
379+ let our_params = self . iter ( ) . collect :: < Vec < _ > > ( ) ;
380+ let their_params = other. iter ( ) . collect :: < Vec < _ > > ( ) ;
381+
382+ if our_params. len ( ) != their_params. len ( ) {
383+ return false ;
384+ }
385+
386+ our_params. iter ( ) . all ( |p| their_params. contains ( p) )
387+ }
388+ }
389+
390+ impl Eq for Cmdline < ' _ > { }
391+
377392/// A single kernel command line parameter key
378393///
379394/// Handles quoted values and treats dashes and underscores in keys as equivalent.
@@ -1066,4 +1081,21 @@ mod tests {
10661081
10671082 assert_eq ! ( params. len( ) , 0 ) ;
10681083 }
1084+
1085+ #[ test]
1086+ fn test_cmdline_eq ( ) {
1087+ // Ordering, quoting, and the whole dash-underscore
1088+ // equivalence thing shouldn't affect whether these are
1089+ // semantically equal
1090+ assert_eq ! (
1091+ Cmdline :: from( "foo bar-with-delim=\" with spaces\" " ) ,
1092+ Cmdline :: from( "\" bar_with_delim=with spaces\" foo" )
1093+ ) ;
1094+
1095+ // Uneven lengths are not equal even if the parameters are. Or
1096+ // to put it another way, duplicate parameters break equality.
1097+ // Check with both orderings.
1098+ assert_ne ! ( Cmdline :: from( "foo" ) , Cmdline :: from( "foo foo" ) ) ;
1099+ assert_ne ! ( Cmdline :: from( "foo foo" ) , Cmdline :: from( "foo" ) ) ;
1100+ }
10691101}
0 commit comments