pub struct Streaming<T = String, E = ()> { /* private fields */ }Expand description
A streaming payload.
§Frames and Chunking
The streaming payload sends and receives data in discrete chunks or “frames”. The size is converted to hex and sent before each chunk, followed by a CRLF, the chunk data, and another CRLF.
This mimics actual HTTP chunked transfer encoding, but allows us to define our own framing protocol on top of it.
Arbitrary bytes can be encoded between these frames, but the frames do come with some overhead.
§Browser Support for Streaming Input
Browser fetch requests do not currently support full request duplexing, which means that that they do not begin handling responses until the full request has been sent.
This means that if you use a streaming input encoding, the input stream needs to end before the output will begin.
Streaming requests are only allowed over HTTP2 or HTTP3.
Also note that not all browsers support streaming bodies to servers.
Implementations§
Source§impl<T: 'static + Send, E> Streaming<T, E>
impl<T: 'static + Send, E> Streaming<T, E>
Sourcepub fn new(value: impl Stream<Item = T> + Send + 'static) -> Self
pub fn new(value: impl Stream<Item = T> + Send + 'static) -> Self
Creates a new stream from the given stream.
Sourcepub async fn next(&mut self) -> Option<Result<T, StreamingError>>
pub async fn next(&mut self) -> Option<Result<T, StreamingError>>
Returns the next item in the stream, or None if the stream has ended.
Sourcepub fn into_inner(self) -> impl Stream<Item = Result<T, StreamingError>> + Send
pub fn into_inner(self) -> impl Stream<Item = Result<T, StreamingError>> + Send
Consumes the wrapper, returning the inner stream.