actix_web_lab/
infallible_body_stream.rs

1use actix_http::body::{BodyStream, SizedStream};
2use bytes::Bytes;
3use futures_core::Stream;
4
5use crate::util::InfallibleStream;
6
7/// Constructs a new [`BodyStream`] from an infallible byte chunk stream.
8///
9/// This could be stabilized into Actix Web as `BodyStream::from_infallible()`.
10pub fn new_infallible_body_stream<S: Stream<Item = Bytes>>(
11    stream: S,
12) -> BodyStream<InfallibleStream<S>> {
13    BodyStream::new(InfallibleStream::new(stream))
14}
15
16/// Constructs a new [`SizedStream`] from an infallible byte chunk stream.
17///
18/// This could be stabilized into Actix Web as `SizedStream::from_infallible()`.
19pub fn new_infallible_sized_stream<S: Stream<Item = Bytes>>(
20    size: u64,
21    stream: S,
22) -> SizedStream<InfallibleStream<S>> {
23    SizedStream::new(size, InfallibleStream::new(stream))
24}