| 1 | use syn::parse::{Parse, ParseStream, Result}; |
| 2 | use syn::{Attribute, Generics, Ident, Token, Visibility, WhereClause}; |
| 3 | |
| 4 | pub struct UnitStruct { |
| 5 | pub attrs: Vec<Attribute>, |
| 6 | pub vis: Visibility, |
| 7 | pub struct_token: Token![struct], |
| 8 | pub ident: Ident, |
| 9 | pub generics: Generics, |
| 10 | } |
| 11 | |
| 12 | impl Parse for UnitStruct { |
| 13 | fn parse(input: ParseStream) -> Result<Self> { |
| 14 | let attrs = input.call(Attribute::parse_outer)?; |
| 15 | let vis: Visibility = input.parse()?; |
| 16 | let struct_token: Token![struct] = input.parse()?; |
| 17 | let ident: Ident = input.parse()?; |
| 18 | |
| 19 | // Require there to be generics. |
| 20 | input.fork().parse::<Token![<]>()?; |
| 21 | let generics: Generics = input.parse()?; |
| 22 | let where_clause: Option<WhereClause> = input.parse()?; |
| 23 | |
| 24 | input.parse::<Token![;]>()?; |
| 25 | |
| 26 | Ok(UnitStruct { |
| 27 | attrs, |
| 28 | vis, |
| 29 | struct_token, |
| 30 | ident, |
| 31 | generics: Generics { |
| 32 | where_clause, |
| 33 | ..generics |
| 34 | }, |
| 35 | }) |
| 36 | } |
| 37 | } |