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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
/*!
* Implementation of common traits for enums and variants.
*/
///
/// Generate an implementation of the standard [From] trait to construct a new enum with
/// the provided variant value.
///
/// ## Forms
///
/// ### `impl_from_for_variant!(Type => Enum, Variant)`
///
/// This form generates a [`From`] `Type` implementation for `Enum`.
///
/// The following — commented line and following implementation — are therefore equivalent:
///
/// ```rust
/// # pub struct Address(String);
/// pub enum TypedAddress {
/// Home(Address),
/// }
/// // impl_from_for_variant!(Address => TypedAddress, Home);
///
/// impl From<Address> for TypedAddress {
/// fn from(value: Address) -> Self {
/// Self::Home(value)
/// }
/// }
/// ```
///
/// ### `impl_from_for_variant!(into Type => Enum, Variant)`
///
/// This form generates a [`From`] `Type` implementation for `Enum`.
///
/// * The type of the generic parameter to `From` is the trait-bound type `T: Into<Type>`
/// rather than simply `Type` for flexibility.
///
/// The following — commented line and following implementation — are therefore equivalent:
///
/// ```rust
/// # pub struct Address(String);
/// pub enum TypedAddress {
/// Home(Address),
/// }
/// // impl_from_for_variant!(into Address => TypedAddress, Home);
///
/// impl<T: Into<Address>> From<T> for TypedAddress {
/// fn from(value: T) -> Self {
/// Self::Home(value.into())
/// }
/// }
/// ```
///
///
/// Generate an implementation for the enumeration of a method that delegates the to the same named
/// method with the same parameters for the value on each variant.
///
/// ## Forms
///
/// ### `impl_delegate_for_all!(Enum [ ( Variant ),* ] => vis Name [ -> Type ]`
///
/// This form generates a simple delegate method implementation for `Enum`.
///
/// ```rust
/// # pub struct Address(String);
/// # impl Address { pub fn to_string(&self) -> String { String::new() } }
/// pub enum TypedAddress {
/// Home(Address),
/// UnParsed(String),
/// XRef(u64),
/// }
/// // impl_delegate_for_all!(TypedAddress [ Home, unParsed, XRef ] => pub to_string -> String);
///
/// impl TypedAddress {
/// pub fn to_string(&self) -> String {
/// match self {
/// Self::Home(value) => value.to_string(),
/// Self::UnParsed(value) => value.to_string(),
/// Self::XRef(value) => value.to_string(),
/// }
/// }
/// }
/// ```
///
/// ### `impl_delegate_for_all!(Enum [ ( Variant ),* ] => vis Name ( (param: type),+ ) [ -> Type ]`
///
/// TBD
///
}
}
};
}
// ------------------------------------------------------------------------------------------------
// Re-export macros
// ------------------------------------------------------------------------------------------------
pub use crate::;