pub trait TryNext {
type Item;
type Error;
// Required method
fn try_next(&mut self) -> Result<Option<Self::Item>, Self::Error>;
// Provided method
fn try_collect(&mut self) -> Result<Vec<Self::Item>, Self::Error> { ... }
}
Expand description
Context-free, fallible producer.
A trait for types that can produce items one at a time, where fetching the next item may fail.
This trait is synchronous — each call to try_next
blocks until an item is produced or an error occurs. See the
module-level documentation for details and examples.
Required Associated Types§
Required Methods§
Provided Methods§
Sourcefn try_collect(&mut self) -> Result<Vec<Self::Item>, Self::Error>
fn try_collect(&mut self) -> Result<Vec<Self::Item>, Self::Error>
Collects all remaining items into a Vec
.
The method repeatedly calls try_next
until None
or an error
is returned, collecting all successful items into a vector.
If any call returns Err(e)
, iteration stops immediately and that error is returned.
§Feature
This method is only available when the alloc
feature is enabled.