1 unstable release
0.1.0 | Feb 5, 2021 |
---|
#1941 in Asynchronous
34KB
729 lines
jstream-ext
This crate provides some additional extensions to the futures stream traits.
Usage
Add the following to your Cargo.toml
:
[dependencies]
jstream-ext = "0.1"
lib.rs
:
Introduction
Extensions to the Stream
and TryStream
traits
which implement behavior that I've implemented at least a few times while working with them.
To use these extensions, simply use
the JStreamExt
or
JTryStreamExt
items exported by this crate.
Summary
Here's a list of the various extensions provided by this crate:
Stream
Extensions
The extensions to Stream
are provided by the JStreamExt
trait.
dedup
- remove duplicate items from a streamfold_mut
- Similar tofold
, but asks for a(&mut T, Self::Item)
->Future<Output=()>
instead of a(T, Self::Item)
->Future<Output=T>
folding function.first
- turns a stream into a future which emits only the first item emitted by the source.nth
- turns a stream into a future which emits an item after skipping a specified number of preceding items.
TryStream
Extensions
The extensions to TryStream
are provided by the JTryStreamExt
trait.
try_first
- turns the stream into a future which emits only the first result emitted by the source.try_nth
- turns the stream into a future which emits an item after skipping a specified number of preceding items, or emits an error immediately when encountered.try_filter_map_ok
- similar tofilter_map
, except it allows you to filter-map on theOk
part of theTryStream
, and it emits any errors immediately when they are encountered.try_dedup
- remove duplicate items from a stream, but also emit any errors immediately when they are seen.fuse_on_fail
- if an error is seen, "fuse" the stream such that it panics iftry_poll_next
is called after anErr(Self::Error)
item is emitted. This also makes aTryStream
implementFusedStream
regardless if the source implements that trait.try_fold_mut
- Similar totry_fold
, but asks for a(&mut T, Self::Ok)
->Future<Output=Result<(), Self::Error>>
instead of a(T, Self::Ok)
->Future<Output=Result<T, Self::Error>>
folding function.
Dependencies
~0.6–0.8MB
~15K SLoC