Path: blob/main/crates/bevy_reflect/derive/src/reflect_opaque.rs
6599 views
use crate::{1container_attributes::ContainerAttributes, derive_data::ReflectTraitToImpl,2type_path::CustomPathDef,3};4use syn::{parenthesized, parse::ParseStream, token::Paren, Attribute, Generics, Path};56/// A struct used to define a simple reflection-opaque types (including primitives).7///8/// This takes the form:9///10/// ```ignore (Method expecting TokenStream is better represented with raw tokens)11/// // Standard12/// ::my_crate::foo::Bar(TraitA, TraitB)13///14/// // With generics15/// ::my_crate::foo::Bar<T1: Bar, T2>(TraitA, TraitB)16///17/// // With generics and where clause18/// ::my_crate::foo::Bar<T1, T2> where T1: Bar (TraitA, TraitB)19///20/// // With a custom path (not with impl_from_reflect_opaque)21/// (in my_crate::bar) Bar(TraitA, TraitB)22/// ```23pub(crate) struct ReflectOpaqueDef {24#[cfg_attr(25not(feature = "documentation"),26expect(27dead_code,28reason = "The is used when the `documentation` feature is enabled.",29)30)]31pub attrs: Vec<Attribute>,32pub type_path: Path,33pub generics: Generics,34pub traits: Option<ContainerAttributes>,35pub custom_path: Option<CustomPathDef>,36}3738impl ReflectOpaqueDef {39pub fn parse_reflect(input: ParseStream) -> syn::Result<Self> {40Self::parse(input, ReflectTraitToImpl::Reflect)41}4243pub fn parse_from_reflect(input: ParseStream) -> syn::Result<Self> {44Self::parse(input, ReflectTraitToImpl::FromReflect)45}4647fn parse(input: ParseStream, trait_: ReflectTraitToImpl) -> syn::Result<Self> {48let attrs = input.call(Attribute::parse_outer)?;4950let custom_path = CustomPathDef::parse_parenthesized(input)?;5152let type_path = Path::parse_mod_style(input)?;53let mut generics = input.parse::<Generics>()?;54generics.where_clause = input.parse()?;5556let mut traits = None;57if input.peek(Paren) {58let content;59parenthesized!(content in input);60traits = Some({61let mut attrs = ContainerAttributes::default();62attrs.parse_terminated(&content, trait_)?;63attrs64});65}66Ok(Self {67attrs,68type_path,69generics,70traits,71custom_path,72})73}74}757677