macro_rules! metadata {
() => { ... };
(
$( $sub_name: ident )+
) => { ... };
}
Expand description
Auto-generates an RPC trait from trait definition.
This just copies out all the methods, docs, and adds another
function to_delegate
which will automatically wrap each strongly-typed
function in a wrapper which handles parameter and output type serialization.
RPC functions may come in a couple forms: synchronous, async and async with metadata.
These are parsed with the custom #[rpc]
attribute, which must follow
documentation.
§The #[rpc] attribute
Valid forms:
#[rpc(name = "name_here")]
(an async rpc function which should be bound to the given name)#[rpc(meta, name = "name_here")]
(an async rpc function with metadata which should be bound to the given name)
Synchronous function format:
fn foo(&self, Param1, Param2, Param3) -> Result<Out>
.
Asynchronous RPC functions must come in this form:
`fn foo(&self, Param1, Param2, Param3) -> BoxFuture
Asynchronous RPC functions with metadata must come in this form:
`fn foo(&self, Self::Metadata, Param1, Param2, Param3) -> BoxFuture
Anything else will be rejected by the code generator.
§The #pubsub attribute
Valid form:
#[pubsub(name = "hello")] {
#[rpc(name = "hello_subscribe")]
fn subscribe(&self, Self::Metadata, pubsub::Subscriber<String>, u64);
#[rpc(name = "hello_unsubscribe")]
fn unsubscribe(&self, Option<Self::Metadata>, SubscriptionId) -> Result<bool>;
}
The attribute is used to create a new pair of subscription methods (if underlying transport supports that.)