1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
//! Byte-count transfer limits for fallible futures streams.
//!
//! This crate is intentionally small: it wraps a `Stream<Item = Result<T, E>>`,
//! counts the bytes yielded by successful chunks, and returns a typed error as
//! soon as the configured transfer limit is exceeded. This is useful when the
//! limit is known only after request routing, authentication, or tenant lookup.
//! The default counter type is `usize`; use `TransferLimit::<u64>::from_limit`
//! or `TransferLimit::<u128>::from_limit` for streams that may exceed
//! pointer-sized byte counts.
//!
//! ```
//! use futures::{StreamExt, stream};
//! use stream_transfer_limit::{TransferLimit, TransferLimitError};
//!
//! # futures::executor::block_on(async {
//! let chunks = stream::iter([
//! Ok::<_, std::io::Error>(vec![1, 2]),
//! Ok(vec![3, 4, 5]),
//! ]);
//! let mut chunks = TransferLimit::new(4).wrap(chunks);
//!
//! assert_eq!(chunks.next().await.unwrap().unwrap(), vec![1, 2]);
//! assert!(matches!(
//! chunks.next().await.unwrap(),
//! Err(TransferLimitError::LimitExceeded { limit: 4, actual: 5 })
//! ));
//! assert!(chunks.next().await.is_none());
//! # });
//! ```
pub use ChunkLength;
pub use TransferCounter;
pub use TransferLimitError;
pub use ;