Skip to content

KeyDeserialize trait is private making custom keys and generics over keys not possible. #691

@0xekez

Description

@0xekez

The KeyDeserialize trait which is required for a type that would like to be a key for a Map is private in the cw_storage_plus::de module. This makes implementing custom map keys and functions that are generic over the map key type not possible.

For example, a generic function which lists all of the keys in a Map can't be implemented because the trait is private:

fn list_items<'a, K, V>(
    deps: Deps,
    map: Map<K, V>,
    start_at: Option<K>,
    limit: Option<u64>,
) -> StdResult<Vec<K>>
where
    K: cw_storage_plus::Bounder<'a>
        + cw_storage_plus::PrimaryKey<'a>
        + cw_storage_plus::de::KeyDeserialize,
    V: serde::de::DeserializeOwned + serde::Serialize,
{
    let items = map.keys(
        deps.storage,
        start_at.map(Bound::inclusive),
        None,
        cosmwasm_std::Order::Descending,
    );
    match limit {
        Some(limit) => Ok(items.take(limit as usize).collect::<Result<Vec<K>, _>>()?),
        None => Ok(items.collect::<Result<Vec<K>, _>>()?),
    }
}

Would be really cool to be able to do this. :)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions