Skip to main content

JsonRpcMessage

Trait JsonRpcMessage 

Source
pub trait JsonRpcMessage:
    'static
    + Debug
    + Sized
    + Send
    + Clone {
    // Required methods
    fn matches_method(method: &str) -> bool;
    fn method(&self) -> &str;
    fn to_untyped_message(&self) -> Result<UntypedMessage, Error>;
    fn parse_message(
        method: &str,
        params: &impl Serialize,
    ) -> Result<Self, Error>;
}
Expand description

Common bounds for any JSON-RPC message.

§Derive Macro

For simple message types, you can use the JsonRpcRequest or JsonRpcNotification derive macros which will implement both JsonRpcMessage and the respective trait. See JsonRpcRequest and JsonRpcNotification for examples.

Required Methods§

Source

fn matches_method(method: &str) -> bool

Check if this message type matches the given method name.

Source

fn method(&self) -> &str

The method name for the message.

Source

fn to_untyped_message(&self) -> Result<UntypedMessage, Error>

Convert this message into an untyped message.

Source

fn parse_message(method: &str, params: &impl Serialize) -> Result<Self, Error>

Parse this type from a method name and parameters.

Returns an error if the method doesn’t match or deserialization fails. Callers should use matches_method first to check if this type handles the method.

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§