Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: clippy/cargo linting cleanups #38

Merged
merged 3 commits into from
Jul 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 29 additions & 26 deletions src/client_features.rs
Original file line number Diff line number Diff line change
Expand Up @@ -231,11 +231,7 @@ impl PartialEq for Strategy {
}
impl PartialOrd for Strategy {
fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
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 {
Expand Down Expand Up @@ -292,7 +288,7 @@ pub struct StrategyVariant {

impl PartialOrd for Variant {
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
self.name.partial_cmp(&other.name)
Some(self.cmp(other))
}
}
impl Ord for Variant {
Expand All @@ -317,7 +313,7 @@ impl PartialEq for Segment {

impl PartialOrd for Segment {
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
self.id.partial_cmp(&other.id)
Some(self.cmp(other))
}
}

Expand Down Expand Up @@ -424,7 +420,7 @@ impl Upsert for ClientFeatures {

impl PartialOrd for ClientFeature {
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
self.name.partial_cmp(&other.name)
Some(self.cmp(other))
}
}

Expand Down Expand Up @@ -481,7 +477,7 @@ mod tests {

#[derive(Debug)]
pub enum EdgeError {
SomethingWentWrong(String),
SomethingWentWrong,
}
#[test]
pub fn ordering_is_stable_for_constraints() {
Expand Down Expand Up @@ -516,7 +512,7 @@ mod tests {

fn read_file(path: PathBuf) -> Result<BufReader<File>, EdgeError> {
File::open(path)
.map_err(|e| EdgeError::SomethingWentWrong(e.to_string()))
.map_err(|_| EdgeError::SomethingWentWrong)
.map(BufReader::new)
}

Expand Down Expand Up @@ -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);
}

Expand Down
8 changes: 4 additions & 4 deletions src/client_metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,15 +155,15 @@ impl ClientApplication {
.strategies
.clone()
.into_iter()
.chain(strategies.into_iter())
.chain(strategies)
.collect::<HashSet<String>>()
.into_iter()
.collect();
self.strategies = unique_strats;
}

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(),
Expand All @@ -182,7 +182,7 @@ impl Merge for ClientApplication {
let mut merged_strategies: Vec<String> = self
.strategies
.into_iter()
.chain(other.strategies.into_iter())
.chain(other.strategies)
.collect::<HashSet<String>>()
.into_iter()
.collect();
Expand All @@ -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<ConnectVia> = initial.chain(other_iter).collect();
connect_via
})
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ mod tests {

let result = first
.into_iter()
.chain(second.into_iter())
.chain(second)
.collect::<Vec<u32>>()
.deduplicate();
assert!(result.len() == 5);
Expand Down
Loading