I'm trying to complete Quiz #4 in the Rustlings exercises:
// Write a macro that passes the quiz! No hints this time, you can do it!
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_my_macro_world() {
assert_eq!(my_macro!("world!"), "Hello world!");
}
#[test]
fn test_my_macro_goodbye() {
assert_eq!(my_macro!("goodbye!"), "Hello goodbye!");
}
}
my macro looks like this:
#[macro_export]
macro_rules! my_macro {
(($val:expr), "world!") => {
println!("Hello world!");
};
(($val:expr), "goodbye!") => {
println!("Hello goodbye!");
};
}
This was patterned after the Declarative Macro section of the Rust Language Documentation. I get the following errors:
assert_eq!(my_macro!("world!"), "Hello world!");
| ^^^^^^^^^^ no rules expected this token in macro call
assert_eq!(my_macro!("goodbye!"), "Hello goodbye!");
| ^^^^^^^^^^ no rules expected this token in macro call
I cannot find a solution to this to make it compile. Help!