@@ -5,16 +5,16 @@ use super::*;
55use std:: marker:: PhantomData ;
66use std:: sync:: atomic:: AtomicU32 ;
77
8- macro_rules! define_handles {
8+ macro_rules! define_client_handles {
99 (
1010 ' owned: $( $oty: ident, ) *
1111 ' interned: $( $ity: ident, ) *
1212 ) => {
1313 #[ repr( C ) ]
1414 #[ allow( non_snake_case) ]
15- pub struct HandleCounters {
16- $( $oty: AtomicU32 , ) *
17- $( $ity: AtomicU32 , ) *
15+ pub ( super ) struct HandleCounters {
16+ $( pub ( super ) $oty: AtomicU32 , ) *
17+ $( pub ( super ) $ity: AtomicU32 , ) *
1818 }
1919
2020 impl HandleCounters {
@@ -29,22 +29,6 @@ macro_rules! define_handles {
2929 }
3030 }
3131
32- // FIXME(eddyb) generate the definition of `HandleStore` in `server.rs`.
33- #[ allow( non_snake_case) ]
34- pub ( super ) struct HandleStore <S : server:: Types > {
35- $( $oty: handle:: OwnedStore <S :: $oty>, ) *
36- $( $ity: handle:: InternedStore <S :: $ity>, ) *
37- }
38-
39- impl <S : server:: Types > HandleStore <S > {
40- pub ( super ) fn new( handle_counters: & ' static HandleCounters ) -> Self {
41- HandleStore {
42- $( $oty: handle:: OwnedStore :: new( & handle_counters. $oty) , ) *
43- $( $ity: handle:: InternedStore :: new( & handle_counters. $ity) , ) *
44- }
45- }
46- }
47-
4832 $(
4933 pub ( crate ) struct $oty {
5034 handle: handle:: Handle ,
@@ -72,53 +56,18 @@ macro_rules! define_handles {
7256 }
7357 }
7458
75- impl <S : server:: Types > DecodeMut <' _, ' _, HandleStore <server:: MarkedTypes <S >>>
76- for Marked <S :: $oty, $oty>
77- {
78- fn decode( r: & mut Reader <' _>, s: & mut HandleStore <server:: MarkedTypes <S >>) -> Self {
79- s. $oty. take( handle:: Handle :: decode( r, & mut ( ) ) )
80- }
81- }
82-
8359 impl <S > Encode <S > for & $oty {
8460 fn encode( self , w: & mut Writer , s: & mut S ) {
8561 self . handle. encode( w, s) ;
8662 }
8763 }
8864
89- impl <' s, S : server:: Types > Decode <' _, ' s, HandleStore <server:: MarkedTypes <S >>>
90- for & ' s Marked <S :: $oty, $oty>
91- {
92- fn decode( r: & mut Reader <' _>, s: & ' s HandleStore <server:: MarkedTypes <S >>) -> Self {
93- & s. $oty[ handle:: Handle :: decode( r, & mut ( ) ) ]
94- }
95- }
96-
9765 impl <S > Encode <S > for & mut $oty {
9866 fn encode( self , w: & mut Writer , s: & mut S ) {
9967 self . handle. encode( w, s) ;
10068 }
10169 }
10270
103- impl <' s, S : server:: Types > DecodeMut <' _, ' s, HandleStore <server:: MarkedTypes <S >>>
104- for & ' s mut Marked <S :: $oty, $oty>
105- {
106- fn decode(
107- r: & mut Reader <' _>,
108- s: & ' s mut HandleStore <server:: MarkedTypes <S >>
109- ) -> Self {
110- & mut s. $oty[ handle:: Handle :: decode( r, & mut ( ) ) ]
111- }
112- }
113-
114- impl <S : server:: Types > Encode <HandleStore <server:: MarkedTypes <S >>>
115- for Marked <S :: $oty, $oty>
116- {
117- fn encode( self , w: & mut Writer , s: & mut HandleStore <server:: MarkedTypes <S >>) {
118- s. $oty. alloc( self ) . encode( w, s) ;
119- }
120- }
121-
12271 impl <S > DecodeMut <' _, ' _, S > for $oty {
12372 fn decode( r: & mut Reader <' _>, s: & mut S ) -> Self {
12473 $oty {
@@ -145,22 +94,6 @@ macro_rules! define_handles {
14594 }
14695 }
14796
148- impl <S : server:: Types > DecodeMut <' _, ' _, HandleStore <server:: MarkedTypes <S >>>
149- for Marked <S :: $ity, $ity>
150- {
151- fn decode( r: & mut Reader <' _>, s: & mut HandleStore <server:: MarkedTypes <S >>) -> Self {
152- s. $ity. copy( handle:: Handle :: decode( r, & mut ( ) ) )
153- }
154- }
155-
156- impl <S : server:: Types > Encode <HandleStore <server:: MarkedTypes <S >>>
157- for Marked <S :: $ity, $ity>
158- {
159- fn encode( self , w: & mut Writer , s: & mut HandleStore <server:: MarkedTypes <S >>) {
160- s. $ity. alloc( self ) . encode( w, s) ;
161- }
162- }
163-
16497 impl <S > DecodeMut <' _, ' _, S > for $ity {
16598 fn decode( r: & mut Reader <' _>, s: & mut S ) -> Self {
16699 $ity {
@@ -172,15 +105,7 @@ macro_rules! define_handles {
172105 ) *
173106 }
174107}
175- define_handles ! {
176- ' owned:
177- FreeFunctions ,
178- TokenStream ,
179- SourceFile ,
180-
181- ' interned:
182- Span ,
183- }
108+ with_api_handle_types ! ( define_client_handles) ;
184109
185110// FIXME(eddyb) generate these impls by pattern-matching on the
186111// names of methods - also could use the presence of `fn drop`
0 commit comments