@@ -17,7 +17,7 @@ use serde::{Deserialize, Serialize};
1717/// Wraps the raw command line bytes and provides methods for parsing and iterating
1818/// over individual parameters. Uses copy-on-write semantics to avoid unnecessary
1919/// allocations when working with borrowed data.
20- #[ derive( Clone , Debug , Default , PartialEq , Eq , Serialize , Deserialize ) ]
20+ #[ derive( Clone , Debug , Default , Serialize , Deserialize ) ]
2121pub struct Cmdline < ' a > ( Cow < ' a , [ u8 ] > ) ;
2222
2323/// An owned Cmdline. Alias for `Cmdline<'static>`.
@@ -375,6 +375,19 @@ impl<'a, 'other> Extend<Parameter<'other>> for Cmdline<'a> {
375375 }
376376}
377377
378+ impl PartialEq for Cmdline < ' _ > {
379+ fn eq ( & self , other : & Self ) -> bool {
380+ let mut our_params = self . iter ( ) . collect :: < Vec < _ > > ( ) ;
381+ our_params. sort ( ) ;
382+ let mut their_params = other. iter ( ) . collect :: < Vec < _ > > ( ) ;
383+ their_params. sort ( ) ;
384+
385+ our_params == their_params
386+ }
387+ }
388+
389+ impl Eq for Cmdline < ' _ > { }
390+
378391/// A single kernel command line parameter key
379392///
380393/// Handles quoted values and treats dashes and underscores in keys as equivalent.
@@ -1091,4 +1104,24 @@ mod tests {
10911104
10921105 assert_eq ! ( params. len( ) , 0 ) ;
10931106 }
1107+
1108+ #[ test]
1109+ fn test_cmdline_eq ( ) {
1110+ // Ordering, quoting, and the whole dash-underscore
1111+ // equivalence thing shouldn't affect whether these are
1112+ // semantically equal
1113+ assert_eq ! (
1114+ Cmdline :: from( "foo bar-with-delim=\" with spaces\" " ) ,
1115+ Cmdline :: from( "\" bar_with_delim=with spaces\" foo" )
1116+ ) ;
1117+
1118+ // Uneven lengths are not equal even if the parameters are. Or
1119+ // to put it another way, duplicate parameters break equality.
1120+ // Check with both orderings.
1121+ assert_ne ! ( Cmdline :: from( "foo" ) , Cmdline :: from( "foo foo" ) ) ;
1122+ assert_ne ! ( Cmdline :: from( "foo foo" ) , Cmdline :: from( "foo" ) ) ;
1123+
1124+ // Equal lengths but differing duplicates are also not equal
1125+ assert_ne ! ( Cmdline :: from( "a a b" ) , Cmdline :: from( "a b b" ) ) ;
1126+ }
10941127}
0 commit comments