I have the following macro. Note that StringContent
is an enum item.
#[macro_export]
macro_rules! from_str {
($json:expr) => {
StringContent(String::from($json))
}
}
which allows me to write code like
from_str!(r#"{
"appName": "Demo App",
"appVersion": "1.0",
"database": {
"host": "dev.database.com",
"port": 3000
}
}"#)
Now I want another macro from_json!
which allows me to do get rid of the r#""#
like so
from_json!({
"appName": "Demo App",
"appVersion": "1.0",
"database": {
"host": "dev.database.com",
"port": 3000
}
})
I've tried the following which does not seem to work
#[macro_export]
macro_rules! from_json {
($t:tt) => {
StringContent(String::from(concat!(r#"r#""#, stringify!($t), r#"""# , r#"#"#)))
}
}
How can I get from_json
to work?