]>
git.proxmox.com Git - rustc.git/blob - src/vendor/syn-0.12.15/src/item.rs
1 // Copyright 2018 Syn Developers
3 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
4 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
5 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
6 // option. This file may not be copied, modified, or distributed
7 // except according to those terms.
10 use derive
::{Data, DeriveInput}
;
11 use punctuated
::Punctuated
;
12 use proc_macro2
::TokenStream
;
13 use token
::{Brace, Paren}
;
15 #[cfg(feature = "extra-traits")]
16 use tt
::TokenStreamHelper
;
17 #[cfg(feature = "extra-traits")]
18 use std
::hash
::{Hash, Hasher}
;
20 ast_enum_of_structs
! {
21 /// Things that can appear directly inside of a module or scope.
23 /// *This type is available if Syn is built with the `"full"` feature.*
25 /// # Syntax tree enum
27 /// This type is a [syntax tree enum].
29 /// [syntax tree enum]: enum.Expr.html#syntax-tree-enums
31 /// An `extern crate` item: `extern crate serde`.
33 /// *This type is available if Syn is built with the `"full"` feature.*
34 pub ExternCrate(ItemExternCrate
{
35 pub attrs
: Vec
<Attribute
>,
37 pub extern_token
: Token
![extern],
38 pub crate_token
: Token
![crate],
40 pub rename
: Option
<(Token
![as], Ident
)>,
41 pub semi_token
: Token
![;],
44 /// A use declaration: `use std::collections::HashMap`.
46 /// *This type is available if Syn is built with the `"full"` feature.*
48 pub attrs
: Vec
<Attribute
>,
50 pub use_token
: Token
![use],
51 pub leading_colon
: Option
<Token
![::]>,
52 pub prefix
: Punctuated
<Ident
, Token
![::]>,
54 pub semi_token
: Token
![;],
57 /// A static item: `static BIKE: Shed = Shed(42)`.
59 /// *This type is available if Syn is built with the `"full"` feature.*
60 pub Static(ItemStatic
{
61 pub attrs
: Vec
<Attribute
>,
63 pub static_token
: Token
![static],
64 pub mutability
: Option
<Token
![mut]>,
66 pub colon_token
: Token
![:],
68 pub eq_token
: Token
![=],
70 pub semi_token
: Token
![;],
73 /// A constant item: `const MAX: u16 = 65535`.
75 /// *This type is available if Syn is built with the `"full"` feature.*
77 pub attrs
: Vec
<Attribute
>,
79 pub const_token
: Token
![const],
81 pub colon_token
: Token
![:],
83 pub eq_token
: Token
![=],
85 pub semi_token
: Token
![;],
88 /// A free-standing function: `fn process(n: usize) -> Result<()> { ...
91 /// *This type is available if Syn is built with the `"full"` feature.*
93 pub attrs
: Vec
<Attribute
>,
95 pub constness
: Option
<Token
![const]>,
96 pub unsafety
: Option
<Token
![unsafe]>,
99 pub decl
: Box
<FnDecl
>,
100 pub block
: Box
<Block
>,
103 /// A module or module declaration: `mod m` or `mod m { ... }`.
105 /// *This type is available if Syn is built with the `"full"` feature.*
107 pub attrs
: Vec
<Attribute
>,
109 pub mod_token
: Token
![mod],
111 pub content
: Option
<(token
::Brace
, Vec
<Item
>)>,
112 pub semi
: Option
<Token
![;]>,
115 /// A block of foreign items: `extern "C" { ... }`.
117 /// *This type is available if Syn is built with the `"full"` feature.*
118 pub ForeignMod(ItemForeignMod
{
119 pub attrs
: Vec
<Attribute
>,
121 pub brace_token
: token
::Brace
,
122 pub items
: Vec
<ForeignItem
>,
125 /// A type alias: `type Result<T> = std::result::Result<T, MyError>`.
127 /// *This type is available if Syn is built with the `"full"` feature.*
129 pub attrs
: Vec
<Attribute
>,
131 pub type_token
: Token
![type],
133 pub generics
: Generics
,
134 pub eq_token
: Token
![=],
136 pub semi_token
: Token
![;],
139 /// A struct definition: `struct Foo<A> { x: A }`.
141 /// *This type is available if Syn is built with the `"full"` feature.*
142 pub Struct(ItemStruct
{
143 pub attrs
: Vec
<Attribute
>,
145 pub struct_token
: Token
![struct],
147 pub generics
: Generics
,
149 pub semi_token
: Option
<Token
![;]>,
152 /// An enum definition: `enum Foo<A, B> { C<A>, D<B> }`.
154 /// *This type is available if Syn is built with the `"full"` feature.*
156 pub attrs
: Vec
<Attribute
>,
158 pub enum_token
: Token
![enum],
160 pub generics
: Generics
,
161 pub brace_token
: token
::Brace
,
162 pub variants
: Punctuated
<Variant
, Token
![,]>,
165 /// A union definition: `union Foo<A, B> { x: A, y: B }`.
167 /// *This type is available if Syn is built with the `"full"` feature.*
168 pub Union(ItemUnion
{
169 pub attrs
: Vec
<Attribute
>,
171 pub union_token
: Token
![union],
173 pub generics
: Generics
,
174 pub fields
: FieldsNamed
,
177 /// A trait definition: `pub trait Iterator { ... }`.
179 /// *This type is available if Syn is built with the `"full"` feature.*
180 pub Trait(ItemTrait
{
181 pub attrs
: Vec
<Attribute
>,
183 pub unsafety
: Option
<Token
![unsafe]>,
184 pub auto_token
: Option
<Token
![auto]>,
185 pub trait_token
: Token
![trait],
187 pub generics
: Generics
,
188 pub colon_token
: Option
<Token
![:]>,
189 pub supertraits
: Punctuated
<TypeParamBound
, Token
![+]>,
190 pub brace_token
: token
::Brace
,
191 pub items
: Vec
<TraitItem
>,
194 /// An impl block providing trait or associated items: `impl<A> Trait
195 /// for Data<A> { ... }`.
197 /// *This type is available if Syn is built with the `"full"` feature.*
199 pub attrs
: Vec
<Attribute
>,
200 pub defaultness
: Option
<Token
![default]>,
201 pub unsafety
: Option
<Token
![unsafe]>,
202 pub impl_token
: Token
![impl],
203 pub generics
: Generics
,
204 /// Trait this impl implements.
205 pub trait_
: Option
<(Option
<Token
![!]>, Path
, Token
![for])>,
206 /// The Self type of the impl.
207 pub self_ty
: Box
<Type
>,
208 pub brace_token
: token
::Brace
,
209 pub items
: Vec
<ImplItem
>,
212 /// A macro invocation, which includes `macro_rules!` definitions.
214 /// *This type is available if Syn is built with the `"full"` feature.*
215 pub Macro(ItemMacro
{
216 pub attrs
: Vec
<Attribute
>,
217 /// The `example` in `macro_rules! example { ... }`.
218 pub ident
: Option
<Ident
>,
220 pub semi_token
: Option
<Token
![;]>,
223 /// A 2.0-style declarative macro introduced by the `macro` keyword.
225 /// *This type is available if Syn is built with the `"full"` feature.*
226 pub Macro2(ItemMacro2
#manual_extra_traits {
227 pub attrs
: Vec
<Attribute
>,
229 pub macro_token
: Token
![macro],
231 pub paren_token
: Paren
,
232 pub args
: TokenStream
,
233 pub brace_token
: Brace
,
234 pub body
: TokenStream
,
237 /// Tokens forming an item not interpreted by Syn.
239 /// *This type is available if Syn is built with the `"full"` feature.*
240 pub Verbatim(ItemVerbatim
#manual_extra_traits {
241 pub tts
: TokenStream
,
246 #[cfg(feature = "extra-traits")]
247 impl Eq
for ItemMacro2 {}
249 #[cfg(feature = "extra-traits")]
250 impl PartialEq
for ItemMacro2
{
251 fn eq(&self, other
: &Self) -> bool
{
252 self.attrs
== other
.attrs
&& self.vis
== other
.vis
&& self.macro_token
== other
.macro_token
253 && self.ident
== other
.ident
&& self.paren_token
== other
.paren_token
254 && TokenStreamHelper(&self.args
) == TokenStreamHelper(&other
.args
)
255 && self.brace_token
== other
.brace_token
256 && TokenStreamHelper(&self.body
) == TokenStreamHelper(&other
.body
)
260 #[cfg(feature = "extra-traits")]
261 impl Hash
for ItemMacro2
{
262 fn hash
<H
>(&self, state
: &mut H
)
266 self.attrs
.hash(state
);
267 self.vis
.hash(state
);
268 self.macro_token
.hash(state
);
269 self.ident
.hash(state
);
270 self.paren_token
.hash(state
);
271 TokenStreamHelper(&self.args
).hash(state
);
272 self.brace_token
.hash(state
);
273 TokenStreamHelper(&self.body
).hash(state
);
277 #[cfg(feature = "extra-traits")]
278 impl Eq
for ItemVerbatim {}
280 #[cfg(feature = "extra-traits")]
281 impl PartialEq
for ItemVerbatim
{
282 fn eq(&self, other
: &Self) -> bool
{
283 TokenStreamHelper(&self.tts
) == TokenStreamHelper(&other
.tts
)
287 #[cfg(feature = "extra-traits")]
288 impl Hash
for ItemVerbatim
{
289 fn hash
<H
>(&self, state
: &mut H
)
293 TokenStreamHelper(&self.tts
).hash(state
);
297 impl From
<DeriveInput
> for Item
{
298 fn from(input
: DeriveInput
) -> Item
{
300 Data
::Struct(data
) => Item
::Struct(ItemStruct
{
303 struct_token
: data
.struct_token
,
305 generics
: input
.generics
,
307 semi_token
: data
.semi_token
,
309 Data
::Enum(data
) => Item
::Enum(ItemEnum
{
312 enum_token
: data
.enum_token
,
314 generics
: input
.generics
,
315 brace_token
: data
.brace_token
,
316 variants
: data
.variants
,
318 Data
::Union(data
) => Item
::Union(ItemUnion
{
321 union_token
: data
.union_token
,
323 generics
: input
.generics
,
330 ast_enum_of_structs
! {
331 /// A suffix of an import tree in a `use` item: `Type as Renamed` or `*`.
333 /// *This type is available if Syn is built with the `"full"` feature.*
335 /// # Syntax tree enum
337 /// This type is a [syntax tree enum].
339 /// [syntax tree enum]: enum.Expr.html#syntax-tree-enums
341 /// An identifier imported by a `use` item: `Type` or `Type as Renamed`.
343 /// *This type is available if Syn is built with the `"full"` feature.*
346 pub rename
: Option
<(Token
![as], Ident
)>,
349 /// A glob import in a `use` item: `*`.
351 /// *This type is available if Syn is built with the `"full"` feature.*
353 pub star_token
: Token
![*],
356 /// A braced list of imports in a `use` item: `{A, B, C}`.
358 /// *This type is available if Syn is built with the `"full"` feature.*
360 pub brace_token
: token
::Brace
,
361 pub items
: Punctuated
<UseTree
, Token
![,]>,
366 ast_enum_of_structs
! {
367 /// An item within an `extern` block.
369 /// *This type is available if Syn is built with the `"full"` feature.*
371 /// # Syntax tree enum
373 /// This type is a [syntax tree enum].
375 /// [syntax tree enum]: enum.Expr.html#syntax-tree-enums
376 pub enum ForeignItem
{
377 /// A foreign function in an `extern` block.
379 /// *This type is available if Syn is built with the `"full"` feature.*
380 pub Fn(ForeignItemFn
{
381 pub attrs
: Vec
<Attribute
>,
384 pub decl
: Box
<FnDecl
>,
385 pub semi_token
: Token
![;],
388 /// A foreign static item in an `extern` block: `static ext: u8`.
390 /// *This type is available if Syn is built with the `"full"` feature.*
391 pub Static(ForeignItemStatic
{
392 pub attrs
: Vec
<Attribute
>,
394 pub static_token
: Token
![static],
395 pub mutability
: Option
<Token
![mut]>,
397 pub colon_token
: Token
![:],
399 pub semi_token
: Token
![;],
402 /// A foreign type in an `extern` block: `type void`.
404 /// *This type is available if Syn is built with the `"full"` feature.*
405 pub Type(ForeignItemType
{
406 pub attrs
: Vec
<Attribute
>,
408 pub type_token
: Token
![type],
410 pub semi_token
: Token
![;],
413 /// Tokens in an `extern` block not interpreted by Syn.
415 /// *This type is available if Syn is built with the `"full"` feature.*
416 pub Verbatim(ForeignItemVerbatim
#manual_extra_traits {
417 pub tts
: TokenStream
,
422 #[cfg(feature = "extra-traits")]
423 impl Eq
for ForeignItemVerbatim {}
425 #[cfg(feature = "extra-traits")]
426 impl PartialEq
for ForeignItemVerbatim
{
427 fn eq(&self, other
: &Self) -> bool
{
428 TokenStreamHelper(&self.tts
) == TokenStreamHelper(&other
.tts
)
432 #[cfg(feature = "extra-traits")]
433 impl Hash
for ForeignItemVerbatim
{
434 fn hash
<H
>(&self, state
: &mut H
)
438 TokenStreamHelper(&self.tts
).hash(state
);
442 ast_enum_of_structs
! {
443 /// An item declaration within the definition of a trait.
445 /// *This type is available if Syn is built with the `"full"` feature.*
447 /// # Syntax tree enum
449 /// This type is a [syntax tree enum].
451 /// [syntax tree enum]: enum.Expr.html#syntax-tree-enums
453 /// An associated constant within the definition of a trait.
455 /// *This type is available if Syn is built with the `"full"` feature.*
456 pub Const(TraitItemConst
{
457 pub attrs
: Vec
<Attribute
>,
458 pub const_token
: Token
![const],
460 pub colon_token
: Token
![:],
462 pub default: Option
<(Token
![=], Expr
)>,
463 pub semi_token
: Token
![;],
466 /// A trait method within the definition of a trait.
468 /// *This type is available if Syn is built with the `"full"` feature.*
469 pub Method(TraitItemMethod
{
470 pub attrs
: Vec
<Attribute
>,
472 pub default: Option
<Block
>,
473 pub semi_token
: Option
<Token
![;]>,
476 /// An associated type within the definition of a trait.
478 /// *This type is available if Syn is built with the `"full"` feature.*
479 pub Type(TraitItemType
{
480 pub attrs
: Vec
<Attribute
>,
481 pub type_token
: Token
![type],
483 pub generics
: Generics
,
484 pub colon_token
: Option
<Token
![:]>,
485 pub bounds
: Punctuated
<TypeParamBound
, Token
![+]>,
486 pub default: Option
<(Token
![=], Type
)>,
487 pub semi_token
: Token
![;],
490 /// A macro invocation within the definition of a trait.
492 /// *This type is available if Syn is built with the `"full"` feature.*
493 pub Macro(TraitItemMacro
{
494 pub attrs
: Vec
<Attribute
>,
496 pub semi_token
: Option
<Token
![;]>,
499 /// Tokens within the definition of a trait not interpreted by Syn.
501 /// *This type is available if Syn is built with the `"full"` feature.*
502 pub Verbatim(TraitItemVerbatim
#manual_extra_traits {
503 pub tts
: TokenStream
,
508 #[cfg(feature = "extra-traits")]
509 impl Eq
for TraitItemVerbatim {}
511 #[cfg(feature = "extra-traits")]
512 impl PartialEq
for TraitItemVerbatim
{
513 fn eq(&self, other
: &Self) -> bool
{
514 TokenStreamHelper(&self.tts
) == TokenStreamHelper(&other
.tts
)
518 #[cfg(feature = "extra-traits")]
519 impl Hash
for TraitItemVerbatim
{
520 fn hash
<H
>(&self, state
: &mut H
)
524 TokenStreamHelper(&self.tts
).hash(state
);
528 ast_enum_of_structs
! {
529 /// An item within an impl block.
531 /// *This type is available if Syn is built with the `"full"` feature.*
533 /// # Syntax tree enum
535 /// This type is a [syntax tree enum].
537 /// [syntax tree enum]: enum.Expr.html#syntax-tree-enums
539 /// An associated constant within an impl block.
541 /// *This type is available if Syn is built with the `"full"` feature.*
542 pub Const(ImplItemConst
{
543 pub attrs
: Vec
<Attribute
>,
545 pub defaultness
: Option
<Token
![default]>,
546 pub const_token
: Token
![const],
548 pub colon_token
: Token
![:],
550 pub eq_token
: Token
![=],
552 pub semi_token
: Token
![;],
555 /// A method within an impl block.
557 /// *This type is available if Syn is built with the `"full"` feature.*
558 pub Method(ImplItemMethod
{
559 pub attrs
: Vec
<Attribute
>,
561 pub defaultness
: Option
<Token
![default]>,
566 /// An associated type within an impl block.
568 /// *This type is available if Syn is built with the `"full"` feature.*
569 pub Type(ImplItemType
{
570 pub attrs
: Vec
<Attribute
>,
572 pub defaultness
: Option
<Token
![default]>,
573 pub type_token
: Token
![type],
575 pub generics
: Generics
,
576 pub eq_token
: Token
![=],
578 pub semi_token
: Token
![;],
581 /// A macro invocation within an impl block.
583 /// *This type is available if Syn is built with the `"full"` feature.*
584 pub Macro(ImplItemMacro
{
585 pub attrs
: Vec
<Attribute
>,
587 pub semi_token
: Option
<Token
![;]>,
590 /// Tokens within an impl block not interpreted by Syn.
592 /// *This type is available if Syn is built with the `"full"` feature.*
593 pub Verbatim(ImplItemVerbatim
#manual_extra_traits {
594 pub tts
: TokenStream
,
599 #[cfg(feature = "extra-traits")]
600 impl Eq
for ImplItemVerbatim {}
602 #[cfg(feature = "extra-traits")]
603 impl PartialEq
for ImplItemVerbatim
{
604 fn eq(&self, other
: &Self) -> bool
{
605 TokenStreamHelper(&self.tts
) == TokenStreamHelper(&other
.tts
)
609 #[cfg(feature = "extra-traits")]
610 impl Hash
for ImplItemVerbatim
{
611 fn hash
<H
>(&self, state
: &mut H
)
615 TokenStreamHelper(&self.tts
).hash(state
);
620 /// A method's signature in a trait or implementation: `unsafe fn
621 /// initialize(&self)`.
623 /// *This type is available if Syn is built with the `"full"` feature.*
624 pub struct MethodSig
{
625 pub constness
: Option
<Token
![const]>,
626 pub unsafety
: Option
<Token
![unsafe]>,
627 pub abi
: Option
<Abi
>,
634 /// Header of a function declaration, without including the body.
636 /// *This type is available if Syn is built with the `"full"` feature.*
638 pub fn_token
: Token
![fn],
639 pub generics
: Generics
,
640 pub paren_token
: token
::Paren
,
641 pub inputs
: Punctuated
<FnArg
, Token
![,]>,
642 pub variadic
: Option
<Token
![...]>,
643 pub output
: ReturnType
,
647 ast_enum_of_structs
! {
648 /// An argument in a function signature: the `n: usize` in `fn f(n: usize)`.
650 /// *This type is available if Syn is built with the `"full"` feature.*
652 /// # Syntax tree enum
654 /// This type is a [syntax tree enum].
656 /// [syntax tree enum]: enum.Expr.html#syntax-tree-enums
658 /// Self captured by reference in a function signature: `&self` or `&mut
661 /// *This type is available if Syn is built with the `"full"` feature.*
662 pub SelfRef(ArgSelfRef
{
663 pub and_token
: Token
![&],
664 pub lifetime
: Option
<Lifetime
>,
665 pub mutability
: Option
<Token
![mut]>,
666 pub self_token
: Token
![self],
669 /// Self captured by value in a function signature: `self` or `mut
672 /// *This type is available if Syn is built with the `"full"` feature.*
673 pub SelfValue(ArgSelf
{
674 pub mutability
: Option
<Token
![mut]>,
675 pub self_token
: Token
![self],
678 /// An explicitly typed pattern captured by a function signature.
680 /// *This type is available if Syn is built with the `"full"` feature.*
681 pub Captured(ArgCaptured
{
683 pub colon_token
: Token
![:],
687 /// A pattern whose type is inferred captured by a function signature.
689 /// A type not bound to any pattern in a function signature.
694 #[cfg(feature = "parsing")]
700 impl_synom
!(Item
"item" alt
!(
701 syn
!(ItemExternCrate
) => { Item::ExternCrate }
703 syn
!(ItemUse
) => { Item::Use }
705 syn
!(ItemStatic
) => { Item::Static }
707 syn
!(ItemConst
) => { Item::Const }
709 syn
!(ItemFn
) => { Item::Fn }
711 syn
!(ItemMod
) => { Item::Mod }
713 syn
!(ItemForeignMod
) => { Item::ForeignMod }
715 syn
!(ItemType
) => { Item::Type }
717 syn
!(ItemStruct
) => { Item::Struct }
719 syn
!(ItemEnum
) => { Item::Enum }
721 syn
!(ItemUnion
) => { Item::Union }
723 syn
!(ItemTrait
) => { Item::Trait }
725 syn
!(ItemImpl
) => { Item::Impl }
727 syn
!(ItemMacro
) => { Item::Macro }
729 syn
!(ItemMacro2
) => { Item::Macro2 }
732 impl_synom
!(ItemMacro
"macro item" do_parse
!(
733 attrs
: many0
!(Attribute
::parse_outer
) >>
734 what
: call
!(Path
::parse_mod_style
) >>
736 ident
: option
!(syn
!(Ident
)) >>
737 body
: call
!(tt
::delimited
) >>
738 semi
: cond
!(!is_brace(&body
.0), punct
!(;)) >>
752 // TODO: figure out the actual grammar; is body required to be braced?
753 impl_synom
!(ItemMacro2
"macro2 item" do_parse
!(
754 attrs
: many0
!(Attribute
::parse_outer
) >>
755 vis
: syn
!(Visibility
) >>
756 macro_
: keyword
!(macro) >>
757 ident
: syn
!(Ident
) >>
758 args
: call
!(tt
::parenthesized
) >>
759 body
: call
!(tt
::braced
) >>
772 impl_synom
!(ItemExternCrate
"extern crate item" do_parse
!(
773 attrs
: many0
!(Attribute
::parse_outer
) >>
774 vis
: syn
!(Visibility
) >>
775 extern_
: keyword
!(extern) >>
776 crate_
: keyword
!(crate) >>
777 ident
: syn
!(Ident
) >>
778 rename
: option
!(tuple
!(keyword
!(as), syn
!(Ident
))) >>
783 extern_token
: extern_
,
791 impl_synom
!(ItemUse
"use item" do_parse
!(
792 attrs
: many0
!(Attribute
::parse_outer
) >>
793 vis
: syn
!(Visibility
) >>
794 use_
: keyword
!(use) >>
795 leading_colon
: option
!(punct
!(::)) >>
796 mut prefix
: call
!(Punctuated
::parse_terminated_with
, use_prefix
) >>
797 tree
: switch
!(value
!(prefix
.empty_or_trailing()),
798 true => syn
!(UseTree
)
801 tuple
!(keyword
!(as), syn
!(Ident
)) => {
802 |rename
| UseTree
::Path(UsePath
{
803 ident
: prefix
.pop().unwrap().into_value(),
804 rename
: Some(rename
),
809 |_
| UseTree
::Path(UsePath
{
810 ident
: prefix
.pop().unwrap().into_value(),
821 leading_colon
: leading_colon
,
828 named
!(use_prefix
-> Ident
, alt
!(
831 keyword
!(self) => { Into::into }
833 keyword
!(super) => { Into::into }
835 keyword
!(crate) => { Into::into }
838 impl_synom
!(UseTree
"use tree" alt
!(
839 syn
!(UsePath
) => { UseTree::Path }
841 syn
!(UseGlob
) => { UseTree::Glob }
843 syn
!(UseList
) => { UseTree::List }
846 impl_synom
!(UsePath
"use path" do_parse
!(
850 keyword
!(self) => { Into::into }
852 rename
: option
!(tuple
!(keyword
!(as), syn
!(Ident
))) >>
859 impl_synom
!(UseGlob
"use glob" do_parse
!(
866 impl_synom
!(UseList
"use list" do_parse
!(
867 list
: braces
!(Punctuated
::parse_terminated
) >>
874 impl_synom
!(ItemStatic
"static item" do_parse
!(
875 attrs
: many0
!(Attribute
::parse_outer
) >>
876 vis
: syn
!(Visibility
) >>
877 static_
: keyword
!(static) >>
878 mutability
: option
!(keyword
!(mut)) >>
879 ident
: syn
!(Ident
) >>
888 static_token
: static_
,
889 mutability
: mutability
,
894 expr
: Box
::new(value
),
899 impl_synom
!(ItemConst
"const item" do_parse
!(
900 attrs
: many0
!(Attribute
::parse_outer
) >>
901 vis
: syn
!(Visibility
) >>
902 const_
: keyword
!(const) >>
903 ident
: syn
!(Ident
) >>
917 expr
: Box
::new(value
),
922 impl_synom
!(ItemFn
"fn item" do_parse
!(
923 outer_attrs
: many0
!(Attribute
::parse_outer
) >>
924 vis
: syn
!(Visibility
) >>
925 constness
: option
!(keyword
!(const)) >>
926 unsafety
: option
!(keyword
!(unsafe)) >>
927 abi
: option
!(syn
!(Abi
)) >>
929 ident
: syn
!(Ident
) >>
930 generics
: syn
!(Generics
) >>
931 inputs
: parens
!(Punctuated
::parse_terminated
) >>
932 ret
: syn
!(ReturnType
) >>
933 where_clause
: option
!(syn
!(WhereClause
)) >>
934 inner_attrs_stmts
: braces
!(tuple
!(
935 many0
!(Attribute
::parse_inner
),
936 call
!(Block
::parse_within
)
940 let mut attrs
= outer_attrs
;
941 attrs
.extend((inner_attrs_stmts
.1).0);
945 constness
: constness
,
948 decl
: Box
::new(FnDecl
{
950 paren_token
: inputs
.0,
955 where_clause
: where_clause
,
960 block
: Box
::new(Block
{
961 brace_token
: inner_attrs_stmts
.0,
962 stmts
: (inner_attrs_stmts
.1).1,
967 impl Synom
for FnArg
{
968 named
!(parse
-> Self, alt
!(
971 lt
: option
!(syn
!(Lifetime
)) >>
972 mutability
: option
!(keyword
!(mut)) >>
973 self_
: keyword
!(self) >>
977 mutability
: mutability
,
984 mutability
: option
!(keyword
!(mut)) >>
985 self_
: keyword
!(self) >>
988 mutability
: mutability
,
1004 syn
!(Type
) => { FnArg::Ignored }
1007 fn description() -> Option
<&'
static str> {
1008 Some("function argument")
1012 impl_synom
!(ItemMod
"mod item" do_parse
!(
1013 outer_attrs
: many0
!(Attribute
::parse_outer
) >>
1014 vis
: syn
!(Visibility
) >>
1015 mod_
: keyword
!(mod) >>
1016 ident
: syn
!(Ident
) >>
1018 punct
!(;) => {|semi
| (
1026 many0
!(Attribute
::parse_inner
),
1029 ) => {|(brace
, (inner_attrs
, items
))| (
1031 Some((brace
, items
)),
1037 let mut attrs
= outer_attrs
;
1038 attrs
.extend(content_semi
.0);
1044 content
: content_semi
.1,
1045 semi
: content_semi
.2,
1049 impl_synom
!(ItemForeignMod
"foreign mod item" do_parse
!(
1050 attrs
: many0
!(Attribute
::parse_outer
) >>
1052 items
: braces
!(many0
!(ForeignItem
::parse
)) >>
1056 brace_token
: items
.0,
1061 impl_synom
!(ForeignItem
"foreign item" alt
!(
1062 syn
!(ForeignItemFn
) => { ForeignItem::Fn }
1064 syn
!(ForeignItemStatic
) => { ForeignItem::Static }
1066 syn
!(ForeignItemType
) => { ForeignItem::Type }
1069 impl_synom
!(ForeignItemFn
"foreign function" do_parse
!(
1070 attrs
: many0
!(Attribute
::parse_outer
) >>
1071 vis
: syn
!(Visibility
) >>
1072 fn_
: keyword
!(fn) >>
1073 ident
: syn
!(Ident
) >>
1074 generics
: syn
!(Generics
) >>
1075 inputs
: parens
!(do_parse
!(
1076 args
: call
!(Punctuated
::parse_terminated
) >>
1077 variadic
: option
!(cond_reduce
!(args
.empty_or_trailing(), punct
!(...))) >>
1080 ret
: syn
!(ReturnType
) >>
1081 where_clause
: option
!(syn
!(WhereClause
)) >>
1084 let (parens
, (inputs
, variadic
)) = inputs
;
1089 decl
: Box
::new(FnDecl
{
1091 paren_token
: parens
,
1095 generics
: Generics
{
1096 where_clause
: where_clause
,
1105 impl_synom
!(ForeignItemStatic
"foreign static" do_parse
!(
1106 attrs
: many0
!(Attribute
::parse_outer
) >>
1107 vis
: syn
!(Visibility
) >>
1108 static_
: keyword
!(static) >>
1109 mutability
: option
!(keyword
!(mut)) >>
1110 ident
: syn
!(Ident
) >>
1114 (ForeignItemStatic
{
1119 mutability
: mutability
,
1120 static_token
: static_
,
1126 impl_synom
!(ForeignItemType
"foreign type" do_parse
!(
1127 attrs
: many0
!(Attribute
::parse_outer
) >>
1128 vis
: syn
!(Visibility
) >>
1129 type_
: keyword
!(type) >>
1130 ident
: syn
!(Ident
) >>
1141 impl_synom
!(ItemType
"type item" do_parse
!(
1142 attrs
: many0
!(Attribute
::parse_outer
) >>
1143 vis
: syn
!(Visibility
) >>
1144 type_
: keyword
!(type) >>
1145 ident
: syn
!(Ident
) >>
1146 generics
: syn
!(Generics
) >>
1147 where_clause
: option
!(syn
!(WhereClause
)) >>
1156 generics
: Generics
{
1157 where_clause
: where_clause
,
1166 impl_synom
!(ItemStruct
"struct item" switch
!(
1167 map
!(syn
!(DeriveInput
), Into
::into
),
1168 Item
::Struct(item
) => value
!(item
)
1173 impl_synom
!(ItemEnum
"enum item" switch
!(
1174 map
!(syn
!(DeriveInput
), Into
::into
),
1175 Item
::Enum(item
) => value
!(item
)
1180 impl_synom
!(ItemUnion
"union item" do_parse
!(
1181 attrs
: many0
!(Attribute
::parse_outer
) >>
1182 vis
: syn
!(Visibility
) >>
1183 union_
: keyword
!(union) >>
1184 ident
: syn
!(Ident
) >>
1185 generics
: syn
!(Generics
) >>
1186 where_clause
: option
!(syn
!(WhereClause
)) >>
1187 fields
: syn
!(FieldsNamed
) >>
1191 union_token
: union_
,
1193 generics
: Generics
{
1194 where_clause
: where_clause
,
1201 impl_synom
!(ItemTrait
"trait item" do_parse
!(
1202 attrs
: many0
!(Attribute
::parse_outer
) >>
1203 vis
: syn
!(Visibility
) >>
1204 unsafety
: option
!(keyword
!(unsafe)) >>
1205 auto_
: option
!(keyword
!(auto)) >>
1206 trait_
: keyword
!(trait) >>
1207 ident
: syn
!(Ident
) >>
1208 generics
: syn
!(Generics
) >>
1209 colon
: option
!(punct
!(:)) >>
1210 bounds
: cond
!(colon
.is_some(), Punctuated
::parse_separated_nonempty
) >>
1211 where_clause
: option
!(syn
!(WhereClause
)) >>
1212 body
: braces
!(many0
!(TraitItem
::parse
)) >>
1218 trait_token
: trait_
,
1220 generics
: Generics
{
1221 where_clause
: where_clause
,
1225 supertraits
: bounds
.unwrap_or_default(),
1226 brace_token
: body
.0,
1231 impl_synom
!(TraitItem
"trait item" alt
!(
1232 syn
!(TraitItemConst
) => { TraitItem::Const }
1234 syn
!(TraitItemMethod
) => { TraitItem::Method }
1236 syn
!(TraitItemType
) => { TraitItem::Type }
1238 syn
!(TraitItemMacro
) => { TraitItem::Macro }
1241 impl_synom
!(TraitItemConst
"const trait item" do_parse
!(
1242 attrs
: many0
!(Attribute
::parse_outer
) >>
1243 const_
: keyword
!(const) >>
1244 ident
: syn
!(Ident
) >>
1247 default: option
!(tuple
!(punct
!(=), syn
!(Expr
))) >>
1251 const_token
: const_
,
1260 impl_synom
!(TraitItemMethod
"method trait item" do_parse
!(
1261 outer_attrs
: many0
!(Attribute
::parse_outer
) >>
1262 constness
: option
!(keyword
!(const)) >>
1263 unsafety
: option
!(keyword
!(unsafe)) >>
1264 abi
: option
!(syn
!(Abi
)) >>
1265 fn_
: keyword
!(fn) >>
1266 ident
: syn
!(Ident
) >>
1267 generics
: syn
!(Generics
) >>
1268 inputs
: parens
!(Punctuated
::parse_terminated
) >>
1269 ret
: syn
!(ReturnType
) >>
1270 where_clause
: option
!(syn
!(WhereClause
)) >>
1271 body
: option
!(braces
!(
1272 tuple
!(many0
!(Attribute
::parse_inner
),
1273 call
!(Block
::parse_within
))
1275 semi
: cond
!(body
.is_none(), punct
!(;)) >>
1277 let (inner_attrs
, stmts
) = match body
{
1278 Some((b
, (inner_attrs
, stmts
))) => (inner_attrs
, Some((stmts
, b
))),
1279 None
=> (Vec
::new(), None
),
1283 let mut attrs
= outer_attrs
;
1284 attrs
.extend(inner_attrs
);
1288 constness
: constness
,
1296 paren_token
: inputs
.0,
1298 generics
: Generics
{
1299 where_clause
: where_clause
,
1304 default: stmts
.map(|stmts
| {
1307 brace_token
: stmts
.1,
1315 impl_synom
!(TraitItemType
"trait item type" do_parse
!(
1316 attrs
: many0
!(Attribute
::parse_outer
) >>
1317 type_
: keyword
!(type) >>
1318 ident
: syn
!(Ident
) >>
1319 generics
: syn
!(Generics
) >>
1320 colon
: option
!(punct
!(:)) >>
1321 bounds
: cond
!(colon
.is_some(), Punctuated
::parse_separated_nonempty
) >>
1322 where_clause
: option
!(syn
!(WhereClause
)) >>
1323 default: option
!(tuple
!(punct
!(=), syn
!(Type
))) >>
1329 generics
: Generics
{
1330 where_clause
: where_clause
,
1334 bounds
: bounds
.unwrap_or_default(),
1340 impl_synom
!(TraitItemMacro
"trait item macro" do_parse
!(
1341 attrs
: many0
!(Attribute
::parse_outer
) >>
1343 semi
: cond
!(!is_brace(&mac
.delimiter
), punct
!(;)) >>
1351 impl_synom
!(ItemImpl
"impl item" do_parse
!(
1352 attrs
: many0
!(Attribute
::parse_outer
) >>
1353 defaultness
: option
!(keyword
!(default)) >>
1354 unsafety
: option
!(keyword
!(unsafe)) >>
1355 impl_
: keyword
!(impl) >>
1356 generics
: syn
!(Generics
) >>
1357 polarity_path
: alt
!(
1359 polarity
: option
!(punct
!(!)) >>
1361 for_
: keyword
!(for) >>
1362 (Some((polarity
, path
, for_
)))
1365 epsilon
!() => { |_| None }
1367 self_ty
: syn
!(Type
) >>
1368 where_clause
: option
!(syn
!(WhereClause
)) >>
1369 body
: braces
!(many0
!(ImplItem
::parse
)) >>
1372 defaultness
: defaultness
,
1375 generics
: Generics
{
1376 where_clause
: where_clause
,
1379 trait_
: polarity_path
,
1380 self_ty
: Box
::new(self_ty
),
1381 brace_token
: body
.0,
1386 impl_synom
!(ImplItem
"item in impl block" alt
!(
1387 syn
!(ImplItemConst
) => { ImplItem::Const }
1389 syn
!(ImplItemMethod
) => { ImplItem::Method }
1391 syn
!(ImplItemType
) => { ImplItem::Type }
1393 syn
!(ImplItemMacro
) => { ImplItem::Macro }
1396 impl_synom
!(ImplItemConst
"const item in impl block" do_parse
!(
1397 attrs
: many0
!(Attribute
::parse_outer
) >>
1398 vis
: syn
!(Visibility
) >>
1399 defaultness
: option
!(keyword
!(default)) >>
1400 const_
: keyword
!(const) >>
1401 ident
: syn
!(Ident
) >>
1405 value
: syn
!(Expr
) >>
1410 defaultness
: defaultness
,
1411 const_token
: const_
,
1421 impl_synom
!(ImplItemMethod
"method in impl block" do_parse
!(
1422 outer_attrs
: many0
!(Attribute
::parse_outer
) >>
1423 vis
: syn
!(Visibility
) >>
1424 defaultness
: option
!(keyword
!(default)) >>
1425 constness
: option
!(keyword
!(const)) >>
1426 unsafety
: option
!(keyword
!(unsafe)) >>
1427 abi
: option
!(syn
!(Abi
)) >>
1428 fn_
: keyword
!(fn) >>
1429 ident
: syn
!(Ident
) >>
1430 generics
: syn
!(Generics
) >>
1431 inputs
: parens
!(Punctuated
::parse_terminated
) >>
1432 ret
: syn
!(ReturnType
) >>
1433 where_clause
: option
!(syn
!(WhereClause
)) >>
1434 inner_attrs_stmts
: braces
!(tuple
!(
1435 many0
!(Attribute
::parse_inner
),
1436 call
!(Block
::parse_within
)
1440 let mut attrs
= outer_attrs
;
1441 attrs
.extend((inner_attrs_stmts
.1).0);
1445 defaultness
: defaultness
,
1447 constness
: constness
,
1453 paren_token
: inputs
.0,
1456 generics
: Generics
{
1457 where_clause
: where_clause
,
1464 brace_token
: inner_attrs_stmts
.0,
1465 stmts
: (inner_attrs_stmts
.1).1,
1470 impl_synom
!(ImplItemType
"type in impl block" do_parse
!(
1471 attrs
: many0
!(Attribute
::parse_outer
) >>
1472 vis
: syn
!(Visibility
) >>
1473 defaultness
: option
!(keyword
!(default)) >>
1474 type_
: keyword
!(type) >>
1475 ident
: syn
!(Ident
) >>
1476 generics
: syn
!(Generics
) >>
1483 defaultness
: defaultness
,
1493 impl_synom
!(ImplItemMacro
"macro in impl block" do_parse
!(
1494 attrs
: many0
!(Attribute
::parse_outer
) >>
1496 semi
: cond
!(!is_brace(&mac
.delimiter
), punct
!(;)) >>
1504 fn is_brace(delimiter
: &MacroDelimiter
) -> bool
{
1506 MacroDelimiter
::Brace(_
) => true,
1507 MacroDelimiter
::Paren(_
) | MacroDelimiter
::Bracket(_
) => false,
1512 #[cfg(feature = "printing")]
1515 use attr
::FilterAttrs
;
1516 use quote
::{ToTokens, Tokens}
;
1518 impl ToTokens
for ItemExternCrate
{
1519 fn to_tokens(&self, tokens
: &mut Tokens
) {
1520 tokens
.append_all(self.attrs
.outer());
1521 self.vis
.to_tokens(tokens
);
1522 self.extern_token
.to_tokens(tokens
);
1523 self.crate_token
.to_tokens(tokens
);
1524 self.ident
.to_tokens(tokens
);
1525 if let Some((ref as_token
, ref rename
)) = self.rename
{
1526 as_token
.to_tokens(tokens
);
1527 rename
.to_tokens(tokens
);
1529 self.semi_token
.to_tokens(tokens
);
1533 impl ToTokens
for ItemUse
{
1534 fn to_tokens(&self, tokens
: &mut Tokens
) {
1535 tokens
.append_all(self.attrs
.outer());
1536 self.vis
.to_tokens(tokens
);
1537 self.use_token
.to_tokens(tokens
);
1538 self.leading_colon
.to_tokens(tokens
);
1539 self.prefix
.to_tokens(tokens
);
1540 self.tree
.to_tokens(tokens
);
1541 self.semi_token
.to_tokens(tokens
);
1545 impl ToTokens
for ItemStatic
{
1546 fn to_tokens(&self, tokens
: &mut Tokens
) {
1547 tokens
.append_all(self.attrs
.outer());
1548 self.vis
.to_tokens(tokens
);
1549 self.static_token
.to_tokens(tokens
);
1550 self.mutability
.to_tokens(tokens
);
1551 self.ident
.to_tokens(tokens
);
1552 self.colon_token
.to_tokens(tokens
);
1553 self.ty
.to_tokens(tokens
);
1554 self.eq_token
.to_tokens(tokens
);
1555 self.expr
.to_tokens(tokens
);
1556 self.semi_token
.to_tokens(tokens
);
1560 impl ToTokens
for ItemConst
{
1561 fn to_tokens(&self, tokens
: &mut Tokens
) {
1562 tokens
.append_all(self.attrs
.outer());
1563 self.vis
.to_tokens(tokens
);
1564 self.const_token
.to_tokens(tokens
);
1565 self.ident
.to_tokens(tokens
);
1566 self.colon_token
.to_tokens(tokens
);
1567 self.ty
.to_tokens(tokens
);
1568 self.eq_token
.to_tokens(tokens
);
1569 self.expr
.to_tokens(tokens
);
1570 self.semi_token
.to_tokens(tokens
);
1574 impl ToTokens
for ItemFn
{
1575 fn to_tokens(&self, tokens
: &mut Tokens
) {
1576 tokens
.append_all(self.attrs
.outer());
1577 self.vis
.to_tokens(tokens
);
1578 self.constness
.to_tokens(tokens
);
1579 self.unsafety
.to_tokens(tokens
);
1580 self.abi
.to_tokens(tokens
);
1581 NamedDecl(&self.decl
, self.ident
).to_tokens(tokens
);
1582 self.block
.brace_token
.surround(tokens
, |tokens
| {
1583 tokens
.append_all(self.attrs
.inner());
1584 tokens
.append_all(&self.block
.stmts
);
1589 impl ToTokens
for ItemMod
{
1590 fn to_tokens(&self, tokens
: &mut Tokens
) {
1591 tokens
.append_all(self.attrs
.outer());
1592 self.vis
.to_tokens(tokens
);
1593 self.mod_token
.to_tokens(tokens
);
1594 self.ident
.to_tokens(tokens
);
1595 if let Some((ref brace
, ref items
)) = self.content
{
1596 brace
.surround(tokens
, |tokens
| {
1597 tokens
.append_all(self.attrs
.inner());
1598 tokens
.append_all(items
);
1601 TokensOrDefault(&self.semi
).to_tokens(tokens
);
1606 impl ToTokens
for ItemForeignMod
{
1607 fn to_tokens(&self, tokens
: &mut Tokens
) {
1608 tokens
.append_all(self.attrs
.outer());
1609 self.abi
.to_tokens(tokens
);
1610 self.brace_token
.surround(tokens
, |tokens
| {
1611 tokens
.append_all(&self.items
);
1616 impl ToTokens
for ItemType
{
1617 fn to_tokens(&self, tokens
: &mut Tokens
) {
1618 tokens
.append_all(self.attrs
.outer());
1619 self.vis
.to_tokens(tokens
);
1620 self.type_token
.to_tokens(tokens
);
1621 self.ident
.to_tokens(tokens
);
1622 self.generics
.to_tokens(tokens
);
1623 self.generics
.where_clause
.to_tokens(tokens
);
1624 self.eq_token
.to_tokens(tokens
);
1625 self.ty
.to_tokens(tokens
);
1626 self.semi_token
.to_tokens(tokens
);
1630 impl ToTokens
for ItemEnum
{
1631 fn to_tokens(&self, tokens
: &mut Tokens
) {
1632 tokens
.append_all(self.attrs
.outer());
1633 self.vis
.to_tokens(tokens
);
1634 self.enum_token
.to_tokens(tokens
);
1635 self.ident
.to_tokens(tokens
);
1636 self.generics
.to_tokens(tokens
);
1637 self.generics
.where_clause
.to_tokens(tokens
);
1638 self.brace_token
.surround(tokens
, |tokens
| {
1639 self.variants
.to_tokens(tokens
);
1644 impl ToTokens
for ItemStruct
{
1645 fn to_tokens(&self, tokens
: &mut Tokens
) {
1646 tokens
.append_all(self.attrs
.outer());
1647 self.vis
.to_tokens(tokens
);
1648 self.struct_token
.to_tokens(tokens
);
1649 self.ident
.to_tokens(tokens
);
1650 self.generics
.to_tokens(tokens
);
1652 Fields
::Named(ref fields
) => {
1653 self.generics
.where_clause
.to_tokens(tokens
);
1654 fields
.to_tokens(tokens
);
1656 Fields
::Unnamed(ref fields
) => {
1657 fields
.to_tokens(tokens
);
1658 self.generics
.where_clause
.to_tokens(tokens
);
1659 TokensOrDefault(&self.semi_token
).to_tokens(tokens
);
1662 self.generics
.where_clause
.to_tokens(tokens
);
1663 TokensOrDefault(&self.semi_token
).to_tokens(tokens
);
1669 impl ToTokens
for ItemUnion
{
1670 fn to_tokens(&self, tokens
: &mut Tokens
) {
1671 tokens
.append_all(self.attrs
.outer());
1672 self.vis
.to_tokens(tokens
);
1673 self.union_token
.to_tokens(tokens
);
1674 self.ident
.to_tokens(tokens
);
1675 self.generics
.to_tokens(tokens
);
1676 self.generics
.where_clause
.to_tokens(tokens
);
1677 self.fields
.to_tokens(tokens
);
1681 impl ToTokens
for ItemTrait
{
1682 fn to_tokens(&self, tokens
: &mut Tokens
) {
1683 tokens
.append_all(self.attrs
.outer());
1684 self.vis
.to_tokens(tokens
);
1685 self.unsafety
.to_tokens(tokens
);
1686 self.auto_token
.to_tokens(tokens
);
1687 self.trait_token
.to_tokens(tokens
);
1688 self.ident
.to_tokens(tokens
);
1689 self.generics
.to_tokens(tokens
);
1690 if !self.supertraits
.is_empty() {
1691 TokensOrDefault(&self.colon_token
).to_tokens(tokens
);
1692 self.supertraits
.to_tokens(tokens
);
1694 self.generics
.where_clause
.to_tokens(tokens
);
1695 self.brace_token
.surround(tokens
, |tokens
| {
1696 tokens
.append_all(&self.items
);
1701 impl ToTokens
for ItemImpl
{
1702 fn to_tokens(&self, tokens
: &mut Tokens
) {
1703 tokens
.append_all(self.attrs
.outer());
1704 self.defaultness
.to_tokens(tokens
);
1705 self.unsafety
.to_tokens(tokens
);
1706 self.impl_token
.to_tokens(tokens
);
1707 self.generics
.to_tokens(tokens
);
1708 if let Some((ref polarity
, ref path
, ref for_token
)) = self.trait_
{
1709 polarity
.to_tokens(tokens
);
1710 path
.to_tokens(tokens
);
1711 for_token
.to_tokens(tokens
);
1713 self.self_ty
.to_tokens(tokens
);
1714 self.generics
.where_clause
.to_tokens(tokens
);
1715 self.brace_token
.surround(tokens
, |tokens
| {
1716 tokens
.append_all(&self.items
);
1721 impl ToTokens
for ItemMacro
{
1722 fn to_tokens(&self, tokens
: &mut Tokens
) {
1723 tokens
.append_all(self.attrs
.outer());
1724 self.mac
.path
.to_tokens(tokens
);
1725 self.mac
.bang_token
.to_tokens(tokens
);
1726 self.ident
.to_tokens(tokens
);
1727 match self.mac
.delimiter
{
1728 MacroDelimiter
::Paren(ref paren
) => {
1729 paren
.surround(tokens
, |tokens
| self.mac
.tts
.to_tokens(tokens
));
1731 MacroDelimiter
::Brace(ref brace
) => {
1732 brace
.surround(tokens
, |tokens
| self.mac
.tts
.to_tokens(tokens
));
1734 MacroDelimiter
::Bracket(ref bracket
) => {
1735 bracket
.surround(tokens
, |tokens
| self.mac
.tts
.to_tokens(tokens
));
1738 self.semi_token
.to_tokens(tokens
);
1742 impl ToTokens
for ItemMacro2
{
1743 fn to_tokens(&self, tokens
: &mut Tokens
) {
1744 tokens
.append_all(self.attrs
.outer());
1745 self.vis
.to_tokens(tokens
);
1746 self.macro_token
.to_tokens(tokens
);
1747 self.ident
.to_tokens(tokens
);
1748 self.paren_token
.surround(tokens
, |tokens
| {
1749 self.args
.to_tokens(tokens
);
1751 self.brace_token
.surround(tokens
, |tokens
| {
1752 self.body
.to_tokens(tokens
);
1757 impl ToTokens
for ItemVerbatim
{
1758 fn to_tokens(&self, tokens
: &mut Tokens
) {
1759 self.tts
.to_tokens(tokens
);
1763 impl ToTokens
for UsePath
{
1764 fn to_tokens(&self, tokens
: &mut Tokens
) {
1765 self.ident
.to_tokens(tokens
);
1766 if let Some((ref as_token
, ref rename
)) = self.rename
{
1767 as_token
.to_tokens(tokens
);
1768 rename
.to_tokens(tokens
);
1773 impl ToTokens
for UseGlob
{
1774 fn to_tokens(&self, tokens
: &mut Tokens
) {
1775 self.star_token
.to_tokens(tokens
);
1779 impl ToTokens
for UseList
{
1780 fn to_tokens(&self, tokens
: &mut Tokens
) {
1781 self.brace_token
.surround(tokens
, |tokens
| {
1782 self.items
.to_tokens(tokens
);
1787 impl ToTokens
for TraitItemConst
{
1788 fn to_tokens(&self, tokens
: &mut Tokens
) {
1789 tokens
.append_all(self.attrs
.outer());
1790 self.const_token
.to_tokens(tokens
);
1791 self.ident
.to_tokens(tokens
);
1792 self.colon_token
.to_tokens(tokens
);
1793 self.ty
.to_tokens(tokens
);
1794 if let Some((ref eq_token
, ref default)) = self.default {
1795 eq_token
.to_tokens(tokens
);
1796 default.to_tokens(tokens
);
1798 self.semi_token
.to_tokens(tokens
);
1802 impl ToTokens
for TraitItemMethod
{
1803 fn to_tokens(&self, tokens
: &mut Tokens
) {
1804 tokens
.append_all(self.attrs
.outer());
1805 self.sig
.to_tokens(tokens
);
1806 match self.default {
1807 Some(ref block
) => {
1808 block
.brace_token
.surround(tokens
, |tokens
| {
1809 tokens
.append_all(self.attrs
.inner());
1810 tokens
.append_all(&block
.stmts
);
1814 TokensOrDefault(&self.semi_token
).to_tokens(tokens
);
1820 impl ToTokens
for TraitItemType
{
1821 fn to_tokens(&self, tokens
: &mut Tokens
) {
1822 tokens
.append_all(self.attrs
.outer());
1823 self.type_token
.to_tokens(tokens
);
1824 self.ident
.to_tokens(tokens
);
1825 self.generics
.to_tokens(tokens
);
1826 if !self.bounds
.is_empty() {
1827 TokensOrDefault(&self.colon_token
).to_tokens(tokens
);
1828 self.bounds
.to_tokens(tokens
);
1830 self.generics
.where_clause
.to_tokens(tokens
);
1831 if let Some((ref eq_token
, ref default)) = self.default {
1832 eq_token
.to_tokens(tokens
);
1833 default.to_tokens(tokens
);
1835 self.semi_token
.to_tokens(tokens
);
1839 impl ToTokens
for TraitItemMacro
{
1840 fn to_tokens(&self, tokens
: &mut Tokens
) {
1841 tokens
.append_all(self.attrs
.outer());
1842 self.mac
.to_tokens(tokens
);
1843 self.semi_token
.to_tokens(tokens
);
1847 impl ToTokens
for TraitItemVerbatim
{
1848 fn to_tokens(&self, tokens
: &mut Tokens
) {
1849 self.tts
.to_tokens(tokens
);
1853 impl ToTokens
for ImplItemConst
{
1854 fn to_tokens(&self, tokens
: &mut Tokens
) {
1855 tokens
.append_all(self.attrs
.outer());
1856 self.vis
.to_tokens(tokens
);
1857 self.defaultness
.to_tokens(tokens
);
1858 self.const_token
.to_tokens(tokens
);
1859 self.ident
.to_tokens(tokens
);
1860 self.colon_token
.to_tokens(tokens
);
1861 self.ty
.to_tokens(tokens
);
1862 self.eq_token
.to_tokens(tokens
);
1863 self.expr
.to_tokens(tokens
);
1864 self.semi_token
.to_tokens(tokens
);
1868 impl ToTokens
for ImplItemMethod
{
1869 fn to_tokens(&self, tokens
: &mut Tokens
) {
1870 tokens
.append_all(self.attrs
.outer());
1871 self.vis
.to_tokens(tokens
);
1872 self.defaultness
.to_tokens(tokens
);
1873 self.sig
.to_tokens(tokens
);
1874 self.block
.brace_token
.surround(tokens
, |tokens
| {
1875 tokens
.append_all(self.attrs
.inner());
1876 tokens
.append_all(&self.block
.stmts
);
1881 impl ToTokens
for ImplItemType
{
1882 fn to_tokens(&self, tokens
: &mut Tokens
) {
1883 tokens
.append_all(self.attrs
.outer());
1884 self.vis
.to_tokens(tokens
);
1885 self.defaultness
.to_tokens(tokens
);
1886 self.type_token
.to_tokens(tokens
);
1887 self.ident
.to_tokens(tokens
);
1888 self.generics
.to_tokens(tokens
);
1889 self.eq_token
.to_tokens(tokens
);
1890 self.ty
.to_tokens(tokens
);
1891 self.semi_token
.to_tokens(tokens
);
1895 impl ToTokens
for ImplItemMacro
{
1896 fn to_tokens(&self, tokens
: &mut Tokens
) {
1897 tokens
.append_all(self.attrs
.outer());
1898 self.mac
.to_tokens(tokens
);
1899 self.semi_token
.to_tokens(tokens
);
1903 impl ToTokens
for ImplItemVerbatim
{
1904 fn to_tokens(&self, tokens
: &mut Tokens
) {
1905 self.tts
.to_tokens(tokens
);
1909 impl ToTokens
for ForeignItemFn
{
1910 fn to_tokens(&self, tokens
: &mut Tokens
) {
1911 tokens
.append_all(self.attrs
.outer());
1912 self.vis
.to_tokens(tokens
);
1913 NamedDecl(&self.decl
, self.ident
).to_tokens(tokens
);
1914 self.semi_token
.to_tokens(tokens
);
1918 impl ToTokens
for ForeignItemStatic
{
1919 fn to_tokens(&self, tokens
: &mut Tokens
) {
1920 tokens
.append_all(self.attrs
.outer());
1921 self.vis
.to_tokens(tokens
);
1922 self.static_token
.to_tokens(tokens
);
1923 self.mutability
.to_tokens(tokens
);
1924 self.ident
.to_tokens(tokens
);
1925 self.colon_token
.to_tokens(tokens
);
1926 self.ty
.to_tokens(tokens
);
1927 self.semi_token
.to_tokens(tokens
);
1931 impl ToTokens
for ForeignItemType
{
1932 fn to_tokens(&self, tokens
: &mut Tokens
) {
1933 tokens
.append_all(self.attrs
.outer());
1934 self.vis
.to_tokens(tokens
);
1935 self.type_token
.to_tokens(tokens
);
1936 self.ident
.to_tokens(tokens
);
1937 self.semi_token
.to_tokens(tokens
);
1941 impl ToTokens
for ForeignItemVerbatim
{
1942 fn to_tokens(&self, tokens
: &mut Tokens
) {
1943 self.tts
.to_tokens(tokens
);
1947 impl ToTokens
for MethodSig
{
1948 fn to_tokens(&self, tokens
: &mut Tokens
) {
1949 self.constness
.to_tokens(tokens
);
1950 self.unsafety
.to_tokens(tokens
);
1951 self.abi
.to_tokens(tokens
);
1952 NamedDecl(&self.decl
, self.ident
).to_tokens(tokens
);
1956 struct NamedDecl
<'a
>(&'a FnDecl
, Ident
);
1958 impl<'a
> ToTokens
for NamedDecl
<'a
> {
1959 fn to_tokens(&self, tokens
: &mut Tokens
) {
1960 self.0.fn_token
.to_tokens(tokens
);
1961 self.1.to_tokens(tokens
);
1962 self.0.generics
.to_tokens(tokens
);
1963 self.0.paren_token
.surround(tokens
, |tokens
| {
1964 self.0.inputs
.to_tokens(tokens
);
1965 if self.0.variadic
.is_some() && !self.0.inputs
.empty_or_trailing() {
1966 <Token
![,]>::default().to_tokens(tokens
);
1968 self.0.variadic
.to_tokens(tokens
);
1970 self.0.output
.to_tokens(tokens
);
1971 self.0.generics
.where_clause
.to_tokens(tokens
);
1975 impl ToTokens
for ArgSelfRef
{
1976 fn to_tokens(&self, tokens
: &mut Tokens
) {
1977 self.and_token
.to_tokens(tokens
);
1978 self.lifetime
.to_tokens(tokens
);
1979 self.mutability
.to_tokens(tokens
);
1980 self.self_token
.to_tokens(tokens
);
1984 impl ToTokens
for ArgSelf
{
1985 fn to_tokens(&self, tokens
: &mut Tokens
) {
1986 self.mutability
.to_tokens(tokens
);
1987 self.self_token
.to_tokens(tokens
);
1991 impl ToTokens
for ArgCaptured
{
1992 fn to_tokens(&self, tokens
: &mut Tokens
) {
1993 self.pat
.to_tokens(tokens
);
1994 self.colon_token
.to_tokens(tokens
);
1995 self.ty
.to_tokens(tokens
);