use darling::{FromDeriveInput, FromField, ast::Data};
use syn::{Generics, Ident, Type, Visibility};
#[derive(Debug, FromField)]
#[darling(attributes(cacheable_response))]
pub struct FieldAttrs {
pub ident: Option<Ident>,
pub ty: Type,
pub vis: Visibility,
#[darling(default)]
pub skip: bool,
}
#[derive(Debug, FromDeriveInput)]
#[darling(attributes(cacheable_response), supports(struct_named))]
pub struct Source {
pub ident: Ident,
pub generics: Generics,
pub data: Data<darling::util::Ignored, FieldAttrs>,
}
impl Source {
pub fn has_skipped_fields(&self) -> bool {
match &self.data {
Data::Struct(fields) => fields.iter().any(|f| f.skip),
_ => false,
}
}
pub fn fields(&self) -> impl Iterator<Item = &FieldAttrs> {
match &self.data {
Data::Struct(fields) => fields.iter(),
_ => unreachable!("only struct_named is supported"),
}
}
}