Skip to content

Commit 0162658

Browse files
committed
Rollup merge of rust-lang#25760 - Ms2ger:tagged_docs, r=alexcrichton
2 parents 3a39858 + 817ca99 commit 0162658

File tree

2 files changed

+168
-271
lines changed

2 files changed

+168
-271
lines changed

src/librbml/lib.rs

+20-14
Original file line numberDiff line numberDiff line change
@@ -436,23 +436,29 @@ pub mod reader {
436436
}
437437
}
438438

439-
pub fn tagged_docs<F>(d: Doc, tg: usize, mut it: F) -> bool where
440-
F: FnMut(Doc) -> bool,
441-
{
442-
let mut pos = d.start;
443-
while pos < d.end {
444-
let elt_tag = try_or!(tag_at(d.data, pos), false);
445-
let elt_size = try_or!(tag_len_at(d.data, elt_tag), false);
446-
pos = elt_size.next + elt_size.val;
447-
if elt_tag.val == tg {
448-
let doc = Doc { data: d.data, start: elt_size.next,
449-
end: pos };
450-
if !it(doc) {
451-
return false;
439+
pub fn tagged_docs<'a>(d: Doc<'a>, tag: usize) -> TaggedDocsIterator<'a> {
440+
TaggedDocsIterator {
441+
iter: docs(d),
442+
tag: tag,
443+
}
444+
}
445+
446+
pub struct TaggedDocsIterator<'a> {
447+
iter: DocsIterator<'a>,
448+
tag: usize,
449+
}
450+
451+
impl<'a> Iterator for TaggedDocsIterator<'a> {
452+
type Item = Doc<'a>;
453+
454+
fn next(&mut self) -> Option<Doc<'a>> {
455+
while let Some((tag, doc)) = self.iter.next() {
456+
if tag == self.tag {
457+
return Some(doc);
452458
}
453459
}
460+
None
454461
}
455-
return true;
456462
}
457463

458464
pub fn with_doc_data<T, F>(d: Doc, f: F) -> T where

0 commit comments

Comments
 (0)