Skip to content

Commit c89e137

Browse files
authored
fix: access iterators from RawDocument without needing to convert to RawDocumentBuf (#462)
1 parent 32f3dc3 commit c89e137

File tree

2 files changed

+26
-6
lines changed

2 files changed

+26
-6
lines changed

Diff for: src/raw/document.rs

+21-1
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,26 @@ impl RawDocument {
181181
Ok(None)
182182
}
183183

184+
/// Gets an iterator over the elements in the [`RawDocument`] that yields
185+
/// `Result<(&str, RawBson<'_>)>`.
186+
pub fn iter(&self) -> Iter<'_> {
187+
Iter::new(self)
188+
}
189+
190+
/// Gets an iterator over the elements in the [`RawDocument`],
191+
/// which yields `Result<RawElement<'_>>` values. These hold a
192+
/// reference to the underlying document but do not explicitly
193+
/// resolve the values.
194+
///
195+
/// This iterator, which underpins the implementation of the
196+
/// default iterator, produces `RawElement` objects that hold a
197+
/// view onto the document but do not parse out or construct
198+
/// values until the `.value()` or `.try_into()` methods are
199+
/// called.
200+
pub fn iter_elements(&self) -> RawIter<'_> {
201+
RawIter::new(self)
202+
}
203+
184204
fn get_with<'a, T>(
185205
&'a self,
186206
key: impl AsRef<str>,
@@ -599,6 +619,6 @@ impl<'a> IntoIterator for &'a RawDocument {
599619
type Item = Result<(&'a str, RawBsonRef<'a>)>;
600620

601621
fn into_iter(self) -> Iter<'a> {
602-
Iter::new(self)
622+
self.iter()
603623
}
604624
}

Diff for: src/raw/document_buf.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -157,10 +157,10 @@ impl RawDocumentBuf {
157157
/// resolve the values.
158158
///
159159
/// This iterator, which underpins the implementation of the
160-
/// default iterator, produces `RawElement` objects, which
161-
/// hold a view onto the document but do not parse out or
162-
/// construct values until the `.value()` or `.try_into()` methods
163-
/// are called.
160+
/// default iterator, produces `RawElement` objects that hold a
161+
/// view onto the document but do not parse out or construct
162+
/// values until the `.value()` or `.try_into()` methods are
163+
/// called.
164164
///
165165
/// # Note:
166166
///
@@ -394,7 +394,7 @@ impl<'a> IntoIterator for &'a RawDocumentBuf {
394394
type Item = Result<(&'a str, RawBsonRef<'a>)>;
395395

396396
fn into_iter(self) -> Iter<'a> {
397-
Iter::new(self)
397+
self.iter()
398398
}
399399
}
400400

0 commit comments

Comments
 (0)