Skip to content

Instantly share code, notes, and snippets.

@tomassedovic
Last active December 26, 2015 21:38
Show Gist options
  • Save tomassedovic/7217029 to your computer and use it in GitHub Desktop.
Save tomassedovic/7217029 to your computer and use it in GitHub Desktop.
#[feature(macro_rules)];
struct Object;
impl Object {
pub fn is_blue(&self) -> bool {true}
pub fn is_small(&self) -> bool {true}
pub fn is_heavy(&self) -> bool {true}
}
macro_rules! is(
($object:ident, $($property:ident),+) => (
($($object.concat_idents!(is_, $property))&&*)
)
)
fn main() {
let obj = Object;
// should be expanded to: (obj.is_blue() && obj.is_small() && obj.is_heavy())
if is!(obj, blue, small, heavy) {}
// macros.rs:14:32: 14:33 error: expected one of `,`, `)` but found `!`
// macros.rs:14 ($($object.concat_idents!(is_, $property)),*)
// ^
// task '<unnamed>' failed at 'explicit failure', /home/thomas/opt/code/rust/src/libsyntax/diagnostic.rs:75
// task '<unnamed>' failed at 'explicit failure', /home/thomas/opt/code/rust/src/librustc/rustc.rs:396
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment