Skip to content

Commit 3eece0d

Browse files
committed
Use BTreeMap.remove() in consuming iterator
1 parent 717c1cc commit 3eece0d

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

src/ordered.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ impl<'a> Iterator for Keys<'a> {
4040

4141
impl<'a> Iterator for Values<'a> {
4242
type Item = &'a Bson;
43-
4443
fn next(&mut self) -> Option<(&'a Bson)> { self.inner.next() }
4544
}
4645

@@ -84,7 +83,7 @@ impl<'a> Iterator for OrderedDocumentIntoIterator {
8483
fn next(&mut self) -> Option<(String, Bson)> {
8584
match self.vec_iter.next() {
8685
Some(key) => {
87-
let val = self.document.get(&key[..]).unwrap();
86+
let val = self.document.remove(&key[..]).unwrap();
8887
Some((key, val.to_owned()))
8988
},
9089
None => None,
@@ -96,7 +95,10 @@ impl<'a> Iterator for OrderedDocumentIterator<'a> {
9695
type Item = (&'a String, &'a Bson);
9796
fn next(&mut self) -> Option<(&'a String, &'a Bson)> {
9897
match self.vec_iter.next() {
99-
Some(key) => Some((&key, self.document.get(&key[..]).unwrap())),
98+
Some(key) => {
99+
let val = self.document.get(&key[..]).unwrap();
100+
Some((&key, val))
101+
},
100102
None => None,
101103
}
102104
}

0 commit comments

Comments
 (0)