bevy_reflect_derive/
custom_attributes.rs1use proc_macro2::TokenStream;
2use quote::quote;
3use syn::{parse::ParseStream, Expr, Path, Token};
4
5#[derive(Default, Clone)]
6pub(crate) struct CustomAttributes {
7 attributes: Vec<Expr>,
8}
9
10impl CustomAttributes {
11 pub fn to_tokens(&self, bevy_reflect_path: &Path) -> TokenStream {
13 let attributes = self.attributes.iter().map(|value| {
14 quote! {
15 .with_attribute(#value)
16 }
17 });
18
19 quote! {
20 #bevy_reflect_path::attributes::CustomAttributes::default()
21 #(#attributes)*
22 }
23 }
24
25 pub fn push(&mut self, value: Expr) -> syn::Result<()> {
27 self.attributes.push(value);
28 Ok(())
29 }
30
31 pub fn parse_custom_attribute(&mut self, input: ParseStream) -> syn::Result<()> {
38 input.parse::<Token![@]>()?;
39 self.push(input.parse()?)
40 }
41}