Change the fold_attrs attr parameter type to &[Attribute]

This commit is contained in:
TheAwiteb 2023-09-20 03:41:44 +03:00
parent c50513b6e4
commit 32371b77aa
No known key found for this signature in database
GPG key ID: ABF818BD15DC2D34
2 changed files with 5 additions and 4 deletions

View file

@ -8,20 +8,21 @@ use syn::{
};
pub(crate) fn fold_attrs<A, R>(
attrs: impl Iterator<Item = Attribute>,
attrs: &[Attribute],
filter: fn(&Attribute) -> bool,
parse: impl Fn(Attr) -> Result<R>,
init: A,
f: impl Fn(A, R) -> Result<A>,
) -> Result<A> {
attrs
.filter(filter)
.iter()
.filter(|&a| filter(a))
.flat_map(|attribute| {
let Some(key) = attribute.path.get_ident().cloned()
else { return vec![Err(compile_error_at("expected an ident", attribute.path.span()))] };
match (|input: ParseStream<'_>| Attrs::parse_with_key(input, key))
.parse(attribute.tokens.into())
.parse(attribute.tokens.clone().into())
{
Ok(ok) => ok.0.into_iter().map(&parse).collect(),
Err(err) => vec![Err(err.into())],

View file

@ -56,7 +56,7 @@ impl CommandAttrs {
use CommandAttrKind::*;
fold_attrs(
attributes.iter().cloned(),
attributes,
|attr| is_command_attribute(attr) || is_doc_comment(attr),
CommandAttr::parse,
Self {