Skip to content

Field: Support easy access name #1938

@latot

Description

@latot

Hi all! I has been using syn for some time, and something very recurrent to me to do, is always the need to build how to access fields, like for structs do the self.#ident, specially if we are working in project when we access all fields even if they are enum or structs.

I think would be nice be able to have a field in the Field struct that represent this access, maybe something like:

pub struct Field {
    pub attrs: Vec<Attribute>,
    pub vis: Visibility,
    pub mutability: FieldMutability,
    pub ident: Option<Ident>,
    pub access_path: proc_macro2::TokenStream,
    pub colon_token: Option<Colon>,
    pub ty: Type,
}

This would help a lot for named and unnamed structs, now to keep things simple, enums variants do not have predefined names for the fields, so use some random ones like field_x would do the trick, then we only need to declare the names in each variant Self::A#definition a function that build that from the fields would be nice, and that function would be idea to be located on the Fields struct as Option<proc_macro2::TokenStream>.

Thx!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions