From 5a1499427b3225f6ba0fede31b29a2a555307cf9 Mon Sep 17 00:00:00 2001 From: Abraham Egnor Date: Wed, 2 Nov 2022 12:16:38 -0400 Subject: [PATCH 1/3] minor: implement iter_mut on Document --- src/document.rs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/document.rs b/src/document.rs index 54b22dcb..0e7cb6d7 100644 --- a/src/document.rs +++ b/src/document.rs @@ -117,6 +117,11 @@ pub struct Values<'a> { inner: indexmap::map::Values<'a, String, Bson>, } +/// An iterator over a Document's keys and mutable values. +pub struct IterMut<'a> { + inner: indexmap::map::IterMut<'a, String, Bson>, +} + impl<'a> Iterator for Keys<'a> { type Item = &'a String; @@ -181,6 +186,14 @@ impl<'a> Iterator for Iter<'a> { } } +impl<'a> Iterator for IterMut<'a> { + type Item = (&'a String, &'a mut Bson); + + fn next(&mut self) -> Option<(&'a String, &'a mut Bson)> { + self.inner.next() + } +} + impl Document { /// Creates a new empty Document. pub fn new() -> Document { @@ -194,6 +207,13 @@ impl Document { self.into_iter() } + /// Gets an iterator over pairs of keys and mutable values. + pub fn iter_mut(&mut self) -> IterMut { + IterMut { + inner: self.inner.iter_mut(), + } + } + /// Clears the document, removing all values. pub fn clear(&mut self) { self.inner.clear(); From b521cc4fb06511ef67b4ceba64e6344d7093d6a9 Mon Sep 17 00:00:00 2001 From: Abraham Egnor Date: Wed, 2 Nov 2022 12:25:13 -0400 Subject: [PATCH 2/3] fix unrelated rustdoc --- src/raw/document.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/raw/document.rs b/src/raw/document.rs index fb5f86dc..b5193067 100644 --- a/src/raw/document.rs +++ b/src/raw/document.rs @@ -28,7 +28,7 @@ use crate::{oid::ObjectId, spec::ElementType, Document}; /// A slice of a BSON document (akin to [`std::str`]). This can be created from a /// [`RawDocumentBuf`] or any type that contains valid BSON data, including static binary literals, -/// [Vec](std::vec::Vec), or arrays. +/// [`Vec`](std::vec::Vec), or arrays. /// /// This is an _unsized_ type, meaning that it must always be used behind a pointer like `&`. For an /// owned version of this type, see [`RawDocumentBuf`]. From b124197ed4c478d9e0de72fd564a5cf0542f36b7 Mon Sep 17 00:00:00 2001 From: Abraham Egnor Date: Thu, 3 Nov 2022 12:25:08 -0400 Subject: [PATCH 3/3] Update src/document.rs Co-authored-by: Isabel Atkinson --- src/document.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/document.rs b/src/document.rs index 0e7cb6d7..fedc38a1 100644 --- a/src/document.rs +++ b/src/document.rs @@ -117,7 +117,7 @@ pub struct Values<'a> { inner: indexmap::map::Values<'a, String, Bson>, } -/// An iterator over a Document's keys and mutable values. +/// An iterator over a `Document`'s keys and mutable values. pub struct IterMut<'a> { inner: indexmap::map::IterMut<'a, String, Bson>, }