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.
pub fn strip_serde_attrs(field: &Field) -> Field {
let mut field = field.clone();
field
.attrs
.retain(|attr| attr.path.segments.len() != 1 || attr.path.segments[0].ident != "serde");
field.attrs.retain(|attr| attr.path.is_ident("serde"));
field
}

View File

@ -29,13 +29,10 @@ impl Meta {
///
/// 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>> {
match &attr.path {
syn::Path { leading_colon: None, segments }
if segments.len() == 1 && segments[0].ident == "ruma_api" =>
{
if attr.path.is_ident("ruma_api") {
attr.parse_args().map(Some)
}
_ => Ok(None),
} else {
Ok(None)
}
}
}