use crate::container_attributes::ContainerAttributes;
use crate::derive_data::ReflectTraitToImpl;
use crate::type_path::CustomPathDef;
use syn::parse::ParseStream;
use syn::token::Paren;
use syn::{parenthesized, Attribute, Generics, Path};
pub(crate) struct ReflectValueDef {
#[allow(dead_code)]
pub attrs: Vec<Attribute>,
pub type_path: Path,
pub generics: Generics,
pub traits: Option<ContainerAttributes>,
pub custom_path: Option<CustomPathDef>,
}
impl ReflectValueDef {
pub fn parse_reflect(input: ParseStream) -> syn::Result<Self> {
Self::parse(input, ReflectTraitToImpl::Reflect)
}
pub fn parse_from_reflect(input: ParseStream) -> syn::Result<Self> {
Self::parse(input, ReflectTraitToImpl::FromReflect)
}
fn parse(input: ParseStream, trait_: ReflectTraitToImpl) -> syn::Result<Self> {
let attrs = input.call(Attribute::parse_outer)?;
let custom_path = CustomPathDef::parse_parenthesized(input)?;
let type_path = Path::parse_mod_style(input)?;
let mut generics = input.parse::<Generics>()?;
generics.where_clause = input.parse()?;
let mut traits = None;
if input.peek(Paren) {
let content;
parenthesized!(content in input);
traits = Some(ContainerAttributes::parse_terminated(&content, trait_)?);
}
Ok(ReflectValueDef {
attrs,
type_path,
generics,
traits,
custom_path,
})
}
}