@@ -61,14 +61,17 @@ pub trait Types {
6161}
6262
6363macro_rules! declare_server_traits {
64- ( $( $name: ident {
65- $( fn $method: ident( $( $arg: ident: $arg_ty: ty) ,* $( , ) ?) $( -> $ret_ty: ty) ?; ) *
66- } ) ,* $( , ) ?) => {
67- $( pub trait $name: Types {
64+ (
65+ FreeFunctions {
66+ $( fn $method: ident( $( $arg: ident: $arg_ty: ty) ,* $( , ) ?) $( -> $ret_ty: ty) * ; ) *
67+ } ,
68+ $( $name: ident) ,* $( , ) ?
69+ ) => {
70+ pub trait FreeFunctions : Types {
6871 $( fn $method( & mut self , $( $arg: $arg_ty) ,* ) $( -> $ret_ty) ?; ) *
69- } ) *
72+ }
7073
71- pub trait Server : Types $ ( + $name ) * {
74+ pub trait Server : Types + FreeFunctions {
7275 fn globals( & mut self ) -> ExpnGlobals <Self :: Span >;
7376
7477 /// Intern a symbol received from RPC
@@ -96,18 +99,22 @@ impl<S: Server> Server for MarkedTypes<S> {
9699}
97100
98101macro_rules! define_mark_types_impls {
99- ( $( $name: ident {
100- $( fn $method: ident( $( $arg: ident: $arg_ty: ty) ,* $( , ) ?) $( -> $ret_ty: ty) ?; ) *
101- } ) ,* $( , ) ?) => {
102+ (
103+ FreeFunctions {
104+ $( fn $method: ident( $( $arg: ident: $arg_ty: ty) ,* $( , ) ?) $( -> $ret_ty: ty) * ; ) *
105+ } ,
106+ $( $name: ident) ,* $( , ) ?
107+ ) => {
102108 impl <S : Types > Types for MarkedTypes <S > {
109+ type FreeFunctions = Marked <S :: FreeFunctions , client:: FreeFunctions >;
103110 $( type $name = Marked <S :: $name, client:: $name>; ) *
104111 }
105112
106- $ ( impl <S : $name> $name for MarkedTypes <S > {
113+ impl <S : FreeFunctions > FreeFunctions for MarkedTypes <S > {
107114 $( fn $method( & mut self , $( $arg: $arg_ty) ,* ) $( -> $ret_ty) ? {
108- <_>:: mark( $name :: $method( & mut self . 0 , $( $arg. unmark( ) ) ,* ) )
115+ <_>:: mark( FreeFunctions :: $method( & mut self . 0 , $( $arg. unmark( ) ) ,* ) )
109116 } ) *
110- } ) *
117+ }
111118 }
112119}
113120with_api ! ( Self , self_, define_mark_types_impls) ;
@@ -122,7 +129,7 @@ macro_rules! define_dispatcher_impl {
122129 FreeFunctions {
123130 $( fn $method: ident( $( $arg: ident: $arg_ty: ty) ,* $( , ) ?) $( -> $ret_ty: ty) * ; ) *
124131 } ,
125- $( $name: ident { $ ( $x : tt ) * } ) ,* $( , ) ?
132+ $( $name: ident) ,* $( , ) ?
126133 ) => {
127134 // FIXME(eddyb) `pub` only for `ExecutionStrategy` below.
128135 pub trait DispatcherTrait {
@@ -142,27 +149,25 @@ macro_rules! define_dispatcher_impl {
142149
143150 let mut reader = & buf[ ..] ;
144151 match api_tags:: Method :: decode( & mut reader, & mut ( ) ) {
145- api_tags:: Method :: FreeFunctions ( m) => match m {
146- $( api_tags:: FreeFunctions :: $method => {
147- let mut call_method = || {
148- $( let $arg = <$arg_ty>:: decode( & mut reader, handle_store) ; ) *
149- FreeFunctions :: $method( server, $( $arg) ,* )
150- } ;
151- // HACK(eddyb) don't use `panic::catch_unwind` in a panic.
152- // If client and server happen to use the same `std`,
153- // `catch_unwind` asserts that the panic counter was 0,
154- // even when the closure passed to it didn't panic.
155- let r = if thread:: panicking( ) {
156- Ok ( call_method( ) )
157- } else {
158- panic:: catch_unwind( panic:: AssertUnwindSafe ( call_method) )
159- . map_err( PanicMessage :: from)
160- } ;
161-
162- buf. clear( ) ;
163- r. encode( & mut buf, handle_store) ;
164- } ) *
165- }
152+ $( api_tags:: Method :: $method => {
153+ let mut call_method = || {
154+ $( let $arg = <$arg_ty>:: decode( & mut reader, handle_store) ; ) *
155+ FreeFunctions :: $method( server, $( $arg) ,* )
156+ } ;
157+ // HACK(eddyb) don't use `panic::catch_unwind` in a panic.
158+ // If client and server happen to use the same `std`,
159+ // `catch_unwind` asserts that the panic counter was 0,
160+ // even when the closure passed to it didn't panic.
161+ let r = if thread:: panicking( ) {
162+ Ok ( call_method( ) )
163+ } else {
164+ panic:: catch_unwind( panic:: AssertUnwindSafe ( call_method) )
165+ . map_err( PanicMessage :: from)
166+ } ;
167+
168+ buf. clear( ) ;
169+ r. encode( & mut buf, handle_store) ;
170+ } ) *
166171 }
167172 buf
168173 }
0 commit comments