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
Expose from_expr option when deriving FromMeta (#370)
* Add from_expr option for FromMeta
This rounds out the ability to make structs that accept custom short-forms without having to hand implement FromMeta.
Fixes#369
* Fix: Don't consider skipped variants for from_expr validation
Copy file name to clipboardExpand all lines: CHANGELOG.md
+1Lines changed: 1 addition & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,6 +4,7 @@
4
4
5
5
- Keep parsing the body and type params even if there are errors from parsing attributes. [#7](https://github.com/TedDriggs/darling/issues/325)
6
6
- Support `#[darling(with = ...)]` on the `generics` field when deriving `FromDeriveInput`.
7
+
- Add `#[darling(from_expr = ...)]` when deriving `FromMeta` to support overriding the key-value form [#369](https://github.com/TedDriggs/darling/issues/369)
@@ -113,6 +122,12 @@ impl ParseData for FromMetaOptions {
113
122
errors.push(Error::custom("`from_word` cannot be used on newtype structs because the implementation is entirely delegated to the inner type").with_span(from_word));
114
123
}
115
124
}
125
+
126
+
ifletSome(from_expr) = &self.from_expr{
127
+
if data.is_newtype(){
128
+
errors.push(Error::custom("`from_expr` cannot be used on newtype structs because the implementation is entirely delegated to the inner type").with_span(from_expr));
129
+
}
130
+
}
116
131
}
117
132
Data::Enum(ref data) => {
118
133
let word_variants:Vec<_> = data
@@ -140,6 +155,15 @@ impl ParseData for FromMetaOptions {
140
155
);
141
156
}
142
157
}
158
+
159
+
ifletSome(from_expr) = &self.from_expr{
160
+
if data.iter().any(|v| v.is_unit_variant() && !v.is_skipped()){
161
+
errors.push(
162
+
Error::custom("`from_expr` cannot be used on enums with non-skipped unit variants because it conflicts with the generated impl")
163
+
.with_span(from_expr),
164
+
);
165
+
}
166
+
}
143
167
}
144
168
}
145
169
}
@@ -151,6 +175,7 @@ impl<'a> From<&'a FromMetaOptions> for FromMetaImpl<'a> {
0 commit comments