@@ -18,71 +18,67 @@ use crate::{Delimiter, Level};
1818/// Higher-order macro describing the server RPC API, allowing automatic
1919/// generation of type-safe Rust APIs, both client-side and server-side.
2020///
21- /// `with_api!(MySelf, my_macro )` expands to:
21+ /// `with_api!(my_macro, MyTokenStream, MySpan, MySymbol )` expands to:
2222/// ```rust,ignore (pseudo-code)
2323/// my_macro! {
24- /// fn lit_character(ch: char) -> MySelf::Literal;
25- /// fn lit_span(lit: &MySelf::Literal) -> MySelf::Span;
26- /// fn lit_set_span(lit: &mut MySelf::Literal, span: MySelf::Span);
24+ /// fn ts_clone(stream: &MyTokenStream) -> MyTokenStream;
25+ /// fn span_debug(span: &MySpan) -> String;
2726/// // ...
2827/// }
2928/// ```
3029///
31- /// The first argument serves to customize the argument/return types,
32- /// to enable several different usecases:
33- ///
34- /// If `MySelf` is just `Self`, then the types are only valid inside
35- /// a trait or a trait impl, where the trait has associated types
36- /// for each of the API types. If non-associated types are desired,
37- /// a module name (`self` in practice) can be used instead of `Self`.
30+ /// The second (`TokenStream`), third (`Span`) and fourth (`Symbol`)
31+ /// argument serve to customize the argument/return types that need
32+ /// special handling, to enable several different representations of
33+ /// these types.
3834macro_rules! with_api {
39- ( $S : ident, $m : ident ) => {
35+ ( $m : ident, $TokenStream : path , $Span : path , $Symbol : path ) => {
4036 $m! {
4137 fn injected_env_var( var: & str ) -> Option <String >;
4238 fn track_env_var( var: & str , value: Option <& str >) ;
4339 fn track_path( path: & str ) ;
44- fn literal_from_str( s: & str ) -> Result <Literal <$S :: Span , $S :: Symbol >, ( ) >;
45- fn emit_diagnostic( diagnostic: Diagnostic <$S :: Span >) ;
46-
47- fn ts_drop( stream: $S :: TokenStream ) ;
48- fn ts_clone( stream: & $S :: TokenStream ) -> $S :: TokenStream ;
49- fn ts_is_empty( stream: & $S :: TokenStream ) -> bool ;
50- fn ts_expand_expr( stream: & $S :: TokenStream ) -> Result <$S :: TokenStream , ( ) >;
51- fn ts_from_str( src: & str ) -> $S :: TokenStream ;
52- fn ts_to_string( stream: & $S :: TokenStream ) -> String ;
40+ fn literal_from_str( s: & str ) -> Result <Literal <$Span, $Symbol>, ( ) >;
41+ fn emit_diagnostic( diagnostic: Diagnostic <$Span>) ;
42+
43+ fn ts_drop( stream: $TokenStream) ;
44+ fn ts_clone( stream: & $TokenStream) -> $TokenStream;
45+ fn ts_is_empty( stream: & $TokenStream) -> bool ;
46+ fn ts_expand_expr( stream: & $TokenStream) -> Result <$TokenStream, ( ) >;
47+ fn ts_from_str( src: & str ) -> $TokenStream;
48+ fn ts_to_string( stream: & $TokenStream) -> String ;
5349 fn ts_from_token_tree(
54- tree: TokenTree <$S :: TokenStream , $S :: Span , $S :: Symbol >,
55- ) -> $S :: TokenStream ;
50+ tree: TokenTree <$TokenStream, $Span, $Symbol>,
51+ ) -> $TokenStream;
5652 fn ts_concat_trees(
57- base: Option <$S :: TokenStream >,
58- trees: Vec <TokenTree <$S :: TokenStream , $S :: Span , $S :: Symbol >>,
59- ) -> $S :: TokenStream ;
53+ base: Option <$TokenStream>,
54+ trees: Vec <TokenTree <$TokenStream, $Span, $Symbol>>,
55+ ) -> $TokenStream;
6056 fn ts_concat_streams(
61- base: Option <$S :: TokenStream >,
62- streams: Vec <$S :: TokenStream >,
63- ) -> $S :: TokenStream ;
57+ base: Option <$TokenStream>,
58+ streams: Vec <$TokenStream>,
59+ ) -> $TokenStream;
6460 fn ts_into_trees(
65- stream: $S :: TokenStream
66- ) -> Vec <TokenTree <$S :: TokenStream , $S :: Span , $S :: Symbol >>;
67-
68- fn span_debug( span: $S :: Span ) -> String ;
69- fn span_parent( span: $S :: Span ) -> Option <$S :: Span >;
70- fn span_source( span: $S :: Span ) -> $S :: Span ;
71- fn span_byte_range( span: $S :: Span ) -> Range <usize >;
72- fn span_start( span: $S :: Span ) -> $S :: Span ;
73- fn span_end( span: $S :: Span ) -> $S :: Span ;
74- fn span_line( span: $S :: Span ) -> usize ;
75- fn span_column( span: $S :: Span ) -> usize ;
76- fn span_file( span: $S :: Span ) -> String ;
77- fn span_local_file( span: $S :: Span ) -> Option <String >;
78- fn span_join( span: $S :: Span , other: $S :: Span ) -> Option <$S :: Span >;
79- fn span_subspan( span: $S :: Span , start: Bound <usize >, end: Bound <usize >) -> Option <$S :: Span >;
80- fn span_resolved_at( span: $S :: Span , at: $S :: Span ) -> $S :: Span ;
81- fn span_source_text( span: $S :: Span ) -> Option <String >;
82- fn span_save_span( span: $S :: Span ) -> usize ;
83- fn span_recover_proc_macro_span( id: usize ) -> $S :: Span ;
84-
85- fn symbol_normalize_and_validate_ident( string: & str ) -> Result <$S :: Symbol , ( ) >;
61+ stream: $TokenStream
62+ ) -> Vec <TokenTree <$TokenStream, $Span, $Symbol>>;
63+
64+ fn span_debug( span: $Span) -> String ;
65+ fn span_parent( span: $Span) -> Option <$Span>;
66+ fn span_source( span: $Span) -> $Span;
67+ fn span_byte_range( span: $Span) -> Range <usize >;
68+ fn span_start( span: $Span) -> $Span;
69+ fn span_end( span: $Span) -> $Span;
70+ fn span_line( span: $Span) -> usize ;
71+ fn span_column( span: $Span) -> usize ;
72+ fn span_file( span: $Span) -> String ;
73+ fn span_local_file( span: $Span) -> Option <String >;
74+ fn span_join( span: $Span, other: $Span) -> Option <$Span>;
75+ fn span_subspan( span: $Span, start: Bound <usize >, end: Bound <usize >) -> Option <$Span>;
76+ fn span_resolved_at( span: $Span, at: $Span) -> $Span;
77+ fn span_source_text( span: $Span) -> Option <String >;
78+ fn span_save_span( span: $Span) -> usize ;
79+ fn span_recover_proc_macro_span( id: usize ) -> $Span;
80+
81+ fn symbol_normalize_and_validate_ident( string: & str ) -> Result <$Symbol, ( ) >;
8682 }
8783 } ;
8884}
@@ -126,7 +122,7 @@ pub struct BridgeConfig<'a> {
126122 input : Buffer ,
127123
128124 /// Server-side function that the client uses to make requests.
129- dispatch : closure:: Closure < ' a , Buffer , Buffer > ,
125+ dispatch : closure:: Closure < ' a > ,
130126
131127 /// If 'true', always invoke the default panic hook
132128 force_show_panics : bool ,
@@ -146,7 +142,7 @@ macro_rules! declare_tags {
146142 rpc_encode_decode!( enum ApiTags { $( $method) ,* } ) ;
147143 }
148144}
149- with_api ! ( self , declare_tags ) ;
145+ with_api ! ( declare_tags , __ , __ , __ ) ;
150146
151147/// Helper to wrap associated types to allow trait impl dispatch.
152148/// That is, normally a pair of impls for `T::Foo` and `T::Bar`
@@ -173,7 +169,7 @@ impl<T, M> Mark for Marked<T, M> {
173169 self . value
174170 }
175171}
176- impl < ' a , T , M > Mark for & ' a Marked < T , M > {
172+ impl < ' a , T > Mark for & ' a Marked < T , client :: TokenStream > {
177173 type Unmarked = & ' a T ;
178174 fn mark ( _: Self :: Unmarked ) -> Self {
179175 unreachable ! ( )
@@ -220,6 +216,8 @@ mark_noop! {
220216 Delimiter ,
221217 LitKind ,
222218 Level ,
219+ Bound <usize >,
220+ Range <usize >,
223221}
224222
225223rpc_encode_decode ! (
@@ -318,7 +316,7 @@ macro_rules! compound_traits {
318316 } ;
319317}
320318
321- compound_traits ! (
319+ rpc_encode_decode ! (
322320 enum Bound <T > {
323321 Included ( x) ,
324322 Excluded ( x) ,
@@ -390,7 +388,7 @@ pub struct Literal<Span, Symbol> {
390388 pub span : Span ,
391389}
392390
393- compound_traits ! ( struct Literal <Sp , Sy > { kind, symbol, suffix, span } ) ;
391+ compound_traits ! ( struct Literal <Span , Symbol > { kind, symbol, suffix, span } ) ;
394392
395393#[ derive( Clone ) ]
396394pub enum TokenTree < TokenStream , Span , Symbol > {
@@ -434,6 +432,6 @@ compound_traits!(
434432 struct ExpnGlobals <Span > { def_site, call_site, mixed_site }
435433) ;
436434
437- compound_traits ! (
435+ rpc_encode_decode ! (
438436 struct Range <T > { start, end }
439437) ;
0 commit comments