pub trait JTryStreamExt: TryStream + Sized {
// Provided methods
fn try_first(self) -> TryStreamNth<Self> ⓘ { ... }
fn try_nth(self, n: usize) -> TryStreamNth<Self> ⓘ { ... }
fn try_filter_map_ok<F, R>(self, predicate: F) -> TryFilterMapOk<Self, F, R>
where F: FnMut(Self::Ok) -> Option<R> { ... }
fn try_dedup(self) -> TryDedupStream<Self>
where Self::Ok: Hash { ... }
fn fuse_on_fail(self) -> FuseOnFail<Self> { ... }
fn try_fold_mut<T, F, Fut>(
self,
initial: T,
handler: F,
) -> TryFoldMut<Self, T, F, Fut> ⓘ
where Self: FusedStream,
F: FnMut(&mut T, Self::Ok) -> Fut,
Fut: TryFuture<Ok = (), Error = Self::Error> { ... }
}
Expand description
Extensions to the TryStream
type which aren’t already covered by the
included TryStreamExt
.
This is implemented using a blanket impl for all TryStream
implementors (which means any
Stream
that emits a Result
).
Provided Methods§
Sourcefn try_first(self) -> TryStreamNth<Self> ⓘ
fn try_first(self) -> TryStreamNth<Self> ⓘ
Sourcefn try_nth(self, n: usize) -> TryStreamNth<Self> ⓘ
fn try_nth(self, n: usize) -> TryStreamNth<Self> ⓘ
Turn this TryStream
into a TryFuture
which
gives the nth item emitted by this stream (in the form of an Option
, because the stream
doesn’t have to emit enough items to reach the index n
).
It will only emit exactly the n
’th item. If the stream completes before the n
th item
is reached, then the future will emit a value of None
.
Any errors encountered while reaching n
th item will be immediately returned.
The future emits a value of type Result<Option<Self::Ok>, Self::Error>
Sourcefn try_filter_map_ok<F, R>(self, predicate: F) -> TryFilterMapOk<Self, F, R>
fn try_filter_map_ok<F, R>(self, predicate: F) -> TryFilterMapOk<Self, F, R>
filter+map on the Self::Ok
value of this stream.
This stream, with the item type Result<Self::Ok, Self::Error>
, can be converted
to a stream which skips some values of Self::Ok
and otherwise transforms non-skipped
values to a new type T
, giving a new stream with item type Result<T, Self::Error>
.
If the current stream emits an Ok(Self::Ok)
value, then the function passed to this
method will be called to transform it to an Ok(T)
message.
If the current stream emits some error by emitting the message Err(Self::Error)
, then
this message will be passed straight-through.
Sourcefn try_dedup(self) -> TryDedupStream<Self>
fn try_dedup(self) -> TryDedupStream<Self>
Given some stream where the Self::Ok
type is Hash
, then this method will allow you
to “de-duplicate” that stream.
This is implemented by storing the hash (a u64
value) of the Self::Ok
messages in a
HashSet<u64>
internally. If an item is emitted, it’s hash is computed, and if the hash
has been seen before, then the item is skipped.
Any error items will not be checked for duplication, and will simply be emitted by the modified “de-duplicated” stream.
Sourcefn fuse_on_fail(self) -> FuseOnFail<Self>
fn fuse_on_fail(self) -> FuseOnFail<Self>
If an Err(Self::Error)
item is emitted from the stream, then panic on further calls to
this stream’s try_poll_next
method, and also implement
FusedStream for this stream (even if the current stream
doesn’t actually implement FusedStream
).
Sourcefn try_fold_mut<T, F, Fut>(
self,
initial: T,
handler: F,
) -> TryFoldMut<Self, T, F, Fut> ⓘ
fn try_fold_mut<T, F, Fut>( self, initial: T, handler: F, ) -> TryFoldMut<Self, T, F, Fut> ⓘ
Given some initial value of a type T
, and some function which accepts &mut T
and
Self::Ok
and returns a Future<Output=Result<(), Self::Error>>
, this stream can be
converted into a Future<Output=Result<T, Self::Error>>
.
The purpose of this method is basically “fold, but with mutable references, instead of moving the value.”
Most implementations will not actually need to return a Future
in the handler function,
but it is required to be a Future
to support rare use-cases where async code must be
executed to update the T
. In the common case, you can just use an async move
block
to turn your non-async code into a Future
, or you can use futures::future::ready
to
construct a ready Future
returning Ok(())
.
If the source stream ever emits an Err(Self::Error)
item, then that causes this future
to immediately emit that same message. Otherwise, the returned future completes when
the stream completes.
If the stream emits no items, then the initial value of T
passed as the first parameter
to this method is emitted as Ok(T)
.
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.