Here is an example implementation for an enum. This would lend itself very well to a derive macro.
/// Unique addresses
#[derive(Copy, Display, FromPrimitive)]
#[cw_serde]
pub enum ConfigUnique {
PriceOracle,
Market,
InterestModel,
WarChest,
Governance,
AdminDoubleSig,
AdminTripleSig,
Owner,
}
impl<'a> PrimaryKey<'a> for ConfigUnique {
type Prefix = ();
type SubPrefix = ();
type Suffix = Self;
type SuperSuffix = Self;
fn key(&self) -> Vec<Key> {
vec![Key::Val8([*self as u8])]
}
}
impl KeyDeserialize for ConfigUnique {
type Output = ConfigUnique;
#[inline(always)]
fn from_vec(value: Vec<u8>) -> StdResult<Self::Output> {
FromPrimitive::from_u8(value[0]).ok_or_else(|| StdError::generic_err("Invalid ConfigUnique"))
}
}