Created
April 25, 2024 13:26
-
-
Save CensoredUsername/267cbf7e10a9aaf169a1f138113c481f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extern crate proc_macro; | |
use quote::quote; | |
use proc_macro2::{TokenTree, TokenStream}; | |
#[proc_macro] | |
pub fn why(tokens: proc_macro::TokenStream) -> proc_macro::TokenStream { | |
use quote::ToTokens; | |
let a = quote! { 1 + 2 }; | |
// delimit a to maintain correct precedence behaviour | |
let group = proc_macro2::Group::new( | |
proc_macro2::Delimiter::None, a.into_token_stream() | |
); | |
let a_delimited = proc_macro2::TokenTree::Group(group); | |
let b = quote! {3 * #a_delimited }; | |
dbg!(b.into()) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment