nyquest_interface/async/
body.rs

1//! Async body types for HTTP requests.
2//!
3//! This module defines types for handling asynchronous request bodies.
4
5use futures_io::{AsyncRead, AsyncSeek};
6
7/// Trait for asynchronous body streams.
8#[doc(hidden)]
9pub trait BodyStream: AsyncRead + AsyncSeek + Send {}
10
11/// Type alias for boxed asynchronous body streams.
12#[doc(hidden)]
13pub type BoxedStream = Box<dyn BodyStream>;
14
15/// Type alias for asynchronous HTTP request bodies.
16pub type Body = crate::body::Body<BoxedStream>;
17
18impl Body {
19    /// Creates a new streaming body from an async reader.
20    #[doc(hidden)]
21    pub fn stream<S: AsyncRead + AsyncSeek + Send + 'static>(
22        stream: S,
23        content_length: Option<u64>,
24    ) -> Self {
25        crate::body::Body::Stream(crate::body::StreamReader {
26            stream: Box::new(stream),
27            content_length,
28        })
29    }
30}
31
32impl<S: AsyncRead + AsyncSeek + Send + ?Sized> BodyStream for S {}