JrMessage

Trait JrMessage 

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

Common bounds for any JSON-RPC message.

§Derive Macro

For simple message types, you can use the JrRequest or JrNotification derive macros which will implement both JrMessage and the respective trait. See JrRequest and JrNotification for examples.

Required Methods§

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, ) -> Option<Result<Self, Error>>

Attempt to parse this type from a method name and parameters.

Returns:

  • None if this type does not recognize the method name
  • Some(Ok(value)) if the method is recognized and deserialization succeeds
  • Some(Err(error)) if the method is recognized but deserialization fails

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§