From 852a1745f34e980c842bf90a19432a083a754d14 Mon Sep 17 00:00:00 2001 From: Melody Horn Date: Sun, 27 Mar 2022 23:55:22 -0600 Subject: lints for days --- src/lib.rs | 71 +++++++++++++++++++++++++++++++------------------------------- 1 file changed, 35 insertions(+), 36 deletions(-) (limited to 'src') diff --git a/src/lib.rs b/src/lib.rs index b622326..c0f742a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,4 +1,17 @@ #![doc = include_str!("../README.md")] +#![warn( + elided_lifetimes_in_paths, + explicit_outlives_requirements, + missing_debug_implementations, + noop_method_call, + single_use_lifetimes, + trivial_casts, + trivial_numeric_casts, + unreachable_pub, + unsafe_code, + unused_crate_dependencies, + unused_qualifications +)] #![warn(clippy::pedantic, clippy::cargo)] #[cfg(feature = "parse-knuffel")] @@ -26,43 +39,43 @@ pub struct Schema { impl Schema { /// Panics if ref is not of the form `[id="foo"]`. + #[must_use] pub fn resolve_node_ref(&self, r#ref: &str) -> Option<&Node> { let id = get_id_from_ref(r#ref).expect("invalid ref"); self.document .nodes .iter() - .filter_map(|node| node.find_node_by_id(id)) - .next() + .find_map(|node| node.find_node_by_id(id)) } /// Panics if ref is not of the form `[id="foo"]`. + #[must_use] pub fn resolve_prop_ref(&self, r#ref: &str) -> Option<&Prop> { let id = get_id_from_ref(r#ref).expect("invalid ref"); self.document .nodes .iter() - .filter_map(|node| node.find_prop_by_id(id)) - .next() + .find_map(|node| node.find_prop_by_id(id)) } /// Panics if ref is not of the form `[id="foo"]`. + #[must_use] pub fn resolve_value_ref(&self, r#ref: &str) -> Option<&Value> { let id = get_id_from_ref(r#ref).expect("invalid ref"); self.document .nodes .iter() - .filter_map(|node| node.find_value_by_id(id)) - .next() + .find_map(|node| node.find_value_by_id(id)) } /// Panics if ref is not of the form `[id="foo"]`. + #[must_use] pub fn resolve_children_ref(&self, r#ref: &str) -> Option<&Children> { let id = get_id_from_ref(r#ref).expect("invalid ref"); self.document .nodes .iter() - .filter_map(|node| node.find_children_by_id(id)) - .next() + .find_map(|node| node.find_children_by_id(id)) } } @@ -186,40 +199,36 @@ impl Node { } else { self.children .iter() - .filter_map(|children| children.find_node_by_id(id)) - .next() + .find_map(|children| children.find_node_by_id(id)) } } fn find_prop_by_id(&self, id: &str) -> Option<&Prop> { self.props .iter() - .filter_map(|prop| prop.find_prop_by_id(id)) - .chain( + .find_map(|prop| prop.find_prop_by_id(id)) + .or_else(|| { self.children .iter() - .filter_map(|children| children.find_prop_by_id(id)), - ) - .next() + .find_map(|children| children.find_prop_by_id(id)) + }) } fn find_value_by_id(&self, id: &str) -> Option<&Value> { self.values .iter() - .filter_map(|value| value.find_value_by_id(id)) - .chain( + .find_map(|value| value.find_value_by_id(id)) + .or_else(|| { self.children .iter() - .filter_map(|children| children.find_value_by_id(id)), - ) - .next() + .find_map(|children| children.find_value_by_id(id)) + }) } fn find_children_by_id(&self, id: &str) -> Option<&Children> { self.children .iter() - .filter_map(|children| children.find_children_by_id(id)) - .next() + .find_map(|children| children.find_children_by_id(id)) } } @@ -319,24 +328,15 @@ pub struct Children { impl Children { fn find_node_by_id(&self, id: &str) -> Option<&Node> { - self.nodes - .iter() - .filter_map(|node| node.find_node_by_id(id)) - .next() + self.nodes.iter().find_map(|node| node.find_node_by_id(id)) } fn find_prop_by_id(&self, id: &str) -> Option<&Prop> { - self.nodes - .iter() - .filter_map(|node| node.find_prop_by_id(id)) - .next() + self.nodes.iter().find_map(|node| node.find_prop_by_id(id)) } fn find_value_by_id(&self, id: &str) -> Option<&Value> { - self.nodes - .iter() - .filter_map(|node| node.find_value_by_id(id)) - .next() + self.nodes.iter().find_map(|node| node.find_value_by_id(id)) } fn find_children_by_id(&self, id: &str) -> Option<&Children> { @@ -345,8 +345,7 @@ impl Children { } else { self.nodes .iter() - .filter_map(|node| node.find_children_by_id(id)) - .next() + .find_map(|node| node.find_children_by_id(id)) } } } -- cgit v1.2.3