Skip to content

Commit

Permalink
Style and docs improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
davidsemakula committed Jan 19, 2024
1 parent 03d781a commit e27d2f7
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 20 deletions.
31 changes: 12 additions & 19 deletions core/src/options/from_meta.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,27 +37,20 @@ impl ParseData for FromMetaOptions {
}

fn validate_body(&self, errors: &mut Accumulator) {
match self.base.data {
Data::Enum(ref data) => {
// Adds errors for duplicate `#[darling(word)]` annotations across all variants.
let word_variants: Vec<_> = data
.iter()
.filter(|variant| variant.word.is_some())
.collect();
if word_variants.len() > 1 {
for variant in word_variants {
if let Some(word) = variant.word {
errors.push(
Error::custom(
"`#[darling(word)]` can only be applied to one variant",
)
.with_span(&word.span()),
);
}
}
if let Data::Enum(ref data) = self.base.data {
// Adds errors for duplicate `#[darling(word)]` annotations across all variants.
let word_variants: Vec<_> = data
.iter()
.filter_map(|variant| variant.word.as_ref())
.collect();
if word_variants.len() > 1 {
for word in word_variants {
errors.push(
Error::custom("`#[darling(word)]` can only be applied to one variant")
.with_span(&word.span()),
);
}
}
Data::Struct(_) => (),
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions core/src/options/input_variant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ pub struct InputVariant {
attr_name: Option<String>,
data: Fields<InputField>,
skip: Option<bool>,
/// Whether or not the variant should be used to create an instance for
/// `FromMeta::from_word`.
pub word: Option<SpannedValue<bool>>,
/// Whether or not unknown fields are acceptable in this
allow_unknown_fields: Option<bool>,
Expand Down
2 changes: 1 addition & 1 deletion core/src/options/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ pub trait ParseData: Sized {
}

/// Perform validation checks that require data from more than one field or variant.
/// This default implementation is essentially a noop.
/// The default implementation does no validations.
/// Implementors can override this method as appropriate for their use-case.
#[allow(unused_variables)]
fn validate_body(&self, errors: &mut Accumulator) {}
Expand Down

0 comments on commit e27d2f7

Please sign in to comment.