Skip to content

Commit

Permalink
Re-add IntoIter implementation for owned Body
Browse files Browse the repository at this point in the history
This implementation holds the arena from the consumed Body.

Close: #6
  • Loading branch information
hillu committed Nov 22, 2024
1 parent 7b5a235 commit e33561a
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions src/body.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,3 +188,28 @@ impl<'a> IntoIterator for &'a Body<'a> {
self.elems.iter()
}
}

pub struct BodyIterator<'a> {
iter: std::vec::IntoIter<(Key, Value<'a>)>,
_arena: Vec<Vec<u8>>,
_pin: std::marker::PhantomPinned,
}

impl<'a> Iterator for BodyIterator<'a> {
type Item = (Key, Value<'a>);
fn next(&mut self) -> Option<Self::Item> {
self.iter.next()
}
}

impl<'a> IntoIterator for Body<'a> {
type Item = (Key, Value<'a>);
type IntoIter = BodyIterator<'a>;
fn into_iter(self) -> Self::IntoIter {
Self::IntoIter {
iter: self.elems.into_iter(),
_arena: self.arena,
_pin: std::marker::PhantomPinned,
}
}
}

0 comments on commit e33561a

Please sign in to comment.