diff --git a/src/raw/document.rs b/src/raw/document.rs index 51ca6530..7132db92 100644 --- a/src/raw/document.rs +++ b/src/raw/document.rs @@ -181,6 +181,26 @@ 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) + } + + /// 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) + } + fn get_with<'a, T>( &'a self, key: impl AsRef, @@ -599,6 +619,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() } }