Refactor attribute parsing to make it more extensible
This commit is contained in:
parent
b1ded882b7
commit
780c7286a6
4 changed files with 172 additions and 46 deletions
|
@ -1,5 +1,5 @@
|
|||
use super::*;
|
||||
use crate::attr::get_with_from_attrs;
|
||||
use crate::attr::Attrs;
|
||||
use serde_derive_internals::ast as serde_ast;
|
||||
use serde_derive_internals::Ctxt;
|
||||
|
||||
|
@ -56,7 +56,7 @@ impl<'a> FromSerde for Variant<'a> {
|
|||
style: serde.style,
|
||||
fields: Field::vec_from_serde(errors, serde.fields)?,
|
||||
original: serde.original,
|
||||
with: get_with_from_attrs(&serde.original.attrs, errors)?,
|
||||
attrs: Attrs::new(&serde.original.attrs, errors),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
@ -70,7 +70,7 @@ impl<'a> FromSerde for Field<'a> {
|
|||
serde_attrs: serde.attrs,
|
||||
ty: serde.ty,
|
||||
original: serde.original,
|
||||
with: get_with_from_attrs(&serde.original.attrs, errors)?,
|
||||
attrs: Attrs::new(&serde.original.attrs, errors),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
mod from_serde;
|
||||
|
||||
use crate::attr::{Attrs, WithAttr};
|
||||
use from_serde::FromSerde;
|
||||
use serde_derive_internals::ast as serde_ast;
|
||||
use serde_derive_internals::{Ctxt, Derive};
|
||||
|
@ -23,7 +24,7 @@ pub struct Variant<'a> {
|
|||
pub style: serde_ast::Style,
|
||||
pub fields: Vec<Field<'a>>,
|
||||
pub original: &'a syn::Variant,
|
||||
pub with: Option<syn::Type>,
|
||||
pub attrs: Attrs,
|
||||
}
|
||||
|
||||
pub struct Field<'a> {
|
||||
|
@ -31,7 +32,7 @@ pub struct Field<'a> {
|
|||
pub serde_attrs: serde_derive_internals::attr::Field,
|
||||
pub ty: &'a syn::Type,
|
||||
pub original: &'a syn::Field,
|
||||
pub with: Option<syn::Type>,
|
||||
pub attrs: Attrs,
|
||||
}
|
||||
|
||||
impl<'a> Container<'a> {
|
||||
|
@ -69,6 +70,10 @@ impl<'a> Field<'a> {
|
|||
}
|
||||
|
||||
pub fn type_for_schema(&self) -> &syn::Type {
|
||||
self.with.as_ref().unwrap_or(self.ty)
|
||||
match &self.attrs.with {
|
||||
None => self.ty,
|
||||
Some(WithAttr::Type(ty)) => ty,
|
||||
Some(WithAttr::_Function(_)) => todo!(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue