File tree Expand file tree Collapse file tree 2 files changed +168
-272
lines changed Expand file tree Collapse file tree 2 files changed +168
-272
lines changed Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments