pub trait LendingIterator {
type Item<'a>
where Self: 'a;
// Required method
fn next(&mut self) -> Option<Self::Item<'_>>;
// Provided method
fn size_hint(&self) -> (usize, Option<usize>) { ... }
}
Expand description
Iterator that only allows access to a single item at a time. You must stop using the returned item before getting the next.
Ultimately we will move to use a common crate for this, but to date there is no good crate to follow. https://blog.rust-lang.org/2022/11/03/Rust-1.65.0.html#generic-associated-types-gats and https://github.com/Crazytieguy/gat-lending-iterator were references for this code.
The idiomatic way to work with this trait is as follows:
while let Some(row) = lending_iterator.next() {
// ... do something with `row` ...
}
Required Associated Types§
Required Methods§
Provided Methods§
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.