Debian Codegraph @

tests/mac_attrs.rs

raw symbols SCIP
1 /*
2 Copyright ⓒ 2016 macro-attr contributors.
3
4 Licensed under the MIT license (see LICENSE or <http://opensource.org
5 /licenses/MIT>) or the Apache License, Version 2.0 (see LICENSE of
6 <http://www.apache.org/licenses/LICENSE-2.0>), at your option. All
7 files in the project carrying such notice may not be copied, modified,
8 or distributed except according to those terms.
9 */
10 #[macro_use] extern crate macro_attr;
11
12 macro_rules! Name {
13 (
14 ()
15 struct $name:ident $($_tail:tt)*
16 ) => {
17 impl $name {
18 pub fn name() -> &'static str {
19 stringify!($name)
20 }
21 }
22 };
23 }
24
25 macro_rules! remove_body {
26 (
27 (),
28 then $cb:tt,
29 $(#[$($attrs:tt)*])*
30 struct $name:ident $($_tail:tt)*
31 ) => {
32 macro_attr_callback! {
33 $cb,
34 $(#[$($attrs)*])*
35 struct $name;
36 }
37 };
38 }
39
40 macro_rules! use_secret_alias {
41 (
42 ($name:ident),
43 then $cb:tt,
44 $(#[$($attrs:tt)*])*
45 struct $_old_name:ident $($tail:tt)*
46 ) => {
47 macro_attr_callback! {
48 $cb,
49 $(#[$($attrs)*])*
50 struct $name $($tail)*
51 }
52 };
53 }
54
55 macro_attr! {
56 #[derive(Debug, Name!)]
57 #[remove_body!]
58 #[use_secret_alias!(Alucard)]
59 struct Dracula {
60 pub vulnerabilities: Vec<Vulnerability>,
61 }
62 }
63
64 #[test]
65 fn test_mac_attrs() {
66 assert_eq!(format!("{:?}", Alucard), "Alucard");
67 assert_eq!(Alucard::name(), "Alucard");
68 }