pub trait BytesStream: Stream {
// Provided methods
fn bytes_chunks<T>(self, capacity: usize) -> BytesChunks<Self, T>
where Self: Sized { ... }
fn try_bytes_chunks<T, E>(
self,
capacity: usize,
) -> BytesChunks<Self, Result<Bytes, TryBytesChunksError<T, E>>>
where Self: Sized { ... }
}
Provided Methods§
Sourcefn bytes_chunks<T>(self, capacity: usize) -> BytesChunks<Self, T>where
Self: Sized,
fn bytes_chunks<T>(self, capacity: usize) -> BytesChunks<Self, T>where
Self: Sized,
Group bytes in chunks of capacity
.
let stream = futures::stream::iter(vec![
Bytes::from_static(&[1, 2, 3]),
Bytes::from_static(&[4, 5, 6]),
Bytes::from_static(&[7, 8, 9]),
]);
let mut stream = stream.bytes_chunks(4);
assert_eq!(stream.next().await, Some(Bytes::from_static(&[1, 2, 3, 4])));
assert_eq!(stream.next().await, Some(Bytes::from_static(&[5, 6, 7, 8])));
assert_eq!(stream.next().await, Some(Bytes::from_static(&[9])));
assert_eq!(stream.next().await, None);
Sourcefn try_bytes_chunks<T, E>(
self,
capacity: usize,
) -> BytesChunks<Self, Result<Bytes, TryBytesChunksError<T, E>>>where
Self: Sized,
fn try_bytes_chunks<T, E>(
self,
capacity: usize,
) -> BytesChunks<Self, Result<Bytes, TryBytesChunksError<T, E>>>where
Self: Sized,
Group result of bytes in chunks of capacity
.
let stream = futures::stream::iter(vec![
Ok::<_, Infallible>(Bytes::from_static(&[1, 2, 3])),
Ok::<_, Infallible>(Bytes::from_static(&[4, 5, 6])),
Ok::<_, Infallible>(Bytes::from_static(&[7, 8, 9])),
]);
let mut stream = stream.try_bytes_chunks(4);
assert_eq!(stream.next().await, Some(Ok(Bytes::from_static(&[1, 2, 3, 4]))));
assert_eq!(stream.next().await, Some(Ok(Bytes::from_static(&[5, 6, 7, 8]))));
assert_eq!(stream.next().await, Some(Ok(Bytes::from_static(&[9]))));
assert_eq!(stream.next().await, None);