Macro jsonrpc_macros::build_rpc_trait [] [src]

macro_rules! build_rpc_trait {
    (
		$(#[$t_attr: meta])*
		pub trait $name: ident {
			$(
				$( #[doc=$m_doc:expr] )*
				#[ rpc( $($t:tt)* ) ]
				fn $m_name: ident ( $($p: tt)* ) -> $result: tt <$out: ty, Error>;
			)*
		}
	) => { ... };
    (
		$(#[$t_attr: meta])*
		pub trait $name: ident {
			type Metadata;
			$(
				$( #[doc=$m_doc:expr] )*
				#[ rpc( $($t:tt)* ) ]
				fn $m_name: ident ( $($p: tt)* ) -> $result: tt <$out: ty, Error>;
			)*
		}
	) => { ... };
    ( WRAP $del: expr =>
		(name = $name: expr)
		fn $method: ident (&self $(, $param: ty)*) -> $result: tt <$out: ty, Error>
	) => { ... };
    ( WRAP $del: expr =>
		(async, name = $name: expr)
		fn $method: ident (&self $(, $param: ty)*) -> $result: tt <$out: ty, Error>
	) => { ... };
    ( WRAP $del: expr =>
		(meta, name = $name: expr)
		fn $method: ident (&self, Self::Metadata $(, $param: ty)*) -> $result: tt <$out: ty, Error>
	) => { ... };
}

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: async and synchronous. These are parsed with the custom #[rpc] attribute, which must follow documentation.

The #[rpc] attribute

Valid forms: - #[rpc(name = "name_here")] (a synchronous rpc function which should be bound to the given name) - #[rpc(async, name = "name_here")] (an async rpc function which should be bound to the given name)

Synchronous function format: fn foo(&self, Param1, Param2, Param3) -> Result<Out, Error>.

Asynchronous RPC functions must come in this form: `fn foo(&self, Param1, Param2, Param3) -> BoxFuture;

Anything else will be rejected by the code generator.