@@ -9,17 +9,13 @@ use crate::attrs::common::{ItemAttributes, ItemType};
9
9
/// Data stored in this struct is validated using darling's `and_then` attribute.
10
10
/// During darlings validation, it is not possible to validate that action
11
11
/// versions match up with declared versions on the container. This validation
12
- /// can be done using the associated [`FieldAttributes ::validate_versions`]
12
+ /// can be done using the associated [`ValidateVersions ::validate_versions`][1 ]
13
13
/// function.
14
14
///
15
- /// ### Field Rules
15
+ /// Rules shared across fields and variants can be found [here][2].
16
16
///
17
- /// - A field can only ever be added once at most. A field not marked as 'added'
18
- /// is part of the struct in every version until renamed or deprecated.
19
- /// - A field can be renamed many times. That's why renames are stored in a
20
- /// [`Vec`].
21
- /// - A field can only be deprecated once. A field not marked as 'deprecated'
22
- /// will be included up until the latest version.
17
+ /// [1]: crate::attrs::common::ValidateVersions::validate_versions
18
+ /// [2]: crate::attrs::common::ItemAttributes
23
19
#[ derive( Debug , FromField ) ]
24
20
#[ darling(
25
21
attributes( versioned) ,
@@ -37,23 +33,18 @@ pub(crate) struct FieldAttributes {
37
33
}
38
34
39
35
impl FieldAttributes {
40
- // NOTE (@Techassi): Ideally, these validations should be moved to the
41
- // ItemAttributes impl, because common validation like action combinations
42
- // and action order can be validated without taking the type of attribute
43
- // into account (field vs variant). However, we would loose access to the
44
- // field / variant ident and as such, cannot display the error directly on
45
- // the affected field / variant. This is a significant decrease in DX.
46
- // See https://github.com/TedDriggs/darling/discussions/294
47
-
48
36
/// This associated function is called by darling (see and_then attribute)
49
37
/// after it successfully parsed the attribute. This allows custom
50
38
/// validation of the attribute which extends the validation already in
51
39
/// place by darling.
52
40
///
53
41
/// Internally, it calls out to other specialized validation functions.
54
42
fn validate ( self ) -> Result < Self , Error > {
55
- self . common
56
- . validate ( self . ident . as_ref ( ) . unwrap ( ) , & ItemType :: Field ) ?;
43
+ let ident = self
44
+ . ident
45
+ . as_ref ( )
46
+ . expect ( "internal error: field must have an ident" ) ;
47
+ self . common . validate ( ident, & ItemType :: Field ) ?;
57
48
58
49
Ok ( self )
59
50
}
0 commit comments