pub trait ChunkSource {
type Chunk: AsRef<[u8]>;
// Required method
fn next_chunk(
&mut self,
) -> impl Future<Output = Result<Option<Self::Chunk>, CompletionError>> + Send;
}Expand description
A response body that a transport supplies one chunk at a time.
A transport is the code that sends a model request and receives the
reply, for example over HTTP. It answers a Chat effect, the Engine’s
request for one model reply, in four steps:
- It builds the request body with
build_request_body. It reads its clock and then sends the request. - It wraps the response body in a
ChunkSource. - On a status outside the 2xx range, it reads the error body whole with
read_body_capped. It bounds the body’s length and escapes its control characters withescape_controls. It then fails the round with the error thatclassify_http_failurereturns. - Otherwise, it passes the source to
read_completion_stream. The returned [Completion] answers the effect.
The transport opens the connection and supplies every clock reading.
The source is the only I/O that read_body_capped and
read_completion_stream touch.
Required Associated Types§
Required Methods§
Sourcefn next_chunk(
&mut self,
) -> impl Future<Output = Result<Option<Self::Chunk>, CompletionError>> + Send
fn next_chunk( &mut self, ) -> impl Future<Output = Result<Option<Self::Chunk>, CompletionError>> + Send
Returns the next chunk, or None once the body is exhausted.
When a read fails, the implementation returns the
CompletionError that the round fails with. It is a
Timeout-kind error when the read ran out of time and a
Transport-kind error otherwise. Build it with
CompletionError::new and attach the transport’s own error with
CompletionError::with_source.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".