1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#[macro_export]
macro_rules! jsonrpc_client {
(
$(#[$struct_attr:meta])*
pub struct $struct_name:ident {$(
$(#[$attr:meta])*
pub fn $method:ident(&mut $selff:ident $(, $arg_name:ident: $arg_ty:ty)*)
-> RpcRequest<$return_ty:ty>;
)*}
) => (
$(#[$struct_attr])*
pub struct $struct_name<T: $crate::Transport> {
transport: T,
}
impl<T: $crate::Transport> $struct_name<T> {
pub fn new(transport: T) -> Self {
$struct_name { transport }
}
$(
$(#[$attr])*
pub fn $method(&mut $selff $(, $arg_name: $arg_ty)*)
-> $crate::RpcRequest<$return_ty, T::Future>
{
let method = String::from(stringify!($method));
let params = expand_params!($($arg_name,)*);
$crate::call_method(&mut $selff.transport, method, params)
}
)*
}
)
}
#[doc(hidden)]
#[macro_export]
macro_rules! expand_params {
() => ([] as [(); 0]);
($($arg_name:ident,)+) => (($($arg_name,)+))
}