Skip to content

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

Open

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 :)

Activity

  1. camelid commented on Jul 28, 2020

    @camelid
    MemberAuthor

    @rustbot modify labels to A-proc-macro New Content Easy

  2. rustbot commented on Jul 28, 2020

    @rustbot
    Collaborator

    Error: This repository is not enabled to use triagebot.
    Add a triagebot.toml in the root of the master branch to enable it.

    Please let @rust-lang/release know if you're having trouble with this bot.

  3. camelid commented on Jul 28, 2020

    @camelid
    MemberAuthor

    Something in statement and pattern positions might be nice too to make it clear that you can use them many more places now

  4. added
    E-EasyWe believe this would not be difficult to actually fix
    New ContentMissing features or aspects of language not currently documented.
    on Jul 28, 2020
  5. camelid commented on Jul 29, 2020

    @camelid
    MemberAuthor

    I also didn't see any examples in the docs of how to consume the input stream. It would be great if someone who has more knowledge of proc macros could add that!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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