CosmWasm / CosmWasm/cw-storage-plus
Create PrimaryKey, etc., derive macro for enums, maybe some other simple types.
- Dominant language
- Rust
- Stars
- 51
- Forks
- 34
- PR merge metrics
- No merged PRs in 30d
Description
Here is an example implementation for an enum. This would lend itself very well to a derive macro.
```rust
/// 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 {
vec![Key::Val8([*self as u8])]
}
}
impl KeyDeserialize for ConfigUnique {
type Output = ConfigUnique;
#[inline(always)]
fn from_vec(value: Vec) -> StdResult {
FromPrimitive::from_u8(value[0]).ok_or_else(|| StdError::generic_err("Invalid ConfigUnique"))
}
}
```
Contributor guide
No contributing guide indexed for this repository
Research direction
Start from the enum implementation in the issue and inspect the existing PrimaryKey and KeyDeserialize traits and their current implementations. Define the derive macro's supported types and behavior, then verify that it generates equivalent key and deserialization implementations for the shown enum and any agreed simple types.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- databases
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100