diff options
author | Melody Horn <melody@boringcactus.com> | 2022-03-27 23:55:22 -0600 |
---|---|---|
committer | Melody Horn <melody@boringcactus.com> | 2022-03-27 23:55:22 -0600 |
commit | 852a1745f34e980c842bf90a19432a083a754d14 (patch) | |
tree | 90475edadb1934f5dce538322915b5e5f9c28880 /src | |
parent | e3c35955a24286d4e654e4cc3498294ac7bc2f99 (diff) | |
download | kdl-schema-852a1745f34e980c842bf90a19432a083a754d14.tar.gz kdl-schema-852a1745f34e980c842bf90a19432a083a754d14.zip |
lints for days
Diffstat (limited to 'src')
-rw-r--r-- | src/lib.rs | 71 |
1 files changed, 35 insertions, 36 deletions
@@ -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)) } } } |