pub trait Source {
type Item<'x>;
type Error: Error + Send + Sync + 'static;
// Required method
fn try_for_some_item<E, F>(
&mut self,
f: F,
) -> StreamResult<bool, Self::Error, E>
where E: Error + Send + Sync + 'static,
F: FnMut(Self::Item<'_>) -> Result<(), E>;
// Provided methods
fn try_for_each_item<F, E>(
&mut self,
f: F,
) -> StreamResult<(), Self::Error, E>
where F: FnMut(Self::Item<'_>) -> Result<(), E>,
E: Error + Send + Sync + 'static { ... }
fn for_some_item<F>(&mut self, f: F) -> Result<bool, Self::Error>
where F: FnMut(Self::Item<'_>) { ... }
fn for_each_item<F>(&mut self, f: F) -> Result<(), Self::Error>
where F: FnMut(Self::Item<'_>) { ... }
fn filter_items<F>(self, predicate: F) -> FilterSource<Self, F>
where Self: Sized,
F: FnMut(&Self::Item<'_>) -> bool { ... }
fn filter_map_items<F, T>(self, filter_map: F) -> FilterMapSource<Self, F>
where Self: Sized,
F: FnMut(Self::Item<'_>) -> Option<T> { ... }
fn map_items<F, T>(self, map: F) -> MapSource<Self, F>
where Self: Sized,
F: FnMut(Self::Item<'_>) -> T { ... }
fn size_hint_items(&self) -> (usize, Option<usize>) { ... }
}
Expand description
A source produces items, and may also fail in the process.
See module documentation for the rationale of his trait.
§Common implementors
Any iterator yielding results
implements the Source
trait.
Any iterator can also be converted to an Infallible
Source
thanks to the IntoSource
extension trait.
Required Associated Types§
Required Methods§
Sourcefn try_for_some_item<E, F>(
&mut self,
f: F,
) -> StreamResult<bool, Self::Error, E>
fn try_for_some_item<E, F>( &mut self, f: F, ) -> StreamResult<bool, Self::Error, E>
Call f for some item(s) (possibly zero) from this source, if any.
Return Ok(false)
if there are no more items in this source.
Return an error if either the source or f
errs.
Provided Methods§
Sourcefn try_for_each_item<F, E>(&mut self, f: F) -> StreamResult<(), Self::Error, E>
fn try_for_each_item<F, E>(&mut self, f: F) -> StreamResult<(), Self::Error, E>
Call f for all items from this source.
Return an error if either the source or f
errs.
Sourcefn for_some_item<F>(&mut self, f: F) -> Result<bool, Self::Error>
fn for_some_item<F>(&mut self, f: F) -> Result<bool, Self::Error>
Call f for some item(s) (possibly zero) from this source, if any.
Return false if there are no more items in this source.
Return an error if either the source errs.
Sourcefn for_each_item<F>(&mut self, f: F) -> Result<(), Self::Error>
fn for_each_item<F>(&mut self, f: F) -> Result<(), Self::Error>
Call f for all items from this source.
Return an error if either the source errs.
Sourcefn filter_items<F>(self, predicate: F) -> FilterSource<Self, F>
fn filter_items<F>(self, predicate: F) -> FilterSource<Self, F>
Returns a source which uses predicate
to determine if an item should be yielded.
Sourcefn filter_map_items<F, T>(self, filter_map: F) -> FilterMapSource<Self, F>
fn filter_map_items<F, T>(self, filter_map: F) -> FilterMapSource<Self, F>
Returns a source that both filters and maps.
See also TripleSource::filter_triples
and TripleSource::map_triples
.
Sourcefn map_items<F, T>(self, map: F) -> MapSource<Self, F>
fn map_items<F, T>(self, map: F) -> MapSource<Self, F>
Returns a source which yield the result of map
for each Item.
NB: due to some limitations in GATs (Generic) Associated Types,
the map
function is currently restricted in what it can return.
In particular, passing functions as trivial as |t| t
currently does not compile on all implementations of Source
.
As a rule of thumb,
whenever map
returns something satisfying the 'static
lifetime,
things should work as expected.
Sourcefn size_hint_items(&self) -> (usize, Option<usize>)
fn size_hint_items(&self) -> (usize, Option<usize>)
Returns the bounds on the remaining length of the source.
This method has the same contract as Iterator::size_hint
.
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.