Skip to content

Commit acd1507

Browse files
bkchrTyera Eulberg
authored andcommitted
Make build_rpc_trait! compatible for rust 2018 (paritytech#345)
The generated trait now uses `_` as identifiers for the trait function arguments.
1 parent 8407fbd commit acd1507

File tree

1 file changed

+38
-21
lines changed

1 file changed

+38
-21
lines changed

macros/src/auto_args.rs

Lines changed: 38 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -110,16 +110,19 @@ macro_rules! build_rpc_trait {
110110
$(
111111
$( #[doc=$m_doc:expr] )*
112112
#[ rpc( $($t:tt)* ) ]
113-
fn $m_name: ident ( $($p: tt)* ) -> $result: tt <$out: ty $(, $error: ty)* >;
113+
fn $m_name: ident ( $( $p: tt )* ) -> $result: tt <$out: ty $(, $error: ty)* >;
114114
)*
115115
}
116116
) => {
117117
$(#[$t_attr])*
118118
pub trait $name $(<$( $simple_generics ,)* $( $generics , )*>)* : Sized + Send + Sync + 'static {
119-
$(
120-
$(#[doc=$m_doc])*
121-
fn $m_name ( $($p)* ) -> $result<$out $(, $error)* > ;
122-
)*
119+
build_rpc_trait!(
120+
GENERATE_FUNCTIONS
121+
$(
122+
$(#[doc=$m_doc])*
123+
fn $m_name ( $( $p )* ) -> $result <$out $(, $error) *>;
124+
)*
125+
);
123126

124127
/// Transform this into an `IoDelegate`, automatically wrapping
125128
/// the parameters.
@@ -133,7 +136,7 @@ macro_rules! build_rpc_trait {
133136
$(
134137
build_rpc_trait!(WRAP del =>
135138
( $($t)* )
136-
fn $m_name ( $($p)* ) -> $result <$out $(, $error)* >
139+
fn $m_name ( $( $p )* ) -> $result <$out $(, $error)* >
137140
);
138141
)*
139142
del
@@ -155,7 +158,7 @@ macro_rules! build_rpc_trait {
155158
$(
156159
$( #[ doc=$m_doc:expr ] )*
157160
#[ rpc( $($t:tt)* ) ]
158-
fn $m_name: ident ( $($p: tt)* ) -> $result: tt <$out: ty $(, $error_std: ty) *>;
161+
fn $m_name: ident ( $( $p: tt )* ) -> $result: tt <$out: ty $(, $error_std: ty) *>;
159162
)*
160163

161164
$(
@@ -178,10 +181,12 @@ macro_rules! build_rpc_trait {
178181
$( $sub_name )*
179182
);
180183

181-
$(
182-
$(#[doc=$m_doc])*
183-
fn $m_name ( $($p)* ) -> $result <$out $(, $error_std) *>;
184-
)*
184+
build_rpc_trait!(GENERATE_FUNCTIONS
185+
$(
186+
$(#[doc=$m_doc])*
187+
fn $m_name ( $( $p )* ) -> $result <$out $(, $error_std) *>;
188+
)*
189+
);
185190

186191
$(
187192
$(#[doc=$sub_doc])*
@@ -202,7 +207,7 @@ macro_rules! build_rpc_trait {
202207
$(
203208
build_rpc_trait!(WRAP del =>
204209
( $($t)* )
205-
fn $m_name ( $($p)* ) -> $result <$out $(, $error_std)* >
210+
fn $m_name ( $( $p )* ) -> $result <$out $(, $error_std)* >
206211
);
207212
)*
208213
$(
@@ -219,17 +224,15 @@ macro_rules! build_rpc_trait {
219224
}
220225
};
221226

222-
( WRAP $del: expr =>
223-
(name = $name: expr $(, alias = [ $( $alias: expr, )+ ])*)
224-
fn $method: ident (&self $(, $param: ty)*) -> $result: tt <$out: ty $(, $error: ty)* >
227+
(GENERATE_FUNCTIONS
228+
$(
229+
$( #[doc=$m_doc:expr] )*
230+
fn $m_name: ident (&self $(, $p: ty)* ) -> $result: ty;
231+
)*
225232
) => {
226-
$del.add_method($name, move |base, params| {
227-
$crate::WrapAsync::wrap_rpc(&(Self::$method as fn(&_ $(, $param)*) -> $result <$out $(, $error)*>), base, params)
228-
});
229233
$(
230-
$(
231-
$del.add_alias($alias, $name);
232-
)+
234+
$(#[doc=$m_doc])*
235+
fn $m_name (&self $(, _: $p )* ) -> $result;
233236
)*
234237
};
235238

@@ -284,6 +287,20 @@ macro_rules! build_rpc_trait {
284287
)*
285288
)*
286289
};
290+
291+
( WRAP $del: expr =>
292+
(name = $name: expr $(, alias = [ $( $alias: expr, )+ ])*)
293+
fn $method: ident (&self $(, $param: ty)*) -> $result: tt <$out: ty $(, $error: ty)* >
294+
) => {
295+
$del.add_method($name, move |base, params| {
296+
$crate::WrapAsync::wrap_rpc(&(Self::$method as fn(&_ $(, $param)*) -> $result <$out $(, $error)*>), base, params)
297+
});
298+
$(
299+
$(
300+
$del.add_alias($alias, $name);
301+
)+
302+
)*
303+
};
287304
}
288305

289306
/// A wrapper type without an implementation of `Deserialize`

0 commit comments

Comments
 (0)