version = "0.1.0" edition = "2021" [lib] proc-macro = true [dependencies] // lib.rs use proc_macro::{Delimiter, Group, Ident, Punct, Spacing, Span, TokenStream, TokenTree}; #[proc_macro] pub fn print_twice(input: proc_macro::TokenStream) -> proc_macro::TokenStream { TokenTree::from(Group::new( Delimiter::Brace, vec![ vec![ TokenTree::from(Ident::new("println", Span::call_site())), TokenTree::from(Punct::new('!', Spacing::Alone)), TokenTree::from(Group::new(Delimiter::Parenthesis, input.clone())), ] .into_iter() .collect::<TokenStream>(), TokenTree::from(Punct::new(';', Spacing::Alone)).into(), vec![ TokenTree::from(Ident::new("println", Span::call_site())), TokenTree::from(Punct::new('!', Spacing::Alone)), TokenTree::from(Group::new(Delimiter::Parenthesis, input.clone())), ] .into_iter() .collect::<TokenStream>(), ] .into_iter() .collect::<TokenStream>(), )) .into() } *あとでわかりやすい書き方説明するので あんまり気にしなくて大丈夫です