blob: ac5357abe2a18b91f1a89fd174fcd798f8770ddc (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
#![feature(more_qualified_paths)]
mod foo_bar {
pub enum Example {
Example1 {},
Example2 {},
}
}
fn main() {
foo!(crate::foo_bar::Example, Example1);
let i1 = foo_bar::Example::Example1 {};
assert_eq!(i1.foo_example(), 1);
let i2 = foo_bar::Example::Example2 {};
assert_eq!(i2.foo_example(), 2);
}
#[macro_export]
macro_rules! foo {
($struct:path, $variant:ident) => {
impl $struct {
pub fn foo_example(&self) -> i32 {
match self {
<$struct>::$variant { .. } => 1,
_ => 2,
}
}
}
};
}
|