File tree Expand file tree Collapse file tree 3 files changed +53
-2
lines changed
Expand file tree Collapse file tree 3 files changed +53
-2
lines changed Original file line number Diff line number Diff line change @@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file.
44
55This project adheres to [ Semantic Versioning] ( https://semver.org ) .
66
7+ ## [ 1.0.1] - 2023-02-16
8+
9+ ### Added
10+
11+ - Add recipes for converting a ` BufList ` into a ` Stream ` or a ` TryStream ` .
12+
713## [ 1.0.0] - 2023-01-06
814
915### Added
@@ -32,6 +38,7 @@ This project adheres to [Semantic Versioning](https://semver.org).
3238
3339- Initial release.
3440
41+ [ 1.0.1 ] : https://github.com/sunshowers-code/buf-list/releases/tag/1.0.1
3542[ 1.0.0 ] : https://github.com/sunshowers-code/buf-list/releases/tag/1.0.0
3643[ 0.1.3 ] : https://github.com/sunshowers-code/buf-list/releases/tag/0.1.3
3744[ 0.1.2 ] : https://github.com/sunshowers-code/buf-list/releases/tag/0.1.2
Original file line number Diff line number Diff line change @@ -37,7 +37,7 @@ Collect a fallible stream of `Bytes` into a `BufList`:
3737``` rust
3838use buf_list :: BufList ;
3939use bytes :: Bytes ;
40- use futures :: stream :: TryStreamExt ;
40+ use futures :: TryStreamExt ;
4141
4242// A common example is a stream of bytes read over HTTP.
4343let stream = futures :: stream :: iter (
@@ -52,6 +52,28 @@ let buf_list = stream.try_collect::<BufList>().await?;
5252assert_eq! (buf_list . num_chunks (), 3 );
5353```
5454
55+ ## Converting to ` Stream ` s
56+
57+ A ` BufList ` can be converted into a ` futures::Stream ` , or a ` TryStream ` , of ` Bytes ` chunks. Use
58+ this recipe to do so:
59+
60+ (This will be exposed as an API on ` BufList ` once ` Stream ` and/or ` TryStream ` become part of
61+ stable Rust.)
62+
63+ ``` rust
64+ use buf_list :: BufList ;
65+ use bytes :: Bytes ;
66+ use futures :: {Stream , TryStream };
67+
68+ fn into_stream (buf_list : BufList ) -> impl Stream <Item = Bytes > {
69+ futures :: stream :: iter (buf_list )
70+ }
71+
72+ fn into_try_stream <E >(buf_list : BufList ) -> impl TryStream <Ok = Bytes , Error = E > {
73+ futures :: stream :: iter (buf_list . into_iter (). map (Ok ))
74+ }
75+ ```
76+
5577## Minimum supported Rust version
5678
5779The minimum supported Rust version (MSRV) is ** 1.39** , same as the ` bytes ` crate.
Original file line number Diff line number Diff line change 4242//! ```
4343//! use buf_list::BufList;
4444//! use bytes::Bytes;
45- //! use futures::stream:: TryStreamExt;
45+ //! use futures::TryStreamExt;
4646//!
4747//! # #[tokio::main(flavor = "current_thread")]
4848//! # async fn main() -> Result<(), ()> {
6060//! # Ok(()) }
6161//! ```
6262//!
63+ //! # Converting to `Stream`s
64+ //!
65+ //! A `BufList` can be converted into a `futures::Stream`, or a `TryStream`, of `Bytes` chunks. Use
66+ //! this recipe to do so:
67+ //!
68+ //! (This will be exposed as an API on `BufList` once `Stream` and/or `TryStream` become part of
69+ //! stable Rust.)
70+ //!
71+ //! ```rust
72+ //! use buf_list::BufList;
73+ //! use bytes::Bytes;
74+ //! use futures::{Stream, TryStream};
75+ //!
76+ //! fn into_stream(buf_list: BufList) -> impl Stream<Item = Bytes> {
77+ //! futures::stream::iter(buf_list)
78+ //! }
79+ //!
80+ //! fn into_try_stream<E>(buf_list: BufList) -> impl TryStream<Ok = Bytes, Error = E> {
81+ //! futures::stream::iter(buf_list.into_iter().map(Ok))
82+ //! }
83+ //! ```
84+ //!
6385//! # Minimum supported Rust version
6486//!
6587//! The minimum supported Rust version (MSRV) is **1.39**, same as the `bytes` crate.
You can’t perform that action at this time.
0 commit comments