pub struct BodyWriter<D, E>(/* private fields */)
where
D: From<Vec<u8>> + Send + 'static,
E: Send + 'static;
Expand description
A std::io::Write
implementation that makes a chunked hyper response body stream.
Automatically applies gzip
content encoding if requested by the client.
The stream is infinitely buffered; calls to write
and flush
never block. flush
thus is a
hint that data should be sent to the client as soon as possible, but this shouldn’t be expected
to happen before it returns. write
and flush
may return error; this indicates that the
client certainly won’t receive any additional bytes, so the calling code should stop producing
them.
The infinite buffering avoids the need for calling code to deal with backpressure via futures or blocking. Many applications anyway produce output while holding a lock or database transaction that should finish quickly, so backpressure must be ignored anyway.
On drop, the stream will be “finished” (for gzip, this writes a special footer). There’s no way to know the complete stream was written successfully. It’s inherent in the combination of HTTP / TCP / Unix sockets / hyper anyway that only the client knows this.
Implementations§
Trait Implementations§
Source§impl<D, E> Write for BodyWriter<D, E>
impl<D, E> Write for BodyWriter<D, E>
Source§fn write(&mut self, buf: &[u8]) -> Result<usize>
fn write(&mut self, buf: &[u8]) -> Result<usize>
Source§fn flush(&mut self) -> Result<()>
fn flush(&mut self) -> Result<()>
Source§fn is_write_vectored(&self) -> bool
fn is_write_vectored(&self) -> bool
can_vector
)1.0.0 · Source§fn write_all(&mut self, buf: &[u8]) -> Result<(), Error>
fn write_all(&mut self, buf: &[u8]) -> Result<(), Error>
Source§fn write_all_vectored(&mut self, bufs: &mut [IoSlice<'_>]) -> Result<(), Error>
fn write_all_vectored(&mut self, bufs: &mut [IoSlice<'_>]) -> Result<(), Error>
write_all_vectored
)