pub mod stream;
pub trait LanceIteratorExtension {
fn exact_size(self, size: usize) -> ExactSize<Self>
where
Self: Sized;
}
impl<I: Iterator> LanceIteratorExtension for I {
fn exact_size(self, size: usize) -> ExactSize<Self>
where
Self: Sized,
{
ExactSize { inner: self, size }
}
}
pub struct ExactSize<I> {
inner: I,
size: usize,
}
impl<I: Iterator> Iterator for ExactSize<I> {
type Item = I::Item;
fn next(&mut self) -> Option<Self::Item> {
match self.inner.next() {
None => None,
Some(x) => {
self.size -= 1;
Some(x)
}
}
}
fn size_hint(&self) -> (usize, Option<usize>) {
(self.size, Some(self.size))
}
}