// SPDX-License-Identifier: Apache-2.0 // SPDX-FileCopyrightText: Copyright The Lance Authors pub mod stream; pub trait LanceIteratorExtension { fn exact_size(self, size: usize) -> ExactSize where Self: Sized; } impl LanceIteratorExtension for I { fn exact_size(self, size: usize) -> ExactSize where Self: Sized, { ExactSize { inner: self, size } } } /// A iterator that is tagged with a known size. This is useful when we are /// able to pre-compute the size of the iterator but the iterator implementation /// isn't able to itself. A common example is when using `flatten()`. /// /// This is inspired by discussion in pub struct ExactSize { inner: I, size: usize, } impl Iterator for ExactSize { type Item = I::Item; fn next(&mut self) -> Option { match self.inner.next() { None => None, Some(x) => { self.size -= 1; Some(x) } } } fn size_hint(&self) -> (usize, Option) { (self.size, Some(self.size)) } }