Skip to main content

Server

Trait Server 

Source
pub trait Server:
    Sized
    + Protocol
    + Send
    + Sync
    + Send
    + Sync {
    // Required method
    fn rpc(
        &mut self,
        context: Context,
        frame: Frame<Self::Request>,
    ) -> impl Future<Output = Result<Frame<Self::Response>, Self::Error>> + Send + Sync;

    // Provided methods
    fn version(client_version: Version) -> Result<Version, Error> { ... }
    fn is_streaming(_message_type: u8) -> bool { ... }
    fn cancel_target(_frame: &Frame<Self::Request>) -> Option<u16> { ... }
    fn cancel_ack(_oldtag: u16) -> Option<Self::Response> { ... }
    fn cancelled_terminator(_method: u8) -> Option<Self::Response> { ... }
    fn rpc_stream(
        &mut self,
        context: Context,
        frame: Frame<Self::Request>,
        cancel: CancellationToken,
    ) -> impl Future<Output = Pin<Box<dyn Stream<Item = Result<Frame<Self::Response>, Self::Error>> + Send>>> + Send + Sync
       where Self::Response: 'static,
             Self::Error: 'static { ... }
}

Required Methods§

Source

fn rpc( &mut self, context: Context, frame: Frame<Self::Request>, ) -> impl Future<Output = Result<Frame<Self::Response>, Self::Error>> + Send + Sync

The main RPC method that handles incoming requests and produces responses.

Provided Methods§

Source

fn version(client_version: Version) -> Result<Version, Error>

Negotiate the protocol version to use.

Source

fn is_streaming(_message_type: u8) -> bool

r[impl jetstream.subscription.surface.declared] Whether a request of this message type opens a subscription. The declaration is the protocol’s, not the call site’s, so the dispatcher can route before it moves the frame.

Defaults to “no streaming methods”, which is every protocol written before this existed.

Source

fn cancel_target(_frame: &Frame<Self::Request>) -> Option<u16>

r[impl jetstream.subscription.dispatch.declared] r[impl jetstream.subscription.cancel] Whether this request is a cancellation, and which subscription it names. Cancellation travels as an ordinary request under a fresh tag, so the dispatcher has to be told how to recognise one — the message id is global, but decoding the payload is the protocol’s.

Defaulted to “this protocol has no cancellation”, which is correct for every protocol without subscriptions.

Source

fn cancel_ack(_oldtag: u16) -> Option<Self::Response>

r[impl jetstream.subscription.dispatch.declared] r[impl jetstream.subscription.cancel] The acknowledgement for a cancelled subscription, sent under the cancellation’s tag once the subscription has stopped emitting.

Source

fn cancelled_terminator(_method: u8) -> Option<Self::Response>

r[impl jetstream.subscription.dispatch.terminator] r[impl jetstream.subscription.termination] The terminator for a subscription that was cut short. A producer stopped by cancellation returns from its stream without saying anything, and a subscription that ends with no terminator leaves the caller’s tag in flight for the life of the lane — see r[jetstream.subscription.identity] for why it cannot simply be released. The dispatcher supplies one, and the protocol says what value it has.

r[impl jetstream.subscription.termination.discriminant] method is the message type of the request that opened the subscription. A protocol with one streaming method can ignore it; one with two cannot, because the terminator’s payload names its method and only the request says which method this was.

Source

fn rpc_stream( &mut self, context: Context, frame: Frame<Self::Request>, cancel: CancellationToken, ) -> impl Future<Output = Pin<Box<dyn Stream<Item = Result<Frame<Self::Response>, Self::Error>> + Send>>> + Send + Sync
where Self::Response: 'static, Self::Error: 'static,

r[impl jetstream.subscription.overview] Serve a subscription: one request, many responses.

r[impl jetstream.subscription.cancel] cancel is how the producer learns the subscriber has gone. Releasing only the delivery obligation is not enough — an inference or a build must be able to stop, not merely stop being listened to — so this is a parameter rather than something the dispatcher keeps to itself.

Failures travel as items, per r[jetstream.subscription.termination], which is also why the end can carry a value.

r[impl jetstream.subscription.compat.rpc-layer] Defaulted, so every existing Server implementation compiles untouched: the breakage this change carries is on the client, where RpcCall resolves to one frame.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

Source§

impl<T> Server for Server<T>
where T: NineP200L + Clone,