Skip to main content

PubSubRpcHandler

Trait PubSubRpcHandler 

Source
pub trait PubSubRpcHandler:
    Clone
    + Send
    + Sync
    + Unpin
    + 'static {
    type Request: DeserializeOwned + Send + Sync + Debug;
    type SubscriptionId: Hash + PartialEq + Eq + Send + Sync + Debug;
    type Subscription: Stream<Item = Value> + Send + Sync + Unpin;

    // Required method
    fn on_request(
        &self,
        request: Self::Request,
        cx: PubSubContext<Self>,
    ) -> impl Future<Output = ResponseResult> + Send;

    // Provided methods
    fn on_request_error(
        &self,
        _method: &str,
        _id: &Id,
        _params: &Value,
        _error: &RpcError,
    ) { ... }
    fn close_on_subscription_end(
        &self,
        _subscription: &Self::Subscription,
    ) -> bool { ... }
}
Expand description

The general purpose trait for handling RPC requests and subscriptions

Required Associated Types§

Source

type Request: DeserializeOwned + Send + Sync + Debug

The request type to expect

Source

type SubscriptionId: Hash + PartialEq + Eq + Send + Sync + Debug

The identifier to use for subscriptions

Source

type Subscription: Stream<Item = Value> + Send + Sync + Unpin

The subscription type this handle may create

Required Methods§

Source

fn on_request( &self, request: Self::Request, cx: PubSubContext<Self>, ) -> impl Future<Output = ResponseResult> + Send

Invoked when the request was received

Provided Methods§

Source

fn on_request_error( &self, _method: &str, _id: &Id, _params: &Value, _error: &RpcError, )

Invoked when a deserialized request returns an error from Self::on_request. Parameters retain their original shape with fork URL credentials redacted. Deserialization errors are excluded because their messages can contain request parameters.

Source

fn close_on_subscription_end(&self, _subscription: &Self::Subscription) -> bool

Whether an ended subscription requires closing the client connection.

Dyn Compatibility§

This trait is not dyn compatible.

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

Implementors§