diff --git a/src/client_features.rs b/src/client_features.rs index ce620b1..d0defdf 100644 --- a/src/client_features.rs +++ b/src/client_features.rs @@ -231,11 +231,7 @@ impl PartialEq for Strategy { } impl PartialOrd for Strategy { fn partial_cmp(&self, other: &Self) -> Option { - match self.sort_order.partial_cmp(&other.sort_order) { - Some(core::cmp::Ordering::Equal) => self.name.partial_cmp(&other.name), - Some(s) => Some(s), - None => self.name.partial_cmp(&other.name), - } + Some(self.cmp(other)) } } impl Ord for Strategy { @@ -292,7 +288,7 @@ pub struct StrategyVariant { impl PartialOrd for Variant { fn partial_cmp(&self, other: &Self) -> Option { - self.name.partial_cmp(&other.name) + Some(self.cmp(other)) } } impl Ord for Variant { @@ -317,7 +313,7 @@ impl PartialEq for Segment { impl PartialOrd for Segment { fn partial_cmp(&self, other: &Self) -> Option { - self.id.partial_cmp(&other.id) + Some(self.cmp(other)) } } @@ -424,7 +420,7 @@ impl Upsert for ClientFeatures { impl PartialOrd for ClientFeature { fn partial_cmp(&self, other: &Self) -> Option { - self.name.partial_cmp(&other.name) + Some(self.cmp(other)) } } @@ -481,7 +477,7 @@ mod tests { #[derive(Debug)] pub enum EdgeError { - SomethingWentWrong(String), + SomethingWentWrong, } #[test] pub fn ordering_is_stable_for_constraints() { @@ -516,7 +512,7 @@ mod tests { fn read_file(path: PathBuf) -> Result, EdgeError> { File::open(path) - .map_err(|e| EdgeError::SomethingWentWrong(e.to_string())) + .map_err(|_| EdgeError::SomethingWentWrong) .map(BufReader::new) } @@ -657,26 +653,33 @@ mod tests { pub fn when_strategy_variants_is_none_default_to_empty_vec() { let client_features = ClientFeatures { version: 2, - features: vec![ - ClientFeature { - name: "feature1".into(), - strategies: Some(vec![Strategy { - name: "default".into(), - sort_order: Some(124), - segments: None, - constraints: None, - parameters: None, - variants: None - }]), - ..ClientFeature::default() - }, - ], + features: vec![ClientFeature { + name: "feature1".into(), + strategies: Some(vec![Strategy { + name: "default".into(), + sort_order: Some(124), + segments: None, + constraints: None, + parameters: None, + variants: None, + }]), + ..ClientFeature::default() + }], segments: None, query: None, }; let client_features_json = serde_json::to_string(&client_features).unwrap(); - let client_features_parsed: ClientFeatures = serde_json::from_str(&client_features_json).unwrap(); - let strategy = client_features_parsed.features.first().unwrap().strategies.as_ref().unwrap().first().unwrap(); + let client_features_parsed: ClientFeatures = + serde_json::from_str(&client_features_json).unwrap(); + let strategy = client_features_parsed + .features + .first() + .unwrap() + .strategies + .as_ref() + .unwrap() + .first() + .unwrap(); assert_eq!(strategy.variants.as_ref().unwrap().len(), 0); } diff --git a/src/client_metrics.rs b/src/client_metrics.rs index a6e4275..0a77a20 100644 --- a/src/client_metrics.rs +++ b/src/client_metrics.rs @@ -155,7 +155,7 @@ impl ClientApplication { .strategies .clone() .into_iter() - .chain(strategies.into_iter()) + .chain(strategies) .collect::>() .into_iter() .collect(); @@ -163,7 +163,7 @@ impl ClientApplication { } pub fn connect_via(&self, app_name: &str, instance_id: &str) -> ClientApplication { - let mut connect_via = self.connect_via.clone().unwrap_or(vec![]); + let mut connect_via = self.connect_via.clone().unwrap_or_default(); connect_via.push(ConnectVia { app_name: app_name.into(), instance_id: instance_id.into(), @@ -182,7 +182,7 @@ impl Merge for ClientApplication { let mut merged_strategies: Vec = self .strategies .into_iter() - .chain(other.strategies.into_iter()) + .chain(other.strategies) .collect::>() .into_iter() .collect(); @@ -191,7 +191,7 @@ impl Merge for ClientApplication { .connect_via .map(|c| { let initial = c.into_iter(); - let other_iter = other.connect_via.clone().unwrap_or(vec![]).into_iter(); + let other_iter = other.connect_via.clone().unwrap_or_default().into_iter(); let connect_via: Vec = initial.chain(other_iter).collect(); connect_via }) diff --git a/src/lib.rs b/src/lib.rs index ad8e39b..ef1394c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -139,7 +139,7 @@ mod tests { let result = first .into_iter() - .chain(second.into_iter()) + .chain(second) .collect::>() .deduplicate(); assert!(result.len() == 5);