Skip to content

Commit 8952194

Browse files
authored
RUST-1534: implement iter_mut on Document (#382)
1 parent 0612667 commit 8952194

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

src/document.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,11 @@ pub struct Values<'a> {
117117
inner: indexmap::map::Values<'a, String, Bson>,
118118
}
119119

120+
/// An iterator over a `Document`'s keys and mutable values.
121+
pub struct IterMut<'a> {
122+
inner: indexmap::map::IterMut<'a, String, Bson>,
123+
}
124+
120125
impl<'a> Iterator for Keys<'a> {
121126
type Item = &'a String;
122127

@@ -181,6 +186,14 @@ impl<'a> Iterator for Iter<'a> {
181186
}
182187
}
183188

189+
impl<'a> Iterator for IterMut<'a> {
190+
type Item = (&'a String, &'a mut Bson);
191+
192+
fn next(&mut self) -> Option<(&'a String, &'a mut Bson)> {
193+
self.inner.next()
194+
}
195+
}
196+
184197
impl Document {
185198
/// Creates a new empty Document.
186199
pub fn new() -> Document {
@@ -194,6 +207,13 @@ impl Document {
194207
self.into_iter()
195208
}
196209

210+
/// Gets an iterator over pairs of keys and mutable values.
211+
pub fn iter_mut(&mut self) -> IterMut {
212+
IterMut {
213+
inner: self.inner.iter_mut(),
214+
}
215+
}
216+
197217
/// Clears the document, removing all values.
198218
pub fn clear(&mut self) {
199219
self.inner.clear();

src/raw/document.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ use crate::{oid::ObjectId, spec::ElementType, Document};
2828

2929
/// A slice of a BSON document (akin to [`std::str`]). This can be created from a
3030
/// [`RawDocumentBuf`] or any type that contains valid BSON data, including static binary literals,
31-
/// [Vec<u8>](std::vec::Vec), or arrays.
31+
/// [`Vec<u8>`](std::vec::Vec), or arrays.
3232
///
3333
/// This is an _unsized_ type, meaning that it must always be used behind a pointer like `&`. For an
3434
/// owned version of this type, see [`RawDocumentBuf`].

0 commit comments

Comments
 (0)