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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
//! # Custom Attrs
//!
//! A library that allows you to configure values specific to each variants of an enum.
//!
//! ## Features
//! - Optional attributes
//! - Default values
//!
//! ## Examples
//!
//! ```
//! use custom_attrs::CustomAttrs;
//!
//! // ...
//!
//! #[derive(CustomAttrs)]
//!
//! // set the attributes
//! #[attr(pub a: usize)]
//! #[attr(b: Option<usize>)] // attributes can be optional
//! #[attr(c: &'static str = "Hello world!")] // and can also have default values
//! enum Enum {
//! #[attr(a = 5)]
//! #[attr(b = 3)]
//! Variant1,
//!
//! #[attr(a = 3)]
//! #[attr(c = "Hello again !")]
//! Variant2,
//! }
//!
//! ```
//!
//! See the examples directory for more details.
//!
//! # License
//!
//! Licensed under the MIT license.
use TokenStream;
use proc_macro_error;
use DeriveInput;
/// The main trait of the library.
///
/// ## Examples
///
/// ```
/// use custom_attrs::CustomAttrs;
///
/// // ...
///
/// #[derive(CustomAttrs)]
///
/// // set the attributes
/// #[attr(pub a: usize)]
/// #[attr(b: Option<usize>)] // attributes can be optional
/// #[attr(c: &'static str = "Hello world!")] // and can also have default values
/// enum Enum {
/// #[attr(a = 5)]
/// #[attr(b = 3)]
/// Variant1,
///
/// #[attr(a = 3)]
/// #[attr(c = "Hello again !")]
/// Variant2,
/// }
///
/// fn main() {
/// let a = Enum::Variant1.get_a();
/// }
/// ```
///
/// See the examples directory for more details.