33// You may obtain a copy of the License in the LICENSE-APACHE file or at:
44// https://www.apache.org/licenses/LICENSE-2.0
55
6+ //! The `impl_anon!` macro
7+
68use crate :: fields:: { Field , Fields , FieldsNamed , FieldsUnnamed , StructStyle } ;
7- use crate :: { IdentFormatter , Scope , ScopeItem } ;
9+ use crate :: scope:: { Scope , ScopeItem } ;
10+ use crate :: IdentFormatter ;
811use proc_macro2:: { Span , TokenStream } ;
912use quote:: { quote, ToTokens , TokenStreamExt } ;
1013use syn:: token:: { Brace , Colon , Comma , Eq , Paren , Semi } ;
1114use syn:: { parse_quote, punctuated:: Punctuated , spanned:: Spanned } ;
1215use syn:: { Attribute , GenericParam , Generics , Ident , ItemImpl , Member , Token , Type , TypePath } ;
1316
14- /// A field of a [`Singleton `]
17+ /// A field of a [`Anon `]
1518#[ derive( Debug ) ]
16- pub struct SingletonField {
19+ pub struct AnonField {
1720 /// Field attributes
1821 pub attrs : Vec < Attribute > ,
1922 /// Field visibility
@@ -32,13 +35,13 @@ pub struct SingletonField {
3235 pub assignment : Option < ( Eq , syn:: Expr ) > ,
3336}
3437
35- /// A struct with a single instantiation
38+ /// Contents of `impl_anon!`
3639///
37- /// The singleton macro may be used to conveniently declare a struct's type,
40+ /// The impl_anon macro may be used to conveniently declare a struct's type,
3841/// implementations and construct an instance.
3942/// This struct represents the macro's input.
4043#[ derive( Debug ) ]
41- pub struct Singleton {
44+ pub struct Anon {
4245 /// Struct attributes
4346 pub attrs : Vec < Attribute > ,
4447 /// `struct` token
@@ -50,14 +53,14 @@ pub struct Singleton {
5053 /// Struct style: unit/tuple/regular
5154 pub style : StructStyle ,
5255 /// Struct fields
53- pub fields : Punctuated < SingletonField , Comma > ,
56+ pub fields : Punctuated < AnonField , Comma > ,
5457 /// (Explicit) struct implementations
5558 pub impls : Vec < ItemImpl > ,
5659}
5760
58- impl Singleton {
59- /// Convert to a [`SingletonScope `]
60- pub fn into_scope ( mut self ) -> SingletonScope {
61+ impl Anon {
62+ /// Convert to a [`AnonScope `]
63+ pub fn into_scope ( mut self ) -> AnonScope {
6164 let mut idfmt = IdentFormatter :: new ( ) ;
6265
6366 let mut fields = Punctuated :: < Field , Comma > :: new ( ) ;
@@ -221,7 +224,7 @@ impl Singleton {
221224 let scope = Scope {
222225 attrs : self . attrs ,
223226 vis : syn:: Visibility :: Inherited ,
224- ident : parse_quote ! { _Singleton } ,
227+ ident : parse_quote ! { _Anon } ,
225228 generics : self . generics ,
226229 item : ScopeItem :: Struct {
227230 token : self . token ,
@@ -232,7 +235,7 @@ impl Singleton {
232235 generated : vec ! [ ] ,
233236 } ;
234237
235- SingletonScope ( scope, field_val_toks)
238+ AnonScope ( scope, field_val_toks)
236239 }
237240}
238241
@@ -243,21 +246,21 @@ impl Singleton {
243246///
244247/// Tokens may be generated by [`Self::expand`].
245248#[ derive( Debug ) ]
246- pub struct SingletonScope ( Scope , TokenStream ) ;
249+ pub struct AnonScope ( Scope , TokenStream ) ;
247250
248- impl std:: ops:: Deref for SingletonScope {
251+ impl std:: ops:: Deref for AnonScope {
249252 type Target = Scope ;
250253 fn deref ( & self ) -> & Scope {
251254 & self . 0
252255 }
253256}
254- impl std:: ops:: DerefMut for SingletonScope {
257+ impl std:: ops:: DerefMut for AnonScope {
255258 fn deref_mut ( & mut self ) -> & mut Scope {
256259 & mut self . 0
257260 }
258261}
259262
260- impl SingletonScope {
263+ impl AnonScope {
261264 /// Generate the [`TokenStream`]
262265 ///
263266 /// This is a convenience function. It is valid to, instead, (1) call
@@ -269,7 +272,7 @@ impl SingletonScope {
269272 }
270273}
271274
272- impl ToTokens for SingletonScope {
275+ impl ToTokens for AnonScope {
273276 fn to_tokens ( & self , tokens : & mut TokenStream ) {
274277 let scope = & self . 0 ;
275278 let field_val_toks = & self . 1 ;
@@ -278,7 +281,7 @@ impl ToTokens for SingletonScope {
278281 {
279282 #scope
280283
281- _Singleton {
284+ _Anon {
282285 #field_val_toks
283286 }
284287 }
@@ -389,7 +392,7 @@ mod parsing {
389392 } )
390393 }
391394
392- impl SingletonField {
395+ impl AnonField {
393396 fn check_is_fixed ( ty : & Type , input_span : Span ) -> Result < ( ) > {
394397 let is_fixed = match ty {
395398 Type :: ImplTrait ( _) | Type :: Infer ( _) => false ,
@@ -448,7 +451,7 @@ mod parsing {
448451 Self :: check_is_fixed ( & ty, input. span ( ) ) ?;
449452 }
450453
451- Ok ( SingletonField {
454+ Ok ( AnonField {
452455 attrs,
453456 vis,
454457 ident,
@@ -471,7 +474,7 @@ mod parsing {
471474 Self :: check_is_fixed ( & ty, input. span ( ) ) ?;
472475 }
473476
474- Ok ( SingletonField {
477+ Ok ( AnonField {
475478 attrs,
476479 vis,
477480 ident : None ,
@@ -482,7 +485,7 @@ mod parsing {
482485 }
483486 }
484487
485- impl Parse for Singleton {
488+ impl Parse for Anon {
486489 fn parse ( input : ParseStream ) -> Result < Self > {
487490 let attrs = input. call ( Attribute :: parse_outer) ?;
488491 let token = input. parse :: < Token ! [ struct ] > ( ) ?;
@@ -500,7 +503,7 @@ mod parsing {
500503 if generics. where_clause . is_none ( ) && lookahead. peek ( Paren ) {
501504 let content;
502505 let paren_token = parenthesized ! ( content in input) ;
503- fields = content. parse_terminated ( SingletonField :: parse_unnamed, Token ! [ , ] ) ?;
506+ fields = content. parse_terminated ( AnonField :: parse_unnamed, Token ! [ , ] ) ?;
504507
505508 lookahead = input. lookahead1 ( ) ;
506509 if lookahead. peek ( Token ! [ where ] ) {
@@ -517,7 +520,7 @@ mod parsing {
517520 let content;
518521 let brace_token = braced ! ( content in input) ;
519522 style = StructStyle :: Regular ( brace_token) ;
520- fields = content. parse_terminated ( SingletonField :: parse_named, Token ! [ , ] ) ?;
523+ fields = content. parse_terminated ( AnonField :: parse_named, Token ! [ , ] ) ?;
521524 } else if lookahead. peek ( Semi ) {
522525 style = StructStyle :: Unit ( input. parse ( ) ?) ;
523526 fields = Punctuated :: new ( ) ;
@@ -530,7 +533,7 @@ mod parsing {
530533 impls. push ( parse_impl ( None , input) ?) ;
531534 }
532535
533- Ok ( Singleton {
536+ Ok ( Anon {
534537 attrs,
535538 token,
536539 generics,
0 commit comments