Skip to main content

Server

Trait Server 

Source
pub trait Server: Sync {
    // Required methods
    fn send(
        &self,
        req: SendRequest,
    ) -> impl Future<Output = Result<SendResponse>> + Send;
    fn stream(
        &self,
        req: StreamRequest,
    ) -> impl Stream<Item = Result<StreamEvent>> + Send;
    fn download(
        &self,
        req: DownloadRequest,
    ) -> impl Stream<Item = Result<DownloadEvent>> + Send;
    fn ping(&self) -> impl Future<Output = Result<()>> + Send;
    fn hub(
        &self,
        package: CompactString,
        action: HubAction,
    ) -> impl Stream<Item = Result<HubEvent>> + Send;

    // Provided method
    fn dispatch(
        &self,
        msg: ClientMessage,
    ) -> impl Stream<Item = ServerMessage> + Send + '_ { ... }
}
Expand description

Server-side protocol handler.

Each method corresponds to one ClientMessage variant. Implementations receive typed request structs and return typed responses — no enum matching required. Streaming operations return impl Stream.

The provided dispatch method routes a raw ClientMessage to the appropriate handler, returning a stream of ServerMessages.

Required Methods§

Source

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

Handle Send — run agent and return complete response.

Source

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

Handle Stream — run agent and stream response events.

Source

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

Handle Download — download model files with progress.

Source

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

Handle Ping — keepalive.

Source

fn hub( &self, package: CompactString, action: HubAction, ) -> impl Stream<Item = Result<HubEvent>> + Send

Handle Hub — install or uninstall a hub package.

Provided Methods§

Source

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

Dispatch a ClientMessage to the appropriate handler method.

Returns a stream of ServerMessages. Request-response operations yield exactly one message; streaming operations yield many.

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§