Skip to content

Add an example of using a function-like proc macro in expression position #858

Open
@camelid

Description

@camelid

A simple example:

use proc_macro::TokenStream;

#[proc_macro]
fn comptime(_input: TokenStream) -> TokenStream {
    "1 + 2".parse().unwrap()
}

fn main() {
    println!("1 + 2 = {}", comptime!());
}

This particular example isn't particularly interesting, but I don't know proc macros very well yet :)

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-proc-macroArea: proc-macrosE-EasyWe believe this would not be difficult to actually fixNew ContentMissing features or aspects of language not currently documented.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions