How to write a macro in Rust to match any element in a set?
问题 In C, I'm used to having: if (ELEM(value, a, b, c)) { ... } which is a macro with a variable number of arguments to avoid typing out if (value == a || value == b || value == c) { ... } A C example can be seen in Varargs `ELEM` macro for use with C. Is this possible in Rust? I assume it would use match . If so, how would variadic arguments be used to achieve this? 回答1: macro_rules! cmp { // Hack for Rust v1.11 and prior. (@as_expr $e:expr) => { $e }; ($lhs:expr, $cmp:tt any $($rhss:expr),*) =>