pub struct Payload { /* private fields */ }Expand description
Buffered HTTP/2 payload stream.
Use Payload::read to receive the next chunk asynchronously, or consume
the payload through its Stream implementation. Waiting tasks are woken
when data, end-of-stream, or an error becomes available.
This type is not thread-safe and can also be used as a
Response body stream.
Implementations§
Source§impl Payload
impl Payload
Sourcepub fn create(cap: Capacity) -> (PayloadSender, Payload)
pub fn create(cap: Capacity) -> (PayloadSender, Payload)
Create payload stream.
This method construct two objects responsible for bytes stream generation.
-
PayloadSender- Sender side of the stream -
Payload- Receiver side of the stream
Sourcepub async fn read(&self) -> Option<Result<Bytes, PayloadError>>
pub async fn read(&self) -> Option<Result<Bytes, PayloadError>>
Receives the next payload chunk.
Returns None after the complete payload has been received.
Sourcepub fn poll_read(
&self,
cx: &mut Context<'_>,
) -> Poll<Option<Result<Bytes, PayloadError>>>
pub fn poll_read( &self, cx: &mut Context<'_>, ) -> Poll<Option<Result<Bytes, PayloadError>>>
Polls for the next payload chunk.
Sourcepub fn trailers(&self) -> Option<HeaderMap>
pub fn trailers(&self) -> Option<HeaderMap>
Returns the trailer fields received at the end of the payload.
Trailers are available after the payload is complete, None is returned if the payload is not complete or has no trailers.
Sourcepub fn take_trailers(&self) -> Option<HeaderMap>
pub fn take_trailers(&self) -> Option<HeaderMap>
Takes the trailer fields received at the end of the payload.
Like Payload::trailers, without copying. Subsequent calls return None.