1use proc_macro2::TokenStream;
2use quote::ToTokens;
3
4use crate::codegen::FromMetaImpl;
5use crate::options::{Core, ParseAttribute, ParseData};
6use crate::Result;
7
8pub struct FromMetaOptions {
9 base: Core,
10}
11
12impl FromMetaOptions {
13 pub fn new(di: &syn::DeriveInput) -> Result<Self> {
14 (FromMetaOptions {
15 base: Core::start(di)?,
16 })
17 .parse_attributes(&di.attrs)?
18 .parse_body(&di.data)
19 }
20}
21
22impl ParseAttribute for FromMetaOptions {
23 fn parse_nested(&mut self, mi: &syn::Meta) -> Result<()> {
24 self.base.parse_nested(mi)
25 }
26}
27
28impl ParseData for FromMetaOptions {
29 fn parse_variant(&mut self, variant: &syn::Variant) -> Result<()> {
30 self.base.parse_variant(variant)
31 }
32
33 fn parse_field(&mut self, field: &syn::Field) -> Result<()> {
34 self.base.parse_field(field)
35 }
36}
37
38impl<'a> From<&'a FromMetaOptions> for FromMetaImpl<'a> {
39 fn from(v: &'a FromMetaOptions) -> Self {
40 FromMetaImpl {
41 base: (&v.base).into(),
42 }
43 }
44}
45
46impl ToTokens for FromMetaOptions {
47 fn to_tokens(&self, tokens: &mut TokenStream) {
48 FromMetaImpl::from(self).to_tokens(tokens)
49 }
50}
51