mirror of
https://github.com/bevyengine/bevy
synced 2025-01-03 00:38:56 +00:00
ec30822517
A couple more uncontroversial changes extracted from #3886. * Enable full feature of syn It is necessary for the ItemFn and ItemTrait type. Currently it is indirectly enabled through the tracing dependency of bevy_utils, but this may no longer be the case in the future. * Remove unused function from bevy_macro_utils
33 lines
955 B
Rust
33 lines
955 B
Rust
use syn::DeriveInput;
|
|
|
|
use crate::symbol::Symbol;
|
|
|
|
pub fn parse_attrs(ast: &DeriveInput, attr_name: Symbol) -> syn::Result<Vec<syn::NestedMeta>> {
|
|
let mut list = Vec::new();
|
|
for attr in ast.attrs.iter().filter(|a| a.path == attr_name) {
|
|
match attr.parse_meta()? {
|
|
syn::Meta::List(meta) => list.extend(meta.nested.into_iter()),
|
|
other => {
|
|
return Err(syn::Error::new_spanned(
|
|
other,
|
|
format!("expected #[{}(...)]", attr_name),
|
|
))
|
|
}
|
|
}
|
|
}
|
|
Ok(list)
|
|
}
|
|
|
|
pub fn get_lit_str(attr_name: Symbol, lit: &syn::Lit) -> syn::Result<&syn::LitStr> {
|
|
if let syn::Lit::Str(lit) = lit {
|
|
Ok(lit)
|
|
} else {
|
|
Err(syn::Error::new_spanned(
|
|
lit,
|
|
format!(
|
|
"expected {} attribute to be a string: `{} = \"...\"`",
|
|
attr_name, attr_name
|
|
),
|
|
))
|
|
}
|
|
}
|