From 38f9d82caa1e0672122be9022d09d96feae3b5ff Mon Sep 17 00:00:00 2001 From: tycho garen Date: Wed, 28 Feb 2024 08:37:05 -0500 Subject: [PATCH 1/2] fix: access iterators from RawDocument without needing to convert --- src/raw/document.rs | 12 +++++++++++- src/raw/document_buf.rs | 10 +++++----- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/src/raw/document.rs b/src/raw/document.rs index 51ca6530..719124cc 100644 --- a/src/raw/document.rs +++ b/src/raw/document.rs @@ -181,6 +181,16 @@ impl RawDocument { Ok(None) } + /// Gets an iterator over the elements in the [`RawDocument`] that yields + /// `Result<(&str, RawBson<'_>)>`. + pub fn iter(&self) -> Iter<'_> { + Iter::new(self) + } + + pub fn iter_elements(&self) -> RawIter<'_> { + RawIter::new(self) + } + fn get_with<'a, T>( &'a self, key: impl AsRef, @@ -599,6 +609,6 @@ impl<'a> IntoIterator for &'a RawDocument { type Item = Result<(&'a str, RawBsonRef<'a>)>; fn into_iter(self) -> Iter<'a> { - Iter::new(self) + self.iter() } } diff --git a/src/raw/document_buf.rs b/src/raw/document_buf.rs index 525ebc44..23981064 100644 --- a/src/raw/document_buf.rs +++ b/src/raw/document_buf.rs @@ -157,10 +157,10 @@ impl RawDocumentBuf { /// resolve the values. /// /// This iterator, which underpins the implementation of the - /// default iterator, produces `RawElement` objects, which - /// hold a view onto the document but do not parse out or - /// construct values until the `.value()` or `.try_into()` methods - /// are called. + /// default iterator, produces `RawElement` objects that hold a + /// view onto the document but do not parse out or construct + /// values until the `.value()` or `.try_into()` methods are + /// called. /// /// # Note: /// @@ -394,7 +394,7 @@ impl<'a> IntoIterator for &'a RawDocumentBuf { type Item = Result<(&'a str, RawBsonRef<'a>)>; fn into_iter(self) -> Iter<'a> { - Iter::new(self) + self.iter() } } From 9189fb0401436cdb1f1d68a5f207d3988b6284d8 Mon Sep 17 00:00:00 2001 From: tycho garen Date: Fri, 1 Mar 2024 15:04:53 -0500 Subject: [PATCH 2/2] add doc --- src/raw/document.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/raw/document.rs b/src/raw/document.rs index 719124cc..7132db92 100644 --- a/src/raw/document.rs +++ b/src/raw/document.rs @@ -187,6 +187,16 @@ impl RawDocument { Iter::new(self) } + /// Gets an iterator over the elements in the [`RawDocument`], + /// which yields `Result>` values. These hold a + /// reference to the underlying document but do not explicitly + /// resolve the values. + /// + /// This iterator, which underpins the implementation of the + /// default iterator, produces `RawElement` objects that hold a + /// view onto the document but do not parse out or construct + /// values until the `.value()` or `.try_into()` methods are + /// called. pub fn iter_elements(&self) -> RawIter<'_> { RawIter::new(self) }