Trait RpcServiceT

Source
pub trait RpcServiceT {
    type MethodResponse;
    type NotificationResponse;
    type BatchResponse;

    // Required methods
    fn call<'a>(
        &self,
        request: Request<'a>,
    ) -> impl Future<Output = Self::MethodResponse> + Send + 'a;
    fn batch<'a>(
        &self,
        requests: Batch<'a>,
    ) -> impl Future<Output = Self::BatchResponse> + Send + 'a;
    fn notification<'a>(
        &self,
        n: Notification<'a, Option<Cow<'a, RawValue>>>,
    ) -> impl Future<Output = Self::NotificationResponse> + Send + 'a;
}
Expand description

Represent a JSON-RPC service that can process JSON-RPC calls, notifications, and batch requests.

This trait is similar to tower::Service but it’s specialized for JSON-RPC operations.

The response type is a future that resolves to a Result<R, E> mainly because this trait is intended to by used by both client and server implementations.

In the server implementation, the error is infallible but in the client implementation, the error can occur due to I/O errors or JSON-RPC protocol errors.

Such that server implementations must use std::convert::Infallible as the error type because the underlying service requires that and otherwise one will get a compiler error that tries to explain that.

Required Associated Types§

Source

type MethodResponse

Response type for RpcServiceT::call.

Source

type NotificationResponse

Response type for RpcServiceT::notification.

Source

type BatchResponse

Response type for RpcServiceT::batch.

Required Methods§

Source

fn call<'a>( &self, request: Request<'a>, ) -> impl Future<Output = Self::MethodResponse> + Send + 'a

Processes a single JSON-RPC call, which may be a subscription or regular call.

Source

fn batch<'a>( &self, requests: Batch<'a>, ) -> impl Future<Output = Self::BatchResponse> + Send + 'a

Processes multiple JSON-RPC calls at once, similar to RpcServiceT::call.

This method wraps RpcServiceT::call and RpcServiceT::notification, but the root RPC service does not inherently recognize custom implementations of these methods.

As a result, if you have custom logic for individual calls or notifications, you must duplicate that implementation in this method or no middleware will be applied for calls inside the batch.

Source

fn notification<'a>( &self, n: Notification<'a, Option<Cow<'a, RawValue>>>, ) -> impl Future<Output = Self::NotificationResponse> + Send + 'a

Similar to RpcServiceT::call but processes a JSON-RPC notification.

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§