@@ -60,33 +60,29 @@ macro_rules! with_api {
60
60
TokenStream {
61
61
fn drop( $self: $S:: TokenStream ) ;
62
62
fn clone( $self: & $S:: TokenStream ) -> $S:: TokenStream ;
63
- fn new( ) -> $S:: TokenStream ;
64
63
fn is_empty( $self: & $S:: TokenStream ) -> bool ;
65
64
fn expand_expr( $self: & $S:: TokenStream ) -> Result <$S:: TokenStream , ( ) >;
66
65
fn from_str( src: & str ) -> $S:: TokenStream ;
67
66
fn to_string( $self: & $S:: TokenStream ) -> String ;
68
67
fn from_token_tree(
69
68
tree: TokenTree <$S:: Group , $S:: Punct , $S:: Ident , $S:: Literal >,
70
69
) -> $S:: TokenStream ;
71
- fn into_iter( $self: $S:: TokenStream ) -> $S:: TokenStreamIter ;
72
- } ,
73
- TokenStreamBuilder {
74
- fn drop( $self: $S:: TokenStreamBuilder ) ;
75
- fn new( ) -> $S:: TokenStreamBuilder ;
76
- fn push( $self: & mut $S:: TokenStreamBuilder , stream: $S:: TokenStream ) ;
77
- fn build( $self: $S:: TokenStreamBuilder ) -> $S:: TokenStream ;
78
- } ,
79
- TokenStreamIter {
80
- fn drop( $self: $S:: TokenStreamIter ) ;
81
- fn clone( $self: & $S:: TokenStreamIter ) -> $S:: TokenStreamIter ;
82
- fn next(
83
- $self: & mut $S:: TokenStreamIter ,
84
- ) -> Option <TokenTree <$S:: Group , $S:: Punct , $S:: Ident , $S:: Literal >>;
70
+ fn concat_trees(
71
+ base: Option <$S:: TokenStream >,
72
+ trees: Vec <TokenTree <$S:: Group , $S:: Punct , $S:: Ident , $S:: Literal >>,
73
+ ) -> $S:: TokenStream ;
74
+ fn concat_streams(
75
+ base: Option <$S:: TokenStream >,
76
+ streams: Vec <$S:: TokenStream >,
77
+ ) -> $S:: TokenStream ;
78
+ fn into_trees(
79
+ $self: $S:: TokenStream
80
+ ) -> Vec <TokenTree <$S:: Group , $S:: Punct , $S:: Ident , $S:: Literal >>;
85
81
} ,
86
82
Group {
87
83
fn drop( $self: $S:: Group ) ;
88
84
fn clone( $self: & $S:: Group ) -> $S:: Group ;
89
- fn new( delimiter: Delimiter , stream: $S:: TokenStream ) -> $S:: Group ;
85
+ fn new( delimiter: Delimiter , stream: Option < $S:: TokenStream > ) -> $S:: Group ;
90
86
fn delimiter( $self: & $S:: Group ) -> Delimiter ;
91
87
fn stream( $self: & $S:: Group ) -> $S:: TokenStream ;
92
88
fn span( $self: & $S:: Group ) -> $S:: Span ;
@@ -311,29 +307,18 @@ impl<'a, T, M> Unmark for &'a mut Marked<T, M> {
311
307
}
312
308
}
313
309
314
- impl < T : Mark > Mark for Option < T > {
315
- type Unmarked = Option < T :: Unmarked > ;
316
- fn mark ( unmarked : Self :: Unmarked ) -> Self {
317
- unmarked. map ( T :: mark)
318
- }
319
- }
320
- impl < T : Unmark > Unmark for Option < T > {
321
- type Unmarked = Option < T :: Unmarked > ;
322
- fn unmark ( self ) -> Self :: Unmarked {
323
- self . map ( T :: unmark)
324
- }
325
- }
326
-
327
- impl < T : Mark , E : Mark > Mark for Result < T , E > {
328
- type Unmarked = Result < T :: Unmarked , E :: Unmarked > ;
310
+ impl < T : Mark > Mark for Vec < T > {
311
+ type Unmarked = Vec < T :: Unmarked > ;
329
312
fn mark ( unmarked : Self :: Unmarked ) -> Self {
330
- unmarked. map ( T :: mark) . map_err ( E :: mark)
313
+ // Should be a no-op due to std's in-place collect optimizations.
314
+ unmarked. into_iter ( ) . map ( T :: mark) . collect ( )
331
315
}
332
316
}
333
- impl < T : Unmark , E : Unmark > Unmark for Result < T , E > {
334
- type Unmarked = Result < T :: Unmarked , E :: Unmarked > ;
317
+ impl < T : Unmark > Unmark for Vec < T > {
318
+ type Unmarked = Vec < T :: Unmarked > ;
335
319
fn unmark ( self ) -> Self :: Unmarked {
336
- self . map ( T :: unmark) . map_err ( E :: unmark)
320
+ // Should be a no-op due to std's in-place collect optimizations.
321
+ self . into_iter ( ) . map ( T :: unmark) . collect ( )
337
322
}
338
323
}
339
324
@@ -367,7 +352,6 @@ mark_noop! {
367
352
Level ,
368
353
LineColumn ,
369
354
Spacing ,
370
- Bound <usize >,
371
355
}
372
356
373
357
rpc_encode_decode ! (
@@ -394,6 +378,61 @@ rpc_encode_decode!(
394
378
}
395
379
) ;
396
380
381
+ macro_rules! mark_compound {
382
+ ( enum $name: ident <$( $T: ident) ,+> { $( $variant: ident $( ( $field: ident) ) ?) ,* $( , ) ? } ) => {
383
+ impl <$( $T: Mark ) ,+> Mark for $name <$( $T) ,+> {
384
+ type Unmarked = $name <$( $T:: Unmarked ) ,+>;
385
+ fn mark( unmarked: Self :: Unmarked ) -> Self {
386
+ match unmarked {
387
+ $( $name:: $variant $( ( $field) ) ? => {
388
+ $name:: $variant $( ( Mark :: mark( $field) ) ) ?
389
+ } ) *
390
+ }
391
+ }
392
+ }
393
+
394
+ impl <$( $T: Unmark ) ,+> Unmark for $name <$( $T) ,+> {
395
+ type Unmarked = $name <$( $T:: Unmarked ) ,+>;
396
+ fn unmark( self ) -> Self :: Unmarked {
397
+ match self {
398
+ $( $name:: $variant $( ( $field) ) ? => {
399
+ $name:: $variant $( ( Unmark :: unmark( $field) ) ) ?
400
+ } ) *
401
+ }
402
+ }
403
+ }
404
+ }
405
+ }
406
+
407
+ macro_rules! compound_traits {
408
+ ( $( $t: tt) * ) => {
409
+ rpc_encode_decode!( $( $t) * ) ;
410
+ mark_compound!( $( $t) * ) ;
411
+ } ;
412
+ }
413
+
414
+ compound_traits ! (
415
+ enum Bound <T > {
416
+ Included ( x) ,
417
+ Excluded ( x) ,
418
+ Unbounded ,
419
+ }
420
+ ) ;
421
+
422
+ compound_traits ! (
423
+ enum Option <T > {
424
+ Some ( t) ,
425
+ None ,
426
+ }
427
+ ) ;
428
+
429
+ compound_traits ! (
430
+ enum Result <T , E > {
431
+ Ok ( t) ,
432
+ Err ( e) ,
433
+ }
434
+ ) ;
435
+
397
436
#[ derive( Clone ) ]
398
437
pub enum TokenTree < G , P , I , L > {
399
438
Group ( G ) ,
@@ -402,30 +441,7 @@ pub enum TokenTree<G, P, I, L> {
402
441
Literal ( L ) ,
403
442
}
404
443
405
- impl < G : Mark , P : Mark , I : Mark , L : Mark > Mark for TokenTree < G , P , I , L > {
406
- type Unmarked = TokenTree < G :: Unmarked , P :: Unmarked , I :: Unmarked , L :: Unmarked > ;
407
- fn mark ( unmarked : Self :: Unmarked ) -> Self {
408
- match unmarked {
409
- TokenTree :: Group ( tt) => TokenTree :: Group ( G :: mark ( tt) ) ,
410
- TokenTree :: Punct ( tt) => TokenTree :: Punct ( P :: mark ( tt) ) ,
411
- TokenTree :: Ident ( tt) => TokenTree :: Ident ( I :: mark ( tt) ) ,
412
- TokenTree :: Literal ( tt) => TokenTree :: Literal ( L :: mark ( tt) ) ,
413
- }
414
- }
415
- }
416
- impl < G : Unmark , P : Unmark , I : Unmark , L : Unmark > Unmark for TokenTree < G , P , I , L > {
417
- type Unmarked = TokenTree < G :: Unmarked , P :: Unmarked , I :: Unmarked , L :: Unmarked > ;
418
- fn unmark ( self ) -> Self :: Unmarked {
419
- match self {
420
- TokenTree :: Group ( tt) => TokenTree :: Group ( tt. unmark ( ) ) ,
421
- TokenTree :: Punct ( tt) => TokenTree :: Punct ( tt. unmark ( ) ) ,
422
- TokenTree :: Ident ( tt) => TokenTree :: Ident ( tt. unmark ( ) ) ,
423
- TokenTree :: Literal ( tt) => TokenTree :: Literal ( tt. unmark ( ) ) ,
424
- }
425
- }
426
- }
427
-
428
- rpc_encode_decode ! (
444
+ compound_traits ! (
429
445
enum TokenTree <G , P , I , L > {
430
446
Group ( tt) ,
431
447
Punct ( tt) ,
0 commit comments