Skip to main content

ChunkSource

Trait ChunkSource 

Source
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:

  1. It builds the request body with build_request_body. It reads its clock and then sends the request.
  2. It wraps the response body in a ChunkSource.
  3. 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 with escape_controls. It then fails the round with the error that classify_http_failure returns.
  4. 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§

Source

type Chunk: AsRef<[u8]>

One chunk of body bytes, in whatever buffer the transport yields.

Required Methods§

Source

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".

Implementors§