From: Chris Mikkelson Date: Sun, 7 Apr 2024 19:09:25 +0000 (-0500) Subject: Iter -> Entries, prep for Iter: IntoIterator X-Git-Url: https://git.mikk.net/?a=commitdiff_plain;h=034978f659da55d12c3333c1998b96d8989f72dd;p=mtbl-rs Iter -> Entries, prep for Iter: IntoIterator --- diff --git a/src/iter.rs b/src/iter.rs index c774aa8..c95f844 100644 --- a/src/iter.rs +++ b/src/iter.rs @@ -3,13 +3,13 @@ use std::cell::RefCell; use std::iter::Iterator; use std::rc::Rc; -pub trait Iter: Iterator + Sized { +pub trait Entries: Iterator + Sized { fn seek>(&mut self, key: T); fn wrap_iter) -> O, O: Iterator>( self, f: F, - ) -> impl Iter { + ) -> impl Entries { let it = IterCell::new(self); WrapIter { inner: it.clone(), @@ -18,7 +18,7 @@ pub trait Iter: Iterator + Sized { } // provided methods - fn filter_seek(self, filter: F) -> impl Iter + fn filter_seek(self, filter: F) -> impl Entries where F: FnMut(&Entry, &mut Vec) -> FilterSeekResult, { @@ -32,23 +32,23 @@ pub trait Iter: Iterator + Sized { // WrapIter -pub struct IterCell { +pub struct IterCell { ic: Rc> } -impl Clone for IterCell { +impl Clone for IterCell { fn clone(&self) -> Self { IterCell{ic: self.ic.clone()} } } -impl IterCell { +impl IterCell { fn new(i: I) -> IterCell { IterCell{ic: Rc::new(RefCell::new(i))} } } -impl Iterator for IterCell { +impl Iterator for IterCell { type Item = Entry; fn next(&mut self) -> Option { @@ -56,19 +56,19 @@ impl Iterator for IterCell { } } -impl Iter for IterCell { +impl Entries for IterCell { fn seek>(&mut self, key: T) { self.ic.borrow_mut().seek(key); } } -struct WrapIter> { +struct WrapIter> { inner: IterCell, outer: O, } -impl> Iterator for WrapIter { +impl> Iterator for WrapIter { type Item = Entry; fn next(&mut self) -> Option { @@ -76,7 +76,7 @@ impl> Iterator for WrapIter { } } -impl> Iter for WrapIter { +impl> Entries for WrapIter { fn seek>(&mut self, key: T) { self.inner.seek(key) } @@ -100,7 +100,7 @@ struct FilterSeek, F: FnMut(&Entry, &mut Vec) -> F impl Iterator for FilterSeek where F: FnMut(&Entry, &mut Vec) -> FilterSeekResult, - I: Iter, + I: Entries, { type Item = Entry; @@ -117,10 +117,10 @@ where } } -impl Iter for FilterSeek +impl Entries for FilterSeek where F: FnMut(&Entry, &mut Vec) -> FilterSeekResult, - I: Iter, + I: Entries, { fn seek>(&mut self, key: T) { self.inner.seek(key.as_ref()); @@ -148,7 +148,7 @@ mod test { } } - impl Iter for TestIter { + impl Entries for TestIter { fn seek>(&mut self, kr: T) { self.0 = kr.as_ref()[0]; }