mirror of
https://github.com/serde-rs/serde.git
synced 2025-10-02 07:21:12 +00:00
Simplify finding of repr(packed) attributes
This commit is contained in:
parent
548eb8f667
commit
da8d6f678e
@ -593,25 +593,15 @@ impl Container {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
use proc_macro2::Delimiter;
|
let mut is_packed = false;
|
||||||
let is_packed = item.attrs.iter().any(|attr| match attr.style {
|
for attr in &item.attrs {
|
||||||
syn::AttrStyle::Outer => {
|
if attr.path.is_ident("repr") {
|
||||||
attr.path
|
let _ = attr.parse_args_with(|input: ParseStream| {
|
||||||
.get_ident()
|
is_packed |= input.parse::<Ident>()? == "packed";
|
||||||
.map_or(false, |ident| *ident == "repr")
|
Ok(())
|
||||||
&& syn::parse2::<Group>(attr.tokens.clone())
|
|
||||||
.ok()
|
|
||||||
.filter(|g| g.delimiter() == Delimiter::Parenthesis)
|
|
||||||
.map(|g| g.stream().to_string())
|
|
||||||
.map_or(false, |repr| {
|
|
||||||
let repr = repr.trim();
|
|
||||||
repr == "packed"
|
|
||||||
|| repr.starts_with("packed(")
|
|
||||||
|| repr.starts_with("packed ")
|
|
||||||
})
|
|
||||||
}
|
|
||||||
_ => false,
|
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Container {
|
Container {
|
||||||
name: Name::from_attrs(unraw(&item.ident), ser_name, de_name, None),
|
name: Name::from_attrs(unraw(&item.ident), ser_name, de_name, None),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user