0 | |
--- a/src/enum_discriminants.rs
|
1 | |
+++ b/src/enum_discriminants.rs
|
2 | |
@@ -2,7 +2,8 @@
|
3 | |
use syn;
|
4 | |
|
5 | |
use helpers::{
|
6 | |
- extract_list_metas, extract_meta, filter_metas, get_meta_ident, get_meta_list, unique_meta_list,
|
7 | |
+ eq_path_str, extract_list_metas, extract_meta, filter_metas, get_meta_ident, get_meta_list,
|
8 | |
+ unique_meta_list,
|
9 | |
};
|
10 | |
|
11 | |
pub fn enum_discriminants_inner(ast: &syn::DeriveInput) -> TokenStream {
|
12 | |
@@ -43,7 +44,9 @@
|
13 | |
// Pass through all other attributes
|
14 | |
let pass_though_attributes =
|
15 | |
filter_metas(discriminant_attrs.iter().map(|&m| m), |meta| match meta {
|
16 | |
- syn::Meta::List(ref metalist) => metalist.ident != "derive" && metalist.ident != "name",
|
17 | |
+ syn::Meta::List(ref metalist) => {
|
18 | |
+ !eq_path_str(&metalist.path, "derive") && !eq_path_str(&metalist.path, "name")
|
19 | |
+ }
|
20 | |
_ => true,
|
21 | |
})
|
22 | |
.map(|meta| quote! { #[ #meta ] })
|
23 | |
@@ -56,8 +59,8 @@
|
24 | |
|
25 | |
// Don't copy across the "strum" meta attribute.
|
26 | |
let attrs = variant.attrs.iter().filter(|attr| {
|
27 | |
- attr.interpret_meta().map_or(true, |meta| match meta {
|
28 | |
- syn::Meta::List(ref metalist) => metalist.ident != "strum",
|
29 | |
+ attr.parse_meta().ok().map_or(true, |meta| match meta {
|
30 | |
+ syn::Meta::List(ref metalist) => !eq_path_str(&metalist.path, "strum"),
|
31 | |
_ => true,
|
32 | |
})
|
33 | |
});
|
34 | |
--- a/src/enum_properties.rs
|
35 | |
+++ b/src/enum_properties.rs
|
36 | |
@@ -2,18 +2,18 @@
|
37 | |
use syn;
|
38 | |
use syn::Meta;
|
39 | |
|
40 | |
-use helpers::{extract_meta, is_disabled};
|
41 | |
+use helpers::{eq_path_str, extract_meta, is_disabled};
|
42 | |
|
43 | |
fn extract_properties(meta: &[Meta]) -> Vec<(&syn::Ident, &syn::Lit)> {
|
44 | |
use syn::{MetaList, MetaNameValue, NestedMeta};
|
45 | |
meta.iter()
|
46 | |
.filter_map(|meta| match *meta {
|
47 | |
Meta::List(MetaList {
|
48 | |
- ref ident,
|
49 | |
+ ref path,
|
50 | |
ref nested,
|
51 | |
..
|
52 | |
}) => {
|
53 | |
- if ident == "strum" {
|
54 | |
+ if eq_path_str(path, "strum") {
|
55 | |
Some(nested)
|
56 | |
} else {
|
57 | |
None
|
58 | |
@@ -24,11 +24,11 @@
|
59 | |
.flat_map(|prop| prop)
|
60 | |
.filter_map(|prop| match *prop {
|
61 | |
NestedMeta::Meta(Meta::List(MetaList {
|
62 | |
- ref ident,
|
63 | |
+ ref path,
|
64 | |
ref nested,
|
65 | |
..
|
66 | |
})) => {
|
67 | |
- if ident == "props" {
|
68 | |
+ if eq_path_str(path, "props") {
|
69 | |
Some(nested)
|
70 | |
} else {
|
71 | |
None
|
72 | |
@@ -40,8 +40,8 @@
|
73 | |
// Only look at key value pairs
|
74 | |
.filter_map(|prop| match *prop {
|
75 | |
NestedMeta::Meta(Meta::NameValue(MetaNameValue {
|
76 | |
- ref ident, ref lit, ..
|
77 | |
- })) => Some((ident, lit)),
|
78 | |
+ ref path, ref lit, ..
|
79 | |
+ })) => Some((&path.segments[0].ident, lit)),
|
80 | |
_ => None,
|
81 | |
})
|
82 | |
.collect()
|
83 | |
--- a/src/helpers.rs
|
84 | |
+++ b/src/helpers.rs
|
85 | |
@@ -1,12 +1,12 @@
|
86 | |
use heck::{CamelCase, KebabCase, MixedCase, ShoutySnakeCase, SnakeCase, TitleCase};
|
87 | |
-use syn::{Attribute, Ident, Meta, MetaList};
|
88 | |
+use syn::{Attribute, Ident, Meta, MetaList, Path};
|
89 | |
|
90 | |
use case_style::CaseStyle;
|
91 | |
|
92 | |
pub fn extract_meta(attrs: &[Attribute]) -> Vec<Meta> {
|
93 | |
attrs
|
94 | |
.iter()
|
95 | |
- .filter_map(|attribute| attribute.interpret_meta())
|
96 | |
+ .flat_map(|attribute| attribute.parse_meta())
|
97 | |
.collect()
|
98 | |
}
|
99 | |
|
100 | |
@@ -57,7 +57,7 @@
|
101 | |
where
|
102 | |
MetaIt: Iterator<Item = &'meta Meta>,
|
103 | |
{
|
104 | |
- filter_meta_lists(metas, move |metalist| metalist.ident == attr)
|
105 | |
+ filter_meta_lists(metas, move |metalist| eq_path_str(&metalist.path, attr))
|
106 | |
}
|
107 | |
|
108 | |
/// Returns the `MetaList` that matches the given name from the list of `Meta`s, or `None`.
|
109 | |
@@ -89,7 +89,7 @@
|
110 | |
/// Returns the `Ident` of the `Meta::Word`, or `None`.
|
111 | |
pub fn get_meta_ident<'meta>(meta: &'meta Meta) -> Option<&'meta Ident> {
|
112 | |
match *meta {
|
113 | |
- Meta::Word(ref ident) => Some(ident),
|
114 | |
+ Meta::Path(ref path) => Some(&path.segments[0].ident),
|
115 | |
_ => None,
|
116 | |
}
|
117 | |
}
|
118 | |
@@ -100,7 +100,7 @@
|
119 | |
// Get all the attributes with our tag on them.
|
120 | |
.filter_map(|meta| match *meta {
|
121 | |
Meta::List(ref metalist) => {
|
122 | |
- if metalist.ident == attr {
|
123 | |
+ if eq_path_str(&metalist.path, attr) {
|
124 | |
Some(&metalist.nested)
|
125 | |
} else {
|
126 | |
None
|
127 | |
@@ -112,11 +112,11 @@
|
128 | |
// Get all the inner elements as long as they start with ser.
|
129 | |
.filter_map(|meta| match *meta {
|
130 | |
NestedMeta::Meta(Meta::NameValue(MetaNameValue {
|
131 | |
- ref ident,
|
132 | |
+ ref path,
|
133 | |
lit: Lit::Str(ref s),
|
134 | |
..
|
135 | |
})) => {
|
136 | |
- if ident == prop {
|
137 | |
+ if eq_path_str(path, prop) {
|
138 | |
Some(s.value())
|
139 | |
} else {
|
140 | |
None
|
141 | |
@@ -160,3 +160,13 @@
|
142 | |
ident_string
|
143 | |
}
|
144 | |
}
|
145 | |
+
|
146 | |
+/// Checks whether the path is equal to the given string.
|
147 | |
+///
|
148 | |
+/// Returns `true` if they are same.
|
149 | |
+///
|
150 | |
+/// Note that the given string should be a single path segment.
|
151 | |
+/// In other words, it should not be multi-segment path like `a::b::c`.
|
152 | |
+pub fn eq_path_str(path: &Path, s: &str) -> bool {
|
153 | |
+ path.get_ident().map_or(false, |ident| ident == s)
|
154 | |
+}
|