pub trait MethodHandler: Send + Sync {
// Required method
fn call(
&self,
params: Value,
ctx: ConnectionContext,
) -> Pin<Box<dyn Future<Output = Result<Value, RpcError>> + Send>>;
}Expand description
Object-safe async handler for one JSON-RPC method.
Why: Router stores handlers as trait objects (Arc<dyn MethodHandler>)
so methods of different concrete closure/fn types can share one registry.
Async fns are not directly object-safe, hence the call -> boxed-future
indirection.
What: implemented for Self by the blanket impl below whenever Self is
Fn(Value, ConnectionContext) -> Fut with Fut: Future<Output = Result<Value, RpcError>> — callers never need to implement this trait
by hand.
Test: exercised indirectly by every router::tests case and by
crate::serve::methods::tests.
Required Methods§
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".