Skip to content

Commit

Permalink
Minor refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
cyqsimon committed Oct 8, 2024
1 parent 406ec38 commit b8d6ae4
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions documented-macros/src/config/derive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,16 +86,15 @@ pub fn get_customisations_from_attrs(
})
.collect::<Result<Vec<_>, _>>()?;

let customise_attr = match customise_attrs.len() {
0 => return Ok(None),
1 => customise_attrs[0].clone(),
_ => {
let mut it = customise_attrs.iter();
let customise_attr = match customise_attrs[..] {
[] => return Ok(None),
[attr] => attr.clone(),
[first, ref rest @ ..] => {
let initial_error = Error::new(
it.next().unwrap().span(),
first.span(),
format!("{attr_name} can only be declared once"),
);
let final_error = it.fold(initial_error, |mut err, declaration| {
let final_error = rest.iter().fold(initial_error, |mut err, declaration| {
err.combine(Error::new(declaration.span(), "Duplicate declaration here"));
err
});
Expand Down

0 comments on commit b8d6ae4

Please sign in to comment.