Skip to content

Commit ff63bd3

Browse files
authored
feat: extend api with iterator for routes (#41)
* feat: extend api with iterator for routes Forward iterator access to the routes to allow collecting them as a client. This allows eg. collecting the routes to subscribe them when using the router in an MQTT usecase. Signed-off-by: Marc Bodmer <marc.bodmer@securiton.ch> * feat: also add into_iter() clippy requests an implementation of into_iter() when implementing iter() Signed-off-by: Marc Bodmer <marc.bodmer@securiton.ch> * feat: implement IntoIterator trait instead of forwarding from vec Signed-off-by: Marc Bodmer <marc.bodmer@securiton.ch> * fix: implement IntoIterator for &PathTree<T> Signed-off-by: Marc Bodmer <marc.bodmer@securiton.ch> --------- Signed-off-by: Marc Bodmer <marc.bodmer@securiton.ch>
1 parent 14dde2b commit ff63bd3

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

src/lib.rs

+14-1
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ use alloc::{
142142
string::{String, ToString},
143143
vec::Vec,
144144
};
145-
use core::str::from_utf8;
145+
use core::{slice::Iter, str::from_utf8};
146146
use smallvec::SmallVec;
147147

148148
mod node;
@@ -258,6 +258,19 @@ impl<T> PathTree<T> {
258258
from_utf8(&bytes).map(ToString::to_string).ok()
259259
})
260260
}
261+
262+
pub fn iter(&self) -> Iter<'_, (T, Vec<Piece>)> {
263+
self.routes.iter()
264+
}
265+
}
266+
267+
impl<'a, T> IntoIterator for &'a PathTree<T> {
268+
type Item = &'a (T, Vec<Piece>);
269+
type IntoIter = Iter<'a, (T, Vec<Piece>)>;
270+
271+
fn into_iter(self) -> Self::IntoIter {
272+
self.iter()
273+
}
261274
}
262275

263276
/// Matched route path infomation.

0 commit comments

Comments
 (0)