pub trait BodyStream: 'static {
// Required method
fn poll_next(
self: Pin<&mut Self>,
context: &mut Context<'_>,
) -> Poll<Option<Result<Vec<u8>, BodyStreamError>>>;
// Provided method
fn recycle(self: Pin<&mut Self>, spent: Vec<u8>) { ... }
}Expand description
Runtime-neutral, pull-based response byte stream.
A transport polls the next chunk only after it has capacity to write it. That pull boundary is the framework’s backpressure contract; producers do not depend on Tokio, Compio, or a Cloudflare runtime.
Required Methods§
fn poll_next( self: Pin<&mut Self>, context: &mut Context<'_>, ) -> Poll<Option<Result<Vec<u8>, BodyStreamError>>>
Provided Methods§
Sourcefn recycle(self: Pin<&mut Self>, spent: Vec<u8>)
fn recycle(self: Pin<&mut Self>, spent: Vec<u8>)
Offers a spent chunk’s buffer back to the producer.
A consumer that copies chunks out of the stream can return the vector here once it is done with it; a producer that refills recycled buffers then moves a long body with a handful of allocations instead of one per chunk. Purely an optimization hint: the buffer’s contents are dead either way, and the default implementation simply drops it.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".