|
| 1 | +use super::*; |
| 2 | +use delimited::Delimited; |
| 3 | + |
| 4 | +ast_struct! { |
| 5 | + /// An enum variant. |
| 6 | + pub struct Variant { |
| 7 | + /// Name of the variant. |
| 8 | + pub ident: Ident, |
| 9 | + |
| 10 | + /// Attributes tagged on the variant. |
| 11 | + pub attrs: Vec<Attribute>, |
| 12 | + |
| 13 | + /// Type of variant. |
| 14 | + pub data: VariantData, |
| 15 | + |
| 16 | + /// Explicit discriminant, e.g. `Foo = 1` |
| 17 | + pub discriminant: Option<Expr>, |
| 18 | + |
| 19 | + pub eq_token: Option<tokens::Eq>, |
| 20 | + } |
| 21 | +} |
| 22 | + |
| 23 | +ast_enum! { |
| 24 | + /// Data stored within an enum variant or struct. |
| 25 | + pub enum VariantData { |
| 26 | + /// Struct variant, e.g. `Point { x: f64, y: f64 }`. |
| 27 | + Struct(Delimited<Field, tokens::Comma>, tokens::Brace), |
| 28 | + |
| 29 | + /// Tuple variant, e.g. `Some(T)`. |
| 30 | + Tuple(Delimited<Field, tokens::Comma>, tokens::Paren), |
| 31 | + |
| 32 | + /// Unit variant, e.g. `None`. |
| 33 | + Unit, |
| 34 | + } |
| 35 | +} |
| 36 | + |
| 37 | +ast_struct! { |
| 38 | + /// A field of a struct or enum variant. |
| 39 | + pub struct Field { |
| 40 | + /// Name of the field, if any. |
| 41 | + /// |
| 42 | + /// Fields of tuple structs have no names. |
| 43 | + pub ident: Option<Ident>, |
| 44 | + |
| 45 | + /// Visibility of the field. |
| 46 | + pub vis: Visibility, |
| 47 | + |
| 48 | + /// Attributes tagged on the field. |
| 49 | + pub attrs: Vec<Attribute>, |
| 50 | + |
| 51 | + /// Type of the field. |
| 52 | + pub ty: Ty, |
| 53 | + |
| 54 | + pub colon_token: Option<tokens::Colon>, |
| 55 | + } |
| 56 | +} |
| 57 | + |
| 58 | +ast_enum_of_structs! { |
| 59 | + /// Visibility level of an item. |
| 60 | + pub enum Visibility { |
| 61 | + /// Public, i.e. `pub`. |
| 62 | + pub Public(VisPublic { |
| 63 | + pub pub_token: tokens::Pub, |
| 64 | + }), |
| 65 | + |
| 66 | + /// Crate-visible, i.e. `pub(crate)`. |
| 67 | + pub Crate(VisCrate { |
| 68 | + pub pub_token: tokens::Pub, |
| 69 | + pub paren_token: tokens::Paren, |
| 70 | + pub crate_token: tokens::Crate, |
| 71 | + }), |
| 72 | + |
| 73 | + /// Restricted, e.g. `pub(self)` or `pub(super)` or `pub(in some::module)`. |
| 74 | + pub Restricted(VisRestricted { |
| 75 | + pub pub_token: tokens::Pub, |
| 76 | + pub paren_token: tokens::Paren, |
| 77 | + pub in_token: Option<tokens::In>, |
| 78 | + pub path: Box<Path>, |
| 79 | + }), |
| 80 | + |
| 81 | + /// Inherited, i.e. private. |
| 82 | + pub Inherited(VisInherited {}), |
| 83 | + } |
| 84 | +} |
0 commit comments