pub trait ByteSource: 'static {
// Required methods
fn poll_next(
&mut self,
context: &mut Context<'_>,
) -> Poll<Option<Result<Vec<u8>>>>;
fn close(&mut self);
fn poll_closed(&mut self, context: &mut Context<'_>) -> Poll<Result<()>>;
}Expand description
The producing side of one byte stream, supplied by its issuer.
A writer learns that the consumer stopped only at its next stream operation; the source cannot cancel an idle producer, which ends at its call’s own timeout.
§Issuer obligations
- Termination. Whenever the issuer’s physical work ends, for any reason (return, error,
panic, or the work being dropped), the source must resolve both sides: a waiting or later
poll_nextyieldsErrunless the producer had already ended cleanly, andpoll_closedbecomesReady. The framework cannot do this itself: it has no link from the physical work to the source. The issuer needs a drop guard on its physical side for this. - Failure is never a clean end. A failed, trapped or timed-out producer yields
Err, neverNone. TheErritem is terminal; reads after it yieldNone. - A clean end is only the body’s end. It does not mean the producer’s call succeeded; a
later failure reaches
Host::errorsand the result ofByteStream::close. A close the consumer asked for should settle asOkunless the producer itself failed, since every recorded failure also failsHost::close. - No re-entry. Every method runs while the stream end is borrowed. A source must not call back into the host synchronously (for example through actions that end or cancel a root); it may only store wakers and buffer state, and wake them.
Required Methods§
Sourcefn poll_next(
&mut self,
context: &mut Context<'_>,
) -> Poll<Option<Result<Vec<u8>>>>
fn poll_next( &mut self, context: &mut Context<'_>, ) -> Poll<Option<Result<Vec<u8>>>>
The next chunk, None once the producer ended cleanly, or the producer’s failure.
Returns Pending with the waker stored when no chunk is buffered.
Sourcefn poll_closed(&mut self, context: &mut Context<'_>) -> Poll<Result<()>>
fn poll_closed(&mut self, context: &mut Context<'_>) -> Poll<Result<()>>
Ready once the producer has physically stopped after ByteSource::close or its own
end, with its final outcome (an error or a timeout of the producer’s call, for example).
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".