File tree 1 file changed +14
-0
lines changed 1 file changed +14
-0
lines changed Original file line number Diff line number Diff line change 5
5
6
6
use std:: fmt;
7
7
use std:: str;
8
+ use std:: cmp;
8
9
#[ cfg( test) ] use super :: encoding:: * ;
9
10
10
11
/// Represents an item with a quality value as defined in
@@ -26,6 +27,12 @@ impl<T> QualityItem<T> {
26
27
}
27
28
}
28
29
30
+ impl < T : PartialEq > cmp:: PartialOrd for QualityItem < T > {
31
+ fn partial_cmp ( & self , other : & QualityItem < T > ) -> Option < cmp:: Ordering > {
32
+ self . quality . partial_cmp ( & other. quality )
33
+ }
34
+ }
35
+
29
36
impl < T : fmt:: Display > fmt:: Display for QualityItem < T > {
30
37
fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
31
38
if self . quality == 1.0 {
@@ -127,3 +134,10 @@ fn test_quality_item_from_str5() {
127
134
let x: Result < QualityItem < Encoding > , ( ) > = "gzip; q=0.2739999" . parse ( ) ;
128
135
assert_eq ! ( x, Err ( ( ) ) ) ;
129
136
}
137
+ #[ test]
138
+ fn test_quality_item_ordering ( ) {
139
+ let x: QualityItem < Encoding > = "gzip; q=0.5" . parse ( ) . ok ( ) . unwrap ( ) ;
140
+ let y: QualityItem < Encoding > = "gzip; q=0.273" . parse ( ) . ok ( ) . unwrap ( ) ;
141
+ let comparision_result: bool = x. gt ( & y) ;
142
+ assert_eq ! ( comparision_result, true )
143
+ }
You can’t perform that action at this time.
0 commit comments