pub trait Pull {
type Ctx<'ctx>: Context<'ctx>;
type Item;
type Meta: Copy;
type CanPend: Toggle;
type CanEnd: Toggle;
Show 28 methods
// Required methods
fn pull(
self: Pin<&mut Self>,
ctx: &mut Self::Ctx<'_>,
) -> PullStep<Self::Item, Self::Meta, Self::CanPend, Self::CanEnd>;
fn size_hint(&self) -> (usize, Option<usize>);
// Provided methods
fn by_ref(&mut self) -> &mut Self { ... }
fn chain<U>(self, other: U) -> Chain<Self, U>
where Self: Sized + FusedPull<CanEnd = Yes>,
U: Pull<Item = Self::Item, Meta = Self::Meta> { ... }
fn enumerate(self) -> Enumerate<Self>
where Self: Sized { ... }
fn filter<P>(self, predicate: P) -> Filter<Self, P>
where Self: Sized,
P: FnMut(&Self::Item) -> bool { ... }
fn filter_map<B, F>(self, f: F) -> FilterMap<Self, F>
where Self: Sized,
F: FnMut(Self::Item) -> Option<B> { ... }
fn flat_map<U, F>(self, f: F) -> FlatMap<Self, F, U::IntoIter, Self::Meta>
where Self: Sized,
F: FnMut(Self::Item) -> U,
U: IntoIterator { ... }
fn flatten(
self,
) -> Flatten<Self, <Self::Item as IntoIterator>::IntoIter, Self::Meta>
where Self: Sized,
Self::Item: IntoIterator { ... }
fn flatten_stream(self) -> FlattenStream<Self, Self::Item, Self::Meta>
where Self: Sized,
Self::Item: Stream { ... }
fn for_each<F>(self, f: F) -> ForEach<Self, F> ⓘ
where Self: Sized,
F: FnMut(Self::Item) { ... }
fn collect<C>(self) -> Collect<Self, C> ⓘ
where Self: Sized,
C: Default + Extend<Self::Item> { ... }
fn fuse(
self,
) -> impl for<'ctx> FusedPull<Ctx<'ctx> = Self::Ctx<'ctx>, Item = Self::Item, Meta = Self::Meta, CanPend = Self::CanPend, CanEnd = Self::CanEnd>
where Self: Sized { ... }
fn inspect<F>(self, f: F) -> Inspect<Self, F>
where Self: Sized,
F: FnMut(&Self::Item) { ... }
fn map<B, F>(self, f: F) -> Map<Self, F>
where Self: Sized,
F: FnMut(Self::Item) -> B { ... }
fn send_sink<Push>(self, push: Push) -> SendSink<Self, Push> ⓘ
where Self: Sized,
Push: Sink<Self::Item> { ... }
fn send_push<Psh>(self, push: Psh) -> SendPush<Self, Psh> ⓘ
where Self: Sized,
Psh: Push<Self::Item, Self::Meta> { ... }
fn skip(self, n: usize) -> Skip<Self>
where Self: Sized { ... }
fn skip_while<P>(self, predicate: P) -> SkipWhile<Self, P>
where Self: Sized,
P: FnMut(&Self::Item) -> bool { ... }
fn take(self, n: usize) -> Take<Self>
where Self: Sized { ... }
fn take_while<P>(self, predicate: P) -> TakeWhile<Self, P>
where Self: Sized,
P: FnMut(&Self::Item) -> bool { ... }
fn zip<U>(self, other: U) -> Zip<Self, U>
where Self: Sized,
U: Pull<Meta = Self::Meta> { ... }
fn zip_longest<U>(self, other: U) -> ZipLongest<Self, U>
where Self: Sized + FusedPull,
U: FusedPull<Meta = Self::Meta> { ... }
fn next(self) -> Next<Self> ⓘ
where Self: Sized { ... }
fn cross_singleton<SinglePull>(
self,
singleton_pull: SinglePull,
) -> CrossSingleton<Self, SinglePull, Option<SinglePull::Item>>
where Self: Sized,
SinglePull: Pull,
SinglePull::Item: Clone { ... }
fn cross_singleton_state<SinglePull>(
self,
singleton_pull: SinglePull,
singleton_state: &mut Option<SinglePull::Item>,
) -> CrossSingleton<Self, SinglePull, &mut Option<SinglePull::Item>>
where Self: Sized,
SinglePull: Pull,
SinglePull::Item: Clone { ... }
fn symmetric_hash_join<Key, V1, Rhs, V2, LhsState, RhsState>(
self,
rhs: Rhs,
lhs_state: LhsState,
rhs_state: RhsState,
) -> SymmetricHashJoin<Self, Rhs, LhsState, RhsState, LhsState, RhsState>
where Self: Sized + FusedPull<Item = (Key, V1), Meta = ()>,
Key: Eq + Hash + Clone,
V1: Clone,
V2: Clone,
Rhs: FusedPull<Item = (Key, V2), Meta = ()>,
LhsState: HalfJoinState<Key, V1, V2>,
RhsState: HalfJoinState<Key, V2, V1> { ... }
fn symmetric_hash_join_state<'a, Key, V1, Rhs, V2, LhsState, RhsState>(
self,
rhs: Rhs,
lhs_state: &'a mut LhsState,
rhs_state: &'a mut RhsState,
) -> SymmetricHashJoin<Self, Rhs, &'a mut LhsState, &'a mut RhsState, LhsState, RhsState>
where Self: Sized + FusedPull<Item = (Key, V1), Meta = ()>,
Key: Eq + Hash + Clone,
V1: Clone,
V2: Clone,
Rhs: FusedPull<Item = (Key, V2), Meta = ()>,
LhsState: HalfJoinState<Key, V1, V2>,
RhsState: HalfJoinState<Key, V2, V1> { ... }
}Expand description
The Pull trait represents a pull-based stream that can be polled for items.
The Ctx type parameter allows operators to be generic over the context type.
Most operators don’t use the context and just forward it to their predecessor,
so they can be generic over Ctx. Operators that need std::task::Context
(like StreamReady) will use Ctx = &mut Context<'_>.
Setting Ctx = () allows most pull pipelines to be used without any context.
Required Associated Types§
Sourcetype CanPend: Toggle
type CanPend: Toggle
Whether this pull can return PullStep::Pending.
Sourcetype CanEnd: Toggle
type CanEnd: Toggle
Whether this pull can return PullStep::Ended.
Required Methods§
Sourcefn pull(
self: Pin<&mut Self>,
ctx: &mut Self::Ctx<'_>,
) -> PullStep<Self::Item, Self::Meta, Self::CanPend, Self::CanEnd>
fn pull( self: Pin<&mut Self>, ctx: &mut Self::Ctx<'_>, ) -> PullStep<Self::Item, Self::Meta, Self::CanPend, Self::CanEnd>
Attempts to pull the next item from this stream.
Sourcefn size_hint(&self) -> (usize, Option<usize>)
fn size_hint(&self) -> (usize, Option<usize>)
Returns the bounds on the remaining length of the pull.
Specifically, size_hint() returns a tuple where the first element
is the lower bound, and the second element is the upper bound.
The second half of the tuple that is returned is an Option<usize>.
A None here means that either there is no known upper bound, or the
upper bound is larger than usize.
§Implementation notes
It is not enforced that a pull implementation yields the declared number of elements. A buggy pull may yield less than the lower bound or more than the upper bound of elements.
size_hint() is primarily intended to be used for optimizations such as
reserving space for the elements of the pull, but must not be trusted
to e.g., omit bounds checks in unsafe code. An incorrect implementation
of size_hint() should not lead to memory safety violations.
That said, the implementation should provide a correct estimation, because otherwise it would be a violation of the trait’s protocol.
A default implementation should return (0, None) which is correct for any
pull. However this is not provided, to prevent oversight.
Provided Methods§
Sourcefn chain<U>(self, other: U) -> Chain<Self, U>
fn chain<U>(self, other: U) -> Chain<Self, U>
Takes two pulls and creates a new pull over both in sequence.
chain() will return a new pull which will first iterate over
values from the first pull and then over values from the second pull.
The first pull must be finite (CanEnd = Yes) and fused (FusedPull).
Sourcefn enumerate(self) -> Enumerate<Self>where
Self: Sized,
fn enumerate(self) -> Enumerate<Self>where
Self: Sized,
Creates a pull which gives the current iteration count as well as the next value.
The pull returned yields pairs (i, val), where i is the current index
of iteration and val is the value returned by the pull.
Sourcefn filter<P>(self, predicate: P) -> Filter<Self, P>
fn filter<P>(self, predicate: P) -> Filter<Self, P>
Creates a pull which uses a closure to determine if an element should be yielded.
Given an element the closure must return true or false. The returned pull
will yield only the elements for which the closure returns true.
Sourcefn filter_map<B, F>(self, f: F) -> FilterMap<Self, F>
fn filter_map<B, F>(self, f: F) -> FilterMap<Self, F>
Creates a pull that both filters and maps.
The returned pull yields only the values for which the supplied closure
returns Some(value).
Sourcefn flat_map<U, F>(self, f: F) -> FlatMap<Self, F, U::IntoIter, Self::Meta>
fn flat_map<U, F>(self, f: F) -> FlatMap<Self, F, U::IntoIter, Self::Meta>
Creates a pull that works like map, but flattens nested structure.
The flat_map() method is useful when you have a pull of items, and you
want to apply a function that returns an iterator for each item, then
flatten all those iterators into a single pull.
Sourcefn flatten(
self,
) -> Flatten<Self, <Self::Item as IntoIterator>::IntoIter, Self::Meta>
fn flatten( self, ) -> Flatten<Self, <Self::Item as IntoIterator>::IntoIter, Self::Meta>
Creates a pull that flattens nested structure.
This is useful when you have a pull of iterables, and you want to flatten them into a single pull.
Sourcefn flatten_stream(self) -> FlattenStream<Self, Self::Item, Self::Meta>
fn flatten_stream(self) -> FlattenStream<Self, Self::Item, Self::Meta>
Creates a pull that flattens items that are streams by polling each inner stream.
This is useful when you have a pull of streams, and you want to flatten them into a single pull. Requires an async context since inner streams are polled.
Sourcefn for_each<F>(self, f: F) -> ForEach<Self, F> ⓘ
fn for_each<F>(self, f: F) -> ForEach<Self, F> ⓘ
Creates a future which runs the given function on each element of a pull.
Sourcefn collect<C>(self) -> Collect<Self, C> ⓘ
fn collect<C>(self) -> Collect<Self, C> ⓘ
Creates a future which collects all elements of a pull into a collection.
The collection type C must implement Default and Extend<Item>.
Sourcefn fuse(
self,
) -> impl for<'ctx> FusedPull<Ctx<'ctx> = Self::Ctx<'ctx>, Item = Self::Item, Meta = Self::Meta, CanPend = Self::CanPend, CanEnd = Self::CanEnd>where
Self: Sized,
fn fuse(
self,
) -> impl for<'ctx> FusedPull<Ctx<'ctx> = Self::Ctx<'ctx>, Item = Self::Item, Meta = Self::Meta, CanPend = Self::CanPend, CanEnd = Self::CanEnd>where
Self: Sized,
Creates a pull that ends after the first None.
After a pull returns Ended for the first time, the behavior of calling
pull again is implementation-defined. fuse() adapts any pull,
ensuring that after Ended is given once, it will always return Ended
forever.
Usually this method will simply return Fuse<Self>, but it may be
overridden for optimization.
Sourcefn inspect<F>(self, f: F) -> Inspect<Self, F>
fn inspect<F>(self, f: F) -> Inspect<Self, F>
Does something with each element of a pull, passing the value on.
When using pulls, you’ll often chain several of them together.
While working on such code, you might want to check out what’s
happening at various parts in the pipeline. To do that, insert
a call to inspect().
Sourcefn map<B, F>(self, f: F) -> Map<Self, F>
fn map<B, F>(self, f: F) -> Map<Self, F>
Takes a closure and creates a pull that calls that closure on each element.
map() transforms one pull into another, by means of its argument: something
that implements FnMut. It produces a new pull which calls this closure on
each element of the original pull.
Sourcefn send_sink<Push>(self, push: Push) -> SendSink<Self, Push> ⓘ
fn send_sink<Push>(self, push: Push) -> SendSink<Self, Push> ⓘ
Creates a future that pulls all items and sends them into a crate::Sink.
Sourcefn send_push<Psh>(self, push: Psh) -> SendPush<Self, Psh> ⓘ
fn send_push<Psh>(self, push: Psh) -> SendPush<Self, Psh> ⓘ
Creates a future that pulls all items and pushes them into a crate::push::Push.
Sourcefn skip(self, n: usize) -> Skip<Self>where
Self: Sized,
fn skip(self, n: usize) -> Skip<Self>where
Self: Sized,
Creates a pull that skips the first n elements.
Sourcefn skip_while<P>(self, predicate: P) -> SkipWhile<Self, P>
fn skip_while<P>(self, predicate: P) -> SkipWhile<Self, P>
Creates a pull that skips elements based on a predicate.
skip_while() takes a closure as an argument. It will call this closure
on each element of the pull, and ignore elements until it returns false.
Sourcefn take(self, n: usize) -> Take<Self>where
Self: Sized,
fn take(self, n: usize) -> Take<Self>where
Self: Sized,
Creates a pull that yields the first n elements, or fewer if the
underlying pull ends sooner.
Sourcefn take_while<P>(self, predicate: P) -> TakeWhile<Self, P>
fn take_while<P>(self, predicate: P) -> TakeWhile<Self, P>
Creates a pull that yields elements based on a predicate.
take_while() takes a closure as an argument. It will call this closure
on each element of the pull, and yield elements while it returns true.
Sourcefn zip<U>(self, other: U) -> Zip<Self, U>
fn zip<U>(self, other: U) -> Zip<Self, U>
Zips two pulls together, stopping once either is exhausted.
Sourcefn zip_longest<U>(self, other: U) -> ZipLongest<Self, U>
fn zip_longest<U>(self, other: U) -> ZipLongest<Self, U>
Zips two pulls together, continuing until both are exhausted.
Unlike a regular zip which ends when either pull ends, zip_longest
continues until both pulls have ended, yielding crate::EitherOrBoth
values to indicate which pulls yielded items.
Both pulls must be fused (FusedPull) to ensure correct behavior
after one pull ends.
Sourcefn next(self) -> Next<Self> ⓘwhere
Self: Sized,
fn next(self) -> Next<Self> ⓘwhere
Self: Sized,
Creates a future that resolves with the next item from this pull.
This is the Pull equivalent of the StreamExt::next() future.
Sourcefn cross_singleton<SinglePull>(
self,
singleton_pull: SinglePull,
) -> CrossSingleton<Self, SinglePull, Option<SinglePull::Item>>
fn cross_singleton<SinglePull>( self, singleton_pull: SinglePull, ) -> CrossSingleton<Self, SinglePull, Option<SinglePull::Item>>
Crosses each item from this pull with a singleton value from another pull.
The singleton value is obtained from the first item of singleton_pull and cached.
All subsequent items from this pull are paired with this cached singleton value.
If singleton_pull ends before yielding any items, the entire combinator ends immediately.
Sourcefn cross_singleton_state<SinglePull>(
self,
singleton_pull: SinglePull,
singleton_state: &mut Option<SinglePull::Item>,
) -> CrossSingleton<Self, SinglePull, &mut Option<SinglePull::Item>>
fn cross_singleton_state<SinglePull>( self, singleton_pull: SinglePull, singleton_state: &mut Option<SinglePull::Item>, ) -> CrossSingleton<Self, SinglePull, &mut Option<SinglePull::Item>>
Self::cross_singleton with external state.
Sourcefn symmetric_hash_join<Key, V1, Rhs, V2, LhsState, RhsState>(
self,
rhs: Rhs,
lhs_state: LhsState,
rhs_state: RhsState,
) -> SymmetricHashJoin<Self, Rhs, LhsState, RhsState, LhsState, RhsState>
Available on crate feature std only.
fn symmetric_hash_join<Key, V1, Rhs, V2, LhsState, RhsState>( self, rhs: Rhs, lhs_state: LhsState, rhs_state: RhsState, ) -> SymmetricHashJoin<Self, Rhs, LhsState, RhsState, LhsState, RhsState>
std only.Performs a symmetric hash join with another pull.
Joins items from this pull with items from rhs based on a common key.
Both pulls must yield (Key, Value) tuples. The result is a pull of
(Key, (V1, V2)) tuples for each matching pair.
The lhs_state and rhs_state parameters store the join state and must
implement HalfJoinState.
Sourcefn symmetric_hash_join_state<'a, Key, V1, Rhs, V2, LhsState, RhsState>(
self,
rhs: Rhs,
lhs_state: &'a mut LhsState,
rhs_state: &'a mut RhsState,
) -> SymmetricHashJoin<Self, Rhs, &'a mut LhsState, &'a mut RhsState, LhsState, RhsState>
Available on crate feature std only.
fn symmetric_hash_join_state<'a, Key, V1, Rhs, V2, LhsState, RhsState>( self, rhs: Rhs, lhs_state: &'a mut LhsState, rhs_state: &'a mut RhsState, ) -> SymmetricHashJoin<Self, Rhs, &'a mut LhsState, &'a mut RhsState, LhsState, RhsState>
std only.Self::symmetric_hash_join with external state.
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.
Implementations on Foreign Types§
Source§impl<P> Pull for &mut P
impl<P> Pull for &mut P
type Ctx<'ctx> = <P as Pull>::Ctx<'ctx>
type Item = <P as Pull>::Item
type Meta = <P as Pull>::Meta
type CanPend = <P as Pull>::CanPend
type CanEnd = <P as Pull>::CanEnd
fn pull( self: Pin<&mut Self>, ctx: &mut Self::Ctx<'_>, ) -> PullStep<Self::Item, Self::Meta, Self::CanPend, Self::CanEnd>
fn size_hint(&self) -> (usize, Option<usize>)
Implementors§
Source§impl<ItemPull, SinglePull, SingleState> Pull for CrossSingleton<ItemPull, SinglePull, SingleState>
impl<ItemPull, SinglePull, SingleState> Pull for CrossSingleton<ItemPull, SinglePull, SingleState>
type Ctx<'ctx> = <<ItemPull as Pull>::Ctx<'ctx> as Context<'ctx>>::Merged<<SinglePull as Pull>::Ctx<'ctx>>
type Item = (<ItemPull as Pull>::Item, <SinglePull as Pull>::Item)
type Meta = <ItemPull as Pull>::Meta
type CanPend = <<ItemPull as Pull>::CanPend as Toggle>::Or<<SinglePull as Pull>::CanPend>
type CanEnd = <<ItemPull as Pull>::CanEnd as Toggle>::Or<<SinglePull as Pull>::CanEnd>
Source§impl<Key, Lhs, V1, Rhs, V2, LhsState, RhsState, LhsStateInner, RhsStateInner> Pull for SymmetricHashJoin<Lhs, Rhs, LhsState, RhsState, LhsStateInner, RhsStateInner>
Available on crate feature std only.
impl<Key, Lhs, V1, Rhs, V2, LhsState, RhsState, LhsStateInner, RhsStateInner> Pull for SymmetricHashJoin<Lhs, Rhs, LhsState, RhsState, LhsStateInner, RhsStateInner>
std only.type Ctx<'ctx> = <<Lhs as Pull>::Ctx<'ctx> as Context<'ctx>>::Merged<<Rhs as Pull>::Ctx<'ctx>>
type Item = (Key, (V1, V2))
type Meta = ()
type CanPend = <<Lhs as Pull>::CanPend as Toggle>::Or<<Rhs as Pull>::CanPend>
type CanEnd = <<Lhs as Pull>::CanEnd as Toggle>::And<<Rhs as Pull>::CanEnd>
Source§impl<L, R> Pull for Either<L, R>
impl<L, R> Pull for Either<L, R>
type Ctx<'ctx> = <<L as Pull>::Ctx<'ctx> as Context<'ctx>>::Merged<<R as Pull>::Ctx<'ctx>>
type Item = <L as Pull>::Item
type Meta = <L as Pull>::Meta
type CanPend = <<L as Pull>::CanPend as Toggle>::Or<<R as Pull>::CanPend>
type CanEnd = <<L as Pull>::CanEnd as Toggle>::Or<<R as Pull>::CanEnd>
Source§impl<Prev1, Prev2> Pull for Zip<Prev1, Prev2>
impl<Prev1, Prev2> Pull for Zip<Prev1, Prev2>
type Ctx<'ctx> = <<Prev1 as Pull>::Ctx<'ctx> as Context<'ctx>>::Merged<<Prev2 as Pull>::Ctx<'ctx>>
type Item = (<Prev1 as Pull>::Item, <Prev2 as Pull>::Item)
type Meta = <Prev1 as Pull>::Meta
type CanPend = <<Prev1 as Pull>::CanPend as Toggle>::Or<<Prev2 as Pull>::CanPend>
type CanEnd = <<Prev1 as Pull>::CanEnd as Toggle>::Or<<Prev2 as Pull>::CanEnd>
Source§impl<Prev1, Prev2> Pull for ZipLongest<Prev1, Prev2>
impl<Prev1, Prev2> Pull for ZipLongest<Prev1, Prev2>
type Ctx<'ctx> = <<Prev1 as Pull>::Ctx<'ctx> as Context<'ctx>>::Merged<<Prev2 as Pull>::Ctx<'ctx>>
type Item = EitherOrBoth<<Prev1 as Pull>::Item, <Prev2 as Pull>::Item>
type Meta = <Prev1 as Pull>::Meta
type CanPend = <<Prev1 as Pull>::CanPend as Toggle>::Or<<Prev2 as Pull>::CanPend>
type CanEnd = <<Prev1 as Pull>::CanEnd as Toggle>::And<<Prev2 as Pull>::CanEnd>
Source§impl<S> Pull for StreamReady<S>where
S: Stream,
StreamReady uses its own waker, so it ignores the context parameter.
It implements Pull with Ctx = ().
impl<S> Pull for StreamReady<S>where
S: Stream,
StreamReady uses its own waker, so it ignores the context parameter.
It implements Pull with Ctx = ().