You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This avoids the issues of the proposed PR by having both the inherent
method *and* the trait, and by using a different method name for the trait.
This is less than ideal, but solves the backwards compatibility issues well
enough.
Closes#32.
Copy file name to clipboardExpand all lines: enum_derive/src/iter_variants.rs
+56Lines changed: 56 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -20,6 +20,8 @@ macro_attr! {
20
20
21
21
Derives a `$name::iter_variants() -> $itername` method. The generated `$itername` type implements `Iterator<Item=$name>`, and yields each of the enumeration's variants. This can only be used on an enum comprised on unitary variants.
22
22
23
+
It also derives an implementation of the `IterVariants` trait.
24
+
23
25
# Example
24
26
25
27
```rust
@@ -32,8 +34,11 @@ macro_attr! {
32
34
}
33
35
34
36
# fn main() {
37
+
use enum_derive::iter_variants::IterVariants;
38
+
35
39
let names: Vec<Cheese> = Cheese::iter_variants().collect();
Derives a `$name::iter_variant_names() -> $itername` method. The generated `$itername` type implements `Iterator<Item=&'static str>`, and yields the name of each of the enumeration's variants. This can only be used on an enum comprised on unitary variants.
189
212
213
+
It also derives an implementation of the `IterVariantNames` trait.
214
+
190
215
# Example
191
216
192
217
```rust
@@ -198,8 +223,11 @@ macro_attr! {
198
223
}
199
224
200
225
# fn main() {
226
+
use enum_derive::iter_variants::IterVariantNames;
227
+
201
228
let names: Vec<&str> = Currency::iter_variant_names().collect();
0 commit comments