diff --git a/src/header/shared/quality_item.rs b/src/header/shared/quality_item.rs index 0e953f05d7..a83060d60f 100644 --- a/src/header/shared/quality_item.rs +++ b/src/header/shared/quality_item.rs @@ -5,6 +5,7 @@ use std::fmt; use std::str; +use std::cmp; #[cfg(test)] use super::encoding::*; /// Represents an item with a quality value as defined in @@ -26,6 +27,12 @@ impl QualityItem { } } +impl cmp::PartialOrd for QualityItem { + fn partial_cmp(&self, other: &QualityItem) -> Option { + self.quality.partial_cmp(&other.quality) + } +} + impl fmt::Display for QualityItem { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { if self.quality == 1.0 { @@ -127,3 +134,10 @@ fn test_quality_item_from_str5() { let x: Result, ()> = "gzip; q=0.2739999".parse(); assert_eq!(x, Err(())); } +#[test] +fn test_quality_item_ordering() { + let x: QualityItem = "gzip; q=0.5".parse().ok().unwrap(); + let y: QualityItem = "gzip; q=0.273".parse().ok().unwrap(); + let comparision_result: bool = x.gt(&y); + assert_eq!(comparision_result, true) +}