pub trait RpcMethod<const ARITY: usize> {
type Params: Params<ARITY>;
type Ok: HasLotusJson;
const NAME: &'static str;
const PARAM_NAMES: [&'static str; ARITY];
const API_PATHS: BitFlags<ApiPaths>;
const PERMISSION: Permission;
const N_REQUIRED_PARAMS: usize = ARITY;
const NAME_ALIAS: Option<&'static str> = None;
const SUMMARY: Option<&'static str> = None;
const DESCRIPTION: Option<&'static str> = None;
const SUBSCRIPTION: bool = false;
// Required method
fn handle(
ctx: Arc<RPCState<impl Blockstore + Send + Sync + 'static>>,
params: Self::Params,
) -> impl Future<Output = Result<Self::Ok, Error>> + Send;
}Expand description
A definition of an RPC method handler which:
- can be registered with an
RpcModule. - can describe itself in OpenRPC.
Note, an earlier draft of this trait had an additional type parameter for Ctx
for generality.
However, fixing it as Ctx<...> saves on complexity/confusion for implementors,
at the expense of handler flexibility, which could come back to bite us.
- All handlers accept the same type.
- All
Ctxs must beSend + Sync + 'staticdue to bounds onRpcModule. - Handlers don’t specialize on top of the given bounds, but they MAY relax them.
Required Associated Constants§
Sourceconst PARAM_NAMES: [&'static str; ARITY]
const PARAM_NAMES: [&'static str; ARITY]
Name of each argument, MUST be unique.
Sourceconst PERMISSION: Permission
const PERMISSION: Permission
See Permission
Provided Associated Constants§
Sourceconst N_REQUIRED_PARAMS: usize = ARITY
const N_REQUIRED_PARAMS: usize = ARITY
Number of required parameters, defaults to ARITY.
Sourceconst NAME_ALIAS: Option<&'static str> = None
const NAME_ALIAS: Option<&'static str> = None
Alias for NAME. Note that currently this is not reflected in the OpenRPC spec.
Sourceconst SUMMARY: Option<&'static str> = None
const SUMMARY: Option<&'static str> = None
Becomes openrpc_types::Method::summary.
Sourceconst DESCRIPTION: Option<&'static str> = None
const DESCRIPTION: Option<&'static str> = None
Becomes openrpc_types::Method::description.
Sourceconst SUBSCRIPTION: bool = false
const SUBSCRIPTION: bool = false
If it a subscription method. Defaults to false.
Required Associated Types§
Sourcetype Params: Params<ARITY>
type Params: Params<ARITY>
Types of each argument. Option-al arguments MUST follow mandatory ones.
Sourcetype Ok: HasLotusJson
type Ok: HasLotusJson
Return value of this method.
Required Methods§
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.