Macro accepting a single string



examples/macros/say-hello-macro/src/lib.rs
extern crate proc_macro;
use proc_macro::TokenStream;

#[proc_macro]
pub fn say_hello(input: TokenStream) -> TokenStream {
    println!("Input: {}", input);

    let value = input.to_string();
    println!("Value: {}", value);

    let code = format!(r#"println!("Hello {value}");"#);
    code.parse().unwrap()
}

Input: Joe
Value: Joe
Input: Jane
Value: Jane
Hello Joe
Hello Jane


examples/macros/say-hello-use/src/main.rs
extern crate say_hello_macro;
use say_hello_macro::say_hello;

fn main() {
    say_hello!(Joe);
    say_hello!(Jane);
}