I wrote a macro for sym-linking files. At first I had just the first pattern, but then thought that it would be nice not to have to write "&format!" all the time.
So with these patterns:
macro_rules! syml {
($a:expr, $b:expr) => {
Command::new("ln").args(&["-s", $a, $b])
};
( ($a:expr, $($x:expr),+), ($b:expr, $($y:expr),+) ) => {
Command::new("ln").args(&["-s", &format!($a, $($x),+), &format!($b, $($y),+)])
}
}
I want to match these cases:
syml!("from", "to");
syml!(("{}", from), "to");
syml!("from", ("{}", to));
syml!(("{}", from), ("{}", to));
syml!(("{}{}", from, here), ("{}{}", to, there));
But so far every time only the first pattern is matched, so I'm getting mismatched types errors like expected reference, found tuple.
I don't understand why, even for the last two example cases, it tries to match the first pattern and not the second.
$a:exprand (2) I believe the patterns are tried in order... have you tried putting the more specific pattern first? - Matthieu M.symlinkfunction. - Francis Gagné