Search code examples
rustattributessyn

Unable use "parse_file" function from Syn, How to enable "parsing" attribute in Rust


I am trying to use syn::parse_file function from syn crate.

But, I unable to use it and found a function in the crate with feature attribute:

#[cfg(all(feature = "parsing", feature = "full"))] 
#[cfg_attr(doc_cfg, doc(cfg(all(feature = "parsing", feature = "full"))))]
pub fn parse_file(mut content: &str) -> Result<File> {
    // other code
}

Unable to find any discription of this feature.
How do I enable these features in my project?
And use this function.


Solution

  • You can enable a certain crate feature in the Cargo.toml file - where you specify the crate itself and its version.

    For the syn crate, the parsing feature is enabled by default but full is not, as described in the docs.

    Here you can read more about how to enable features for your crates (dependencies).