Trait Source

Source
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§

Source

type Item<'x>

The type of items this source yields.

Source

type Error: Error + Send + Sync + 'static

The type of errors produced by this source.

Required Methods§

Source

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>,

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§

Source

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,

Call f for all items from this source.

Return an error if either the source or f errs.

Source

fn for_some_item<F>(&mut self, f: F) -> Result<bool, Self::Error>
where F: FnMut(Self::Item<'_>),

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.

Source

fn for_each_item<F>(&mut self, f: F) -> Result<(), Self::Error>
where F: FnMut(Self::Item<'_>),

Call f for all items from this source.

Return an error if either the source errs.

Source

fn filter_items<F>(self, predicate: F) -> FilterSource<Self, F>
where Self: Sized, F: FnMut(&Self::Item<'_>) -> bool,

Returns a source which uses predicate to determine if an item should be yielded.

Source

fn filter_map_items<F, T>(self, filter_map: F) -> FilterMapSource<Self, F>
where Self: Sized, F: FnMut(Self::Item<'_>) -> Option<T>,

Returns a source that both filters and maps.

See also TripleSource::filter_triples and TripleSource::map_triples.

Source

fn map_items<F, T>(self, map: F) -> MapSource<Self, F>
where Self: Sized, F: FnMut(Self::Item<'_>) -> T,

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.

Source

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.

Implementors§

Source§

impl<'a, I, T, E> Source for I
where I: Iterator<Item = Result<T, E>> + 'a, E: Error + Send + Sync + 'static,

Source§

type Item<'x> = T

Source§

type Error = E

Source§

impl<QS: QuadSource> Source for ToTriples<QS>

Source§

type Item<'x> = [<<QS as IsQuadSource>::Quad<'x> as Quad>::Term; 3]

Source§

type Error = <QS as Source>::Error

Source§

impl<S, F, T> Source for FilterMapSource<S, F>
where S: Source, F: FnMut(S::Item<'_>) -> Option<T>,

Source§

type Item<'x> = T

Source§

type Error = <S as Source>::Error

Source§

impl<S, F, T> Source for MapSource<S, F>
where S: Source, F: FnMut(S::Item<'_>) -> T,

Source§

type Item<'x> = T

Source§

type Error = <S as Source>::Error

Source§

impl<S, P> Source for FilterQuadSource<S, P>
where S: QuadSource, P: FnMut(&S::Item<'_>) -> bool,

Source§

type Item<'x> = <S as IsQuadSource>::Quad<'x>

Source§

type Error = <S as Source>::Error

Source§

impl<S, P> Source for FilterSource<S, P>
where S: Source, P: FnMut(&S::Item<'_>) -> bool,

Source§

type Item<'x> = <S as Source>::Item<'x>

Source§

type Error = <S as Source>::Error

Source§

impl<S, P> Source for FilterTripleSource<S, P>
where S: TripleSource, P: FnMut(&S::Item<'_>) -> bool,

Source§

type Item<'x> = <S as IsTripleSource>::Triple<'x>

Source§

type Error = <S as Source>::Error

Source§

impl<TS: TripleSource> Source for ToQuads<TS>

Source§

type Item<'x> = ([<<TS as IsTripleSource>::Triple<'x> as Triple>::Term; 3], Option<<<TS as IsTripleSource>::Triple<'x> as Triple>::Term>)

Source§

type Error = <TS as Source>::Error