ruma-api-macros: Use syn::Path::is_ident

This commit is contained in:
Jonas Platte 2019-11-19 20:38:27 +01:00
parent f0e724d391
commit 8c898f3766
No known key found for this signature in database
GPG Key ID: 7D261D771D915378
2 changed files with 5 additions and 10 deletions

View File

@ -20,9 +20,7 @@ use self::{metadata::Metadata, request::Request, response::Response};
/// Removes `serde` attributes from struct fields. /// Removes `serde` attributes from struct fields.
pub fn strip_serde_attrs(field: &Field) -> Field { pub fn strip_serde_attrs(field: &Field) -> Field {
let mut field = field.clone(); let mut field = field.clone();
field field.attrs.retain(|attr| attr.path.is_ident("serde"));
.attrs
.retain(|attr| attr.path.segments.len() != 1 || attr.path.segments[0].ident != "serde");
field field
} }

View File

@ -29,13 +29,10 @@ impl Meta {
/// ///
/// Panics if the given attribute is a ruma_api attribute, but fails to parse. /// Panics if the given attribute is a ruma_api attribute, but fails to parse.
pub fn from_attribute(attr: &syn::Attribute) -> syn::Result<Option<Self>> { pub fn from_attribute(attr: &syn::Attribute) -> syn::Result<Option<Self>> {
match &attr.path { if attr.path.is_ident("ruma_api") {
syn::Path { leading_colon: None, segments }
if segments.len() == 1 && segments[0].ident == "ruma_api" =>
{
attr.parse_args().map(Some) attr.parse_args().map(Some)
} } else {
_ => Ok(None), Ok(None)
} }
} }
} }