# parse.rs - source
Source of the Rust file `/home/runner/.cargo/registry/src/github.com-1ecc6299db9ec823/ghost-0.1.2/src/parse.rs`.
Keywords: rust, rustlang, rust-lang

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35

    use syn::parse::{Parse, ParseStream, Result};
    use syn::{Attribute, Generics, Ident, Token, Visibility, WhereClause};

    pub struct UnitStruct {
        pub attrs: Vec<Attribute>,
        pub vis: Visibility,
        pub ident: Ident,
        pub generics: Generics,
    }

    impl Parse for UnitStruct {
        fn parse(input: ParseStream) -> Result<Self> {
            let attrs = input.call(Attribute::parse_outer)?;
            let vis: Visibility = input.parse()?;
            input.parse::<Token![struct]>()?;
            let ident: Ident = input.parse()?;

            // Require there to be generics.
            input.fork().parse::<Token![<]>()?;
            let generics: Generics = input.parse()?;
            let where_clause: Option<WhereClause> = input.parse()?;

            input.parse::<Token![;]>()?;

            Ok(UnitStruct {
                attrs: attrs,
                vis: vis,
                ident: ident,
                generics: Generics {
                    where_clause: where_clause,
                    ..generics
                },
            })
        }
    }