diff --git a/src/map.rs b/src/map.rs index 7fdf0f2..ec02cbc 100644 --- a/src/map.rs +++ b/src/map.rs @@ -391,7 +391,7 @@ impl GenericPatriciaMap { /// assert_eq!(vec![(Vec::from("bar"), &2), ("baz".into(), &3), ("foo".into(), &1)], /// map.iter().collect::>()); /// ``` - pub fn iter(&self) -> Iter { + pub fn iter(&self) -> Iter<'_, K, V> { Iter::new(self.tree.nodes(), Vec::new()) } @@ -409,7 +409,7 @@ impl GenericPatriciaMap { /// } /// assert_eq!(map.get("bar"), Some(&12)); /// ``` - pub fn iter_mut(&mut self) -> IterMut { + pub fn iter_mut(&mut self) -> IterMut<'_, K, V> { IterMut::new(self.tree.nodes_mut(), Vec::new()) } @@ -425,7 +425,7 @@ impl GenericPatriciaMap { /// assert_eq!(vec![Vec::from("bar"), "baz".into(), "foo".into()], /// map.keys().collect::>()); /// ``` - pub fn keys(&self) -> Keys { + pub fn keys(&self) -> Keys<'_, K, V> { Keys(self.iter()) } @@ -441,7 +441,7 @@ impl GenericPatriciaMap { /// assert_eq!(vec![2, 3, 1], /// map.values().cloned().collect::>()); /// ``` - pub fn values(&self) -> Values { + pub fn values(&self) -> Values<'_, V> { Values { nodes: self.tree.nodes(), } @@ -462,7 +462,7 @@ impl GenericPatriciaMap { /// assert_eq!(vec![12, 13, 11], /// map.values().cloned().collect::>()); /// ``` - pub fn values_mut(&mut self) -> ValuesMut { + pub fn values_mut(&mut self) -> ValuesMut<'_, V> { ValuesMut { nodes: self.tree.nodes_mut(), } diff --git a/src/node.rs b/src/node.rs index 6930ede..e8e76de 100644 --- a/src/node.rs +++ b/src/node.rs @@ -1,6 +1,6 @@ //! A node which represents a subtree of a patricia tree. use crate::BorrowedBytes; -use alloc::alloc::{alloc, dealloc, handle_alloc_error, Layout}; +use alloc::alloc::{Layout, alloc, dealloc, handle_alloc_error}; use alloc::vec::Vec; use core::marker::PhantomData; use core::{mem, ptr, slice}; @@ -370,26 +370,26 @@ impl Node { } /// Gets an iterator which traverses the nodes in this tree, in depth first order. - pub fn iter(&self) -> Iter { + pub fn iter(&self) -> Iter<'_, V> { Iter { stack: vec![(0, self)], } } /// Gets a mutable iterator which traverses the nodes in this tree, in depth first order. - pub fn iter_mut(&mut self) -> IterMut { + pub fn iter_mut(&mut self) -> IterMut<'_, V> { IterMut { stack: vec![(0, self)], } } - pub(crate) fn iter_descendant(&self) -> Iter { + pub(crate) fn iter_descendant(&self) -> Iter<'_, V> { Iter { stack: vec![(0, self)], } } - pub(crate) fn iter_descendant_mut(&mut self) -> IterMut { + pub(crate) fn iter_descendant_mut(&mut self) -> IterMut<'_, V> { IterMut { stack: vec![(0, self)], } diff --git a/src/set.rs b/src/set.rs index 0f50604..c54e86e 100644 --- a/src/set.rs +++ b/src/set.rs @@ -1,8 +1,8 @@ //! A set based on a patricia tree. +use crate::Bytes; use crate::map::{self, GenericPatriciaMap}; #[cfg(any(feature = "serde", test))] use crate::node::Node; -use crate::Bytes; use alloc::string::String; use alloc::vec::Vec; use core::fmt; @@ -246,7 +246,7 @@ impl GenericPatriciaSet { /// /// assert_eq!(set.iter().collect::>(), [Vec::from("bar"), "baz".into(), "foo".into()]); /// ``` - pub fn iter(&self) -> Iter { + pub fn iter(&self) -> Iter<'_, T> { Iter(self.map.keys()) } } diff --git a/src/tree.rs b/src/tree.rs index 9823ceb..5c75b76 100644 --- a/src/tree.rs +++ b/src/tree.rs @@ -1,8 +1,8 @@ use alloc::vec::Vec; use crate::{ - node::{self, Node, NodeMut}, BorrowedBytes, + node::{self, Node, NodeMut}, }; #[derive(Debug, Clone)] @@ -59,7 +59,10 @@ impl PatriciaTree { .get_longest_common_prefix_mut(key, 0) .map(|(n, v)| (&key.as_bytes()[..n], v)) } - pub fn iter_prefix(&self, prefix: &K) -> Option<(usize, Nodes)> { + pub fn iter_prefix( + &self, + prefix: &K, + ) -> Option<(usize, Nodes<'_, V>)> { if let Some((common_prefix_len, node)) = self.root.get_prefix_node(prefix) { let nodes = Nodes { nodes: node.iter_descendant(), @@ -73,7 +76,7 @@ impl PatriciaTree { pub fn iter_prefix_mut( &mut self, prefix: &K, - ) -> Option<(usize, NodesMut)> { + ) -> Option<(usize, NodesMut<'_, V>)> { if let Some((common_prefix_len, node)) = self.root.get_prefix_node_mut(prefix) { let nodes = NodesMut { nodes: node.iter_descendant_mut(), @@ -119,13 +122,13 @@ impl PatriciaTree { pub fn len(&self) -> usize { self.len } - pub fn nodes(&self) -> Nodes { + pub fn nodes(&self) -> Nodes<'_, V> { Nodes { nodes: self.root.iter(), label_lens: Vec::new(), } } - pub fn nodes_mut(&mut self) -> NodesMut { + pub fn nodes_mut(&mut self) -> NodesMut<'_, V> { NodesMut { nodes: self.root.iter_mut(), label_lens: Vec::new(),