Trait RpcService

Source
pub trait RpcService {
    const SERVICE_NAME: &'static str;

    // Required method
    fn dispatch(
        &self,
        method: &str,
        args: &[u8],
    ) -> Result<Option<Vec<u8>>, RpcError>;
}
Expand description

Typed service API marker to allow compile-time mapping between Rust methods and MethodId.

Required Associated Constants§

Source

const SERVICE_NAME: &'static str

The name of the service for routing and authorization, e.g., “storage”.

Required Methods§

Source

fn dispatch( &self, method: &str, args: &[u8], ) -> Result<Option<Vec<u8>>, RpcError>

Handle an incoming postcard-encoded request for a method id, producing a postcard-encoded response or error.

Implementations should:

  • decode args to the appropriate request type
  • execute the method
  • encode the result to postcard
  • return Ok(Some(Vec<u8>)) for non-void results, Ok(None) for void, or Err(RpcError)

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§