Skip to content
This repository was archived by the owner on Jul 9, 2023. It is now read-only.
This repository was archived by the owner on Jul 9, 2023. It is now read-only.

Library for parsing function signature without parsing function body #16

@dtolnay

Description

@dtolnay

The Syn crate has fairly coarse compile-time control over the set of available syntax tree types. There is default-features = false mode where only the parsing API is provided with no syntax tree types at all, there is features = ["derive"] which is the default and supports structs and enums, and there is features = ["full"] which supports all possible Rust syntax.

Sometimes Rust macros, especially attribute macros, need to parse just slightly more than what is exposed by the default feature set. For example wasm-bindgen wants to parse function signatures but not their bodies. That means there should be no need for any of the expression-parsing logic enabled by features = ["full"]. They could save compile time by using features = ["derive"] in combination with a library that just parses function signatures.

pub struct Function {
    /* ... */
}

pub fn parse_signature_only(function: TokenStream) -> syn::Result<Function>;

The return struct would look like pretty much like syn::ItemFn except where the function body is kept as an unparsed TokenStream instead of a fully parsed syn::Block.

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