Search code examples
parsingrustsyn

syn::ItemStruct not found on root


I am trying to use syn::ItemStruct, but the compiler it's telling me: no ItemStruct in the root.

I am using syn = "1.0.86", following this docs: https://docs.rs/syn/1.0.86/syn/struct.ItemStruct.html

Does anyone knows how to workaround this issue?

Minimal context:

fn parse(input: &ParseBuffer) -> syn::Result<Self> {
        let _struct = input.parse::<Struct>()?;

        let mut parsed_fields = Vec::new();

        for field in _struct.span.fields {
            let struct_attribute = StructField::try_from(&field)?;
                                            
            parsed_fields.push(struct_attribute);
        }
        ...
}

Thanks.


Solution

  • The documentation says:

    This is supported on crate feature full only.

    That means you must enable the feature: in your Cargo.toml, replace

    syn = "1.0.86"
    

    with

    syn = { version = "1.0.86", features = ["full"] }
    

    Otherwise, the syn crate is compiled without that type definition.