Skip to main content

Client

Trait Client 

Source
pub trait Client: Send {
    // Required methods
    fn request(
        &mut self,
        msg: ClientMessage,
    ) -> impl Future<Output = Result<ServerMessage>> + Send;
    fn request_stream(
        &mut self,
        msg: ClientMessage,
    ) -> impl Stream<Item = Result<ServerMessage>> + Send + '_;

    // Provided methods
    fn send(
        &mut self,
        req: SendRequest,
    ) -> impl Future<Output = Result<SendResponse>> + Send { ... }
    fn stream(
        &mut self,
        req: StreamRequest,
    ) -> impl Stream<Item = Result<StreamEvent>> + Send + '_ { ... }
    fn download(
        &mut self,
        req: DownloadRequest,
    ) -> impl Stream<Item = Result<DownloadEvent>> + Send + '_ { ... }
    fn hub(
        &mut self,
        req: HubRequest,
    ) -> impl Stream<Item = Result<HubEvent>> + Send + '_ { ... }
    fn ping(&mut self) -> impl Future<Output = Result<()>> + Send { ... }
}
Expand description

Client-side protocol interface.

Implementors provide two transport primitives — request for request-response and request_stream for streaming operations. All typed methods are provided defaults that delegate to these primitives.

Required Methods§

Source

fn request( &mut self, msg: ClientMessage, ) -> impl Future<Output = Result<ServerMessage>> + Send

Send a ClientMessage and receive a single ServerMessage.

Source

fn request_stream( &mut self, msg: ClientMessage, ) -> impl Stream<Item = Result<ServerMessage>> + Send + '_

Send a ClientMessage and receive a stream of ServerMessages.

This is a raw transport primitive — the stream reads indefinitely. Callers must detect the terminal sentinel (e.g. StreamEnd, DownloadEnd) and stop consuming. The typed streaming methods handle this automatically.

Provided Methods§

Source

fn send( &mut self, req: SendRequest, ) -> impl Future<Output = Result<SendResponse>> + Send

Send a message to an agent and receive a complete response.

Source

fn stream( &mut self, req: StreamRequest, ) -> impl Stream<Item = Result<StreamEvent>> + Send + '_

Send a message to an agent and receive a streamed response.

Source

fn download( &mut self, req: DownloadRequest, ) -> impl Stream<Item = Result<DownloadEvent>> + Send + '_

Download a model’s files with progress reporting.

Source

fn hub( &mut self, req: HubRequest, ) -> impl Stream<Item = Result<HubEvent>> + Send + '_

Install or uninstall a hub package, streaming progress events.

Source

fn ping(&mut self) -> impl Future<Output = Result<()>> + Send

Ping the server (keepalive).

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§