use {deluxe::*, syn::spanned::*};
#[derive(Clone, ExtractAttributes)]
#[deluxe(attributes(resolve))]
pub struct FieldAttribute {
pub key: Option<syn::Expr>,
#[deluxe(default)]
pub required: bool,
#[deluxe(default)]
pub ignore_null: bool,
pub null: Option<syn::Expr>,
#[deluxe(default)]
pub single: bool,
#[deluxe(default)]
pub other_keys: bool,
#[deluxe(default)]
pub annotations: bool,
}
impl FieldAttribute {
pub fn is_annotations(&self, field: &syn::Field) -> syn::Result<bool> {
if self.annotations {
if self.key.is_some()
|| self.required
|| self.ignore_null
|| self.null.is_some()
|| self.single
|| self.other_keys
{
return Err(syn::Error::new(
field.span(),
"`resolve` attribute: can't specify other flags with `annotations`",
));
}
Ok(true)
} else {
Ok(false)
}
}
}