use crate::{
ast,
utils::duplicate_config_err,
};
#[derive(Debug, Default, PartialEq, Eq)]
pub struct StorageItemConfig {
derive: bool,
}
impl TryFrom<ast::AttributeArgs> for StorageItemConfig {
type Error = syn::Error;
fn try_from(args: ast::AttributeArgs) -> Result<Self, Self::Error> {
let mut derive: Option<syn::LitBool> = None;
for arg in args.into_iter() {
if arg.name().is_ident("derive") {
if let Some(lit_bool) = derive {
return Err(duplicate_config_err(
lit_bool,
arg,
"derive",
"storage item",
));
}
if let Some(lit_bool) = arg.value().and_then(ast::MetaValue::as_lit_bool)
{
derive = Some(lit_bool.clone())
} else {
return Err(format_err_spanned!(
arg,
"expected a bool literal value for `derive` ink! storage item configuration argument",
));
}
} else {
return Err(format_err_spanned!(
arg,
"encountered unknown or unsupported ink! storage item configuration argument",
));
}
}
Ok(StorageItemConfig {
derive: derive.map(|lit_bool| lit_bool.value).unwrap_or(true),
})
}
}
impl StorageItemConfig {
pub fn derive(&self) -> bool {
self.derive
}
}