Skip to content

Replace Cow with an associated type in ReadOps::get() method in storage abstraction #658

Open
@TheQuantumPhysicist

Description

@TheQuantumPhysicist

The get() method used to return a slice &[u8], but that's very difficult to guarantee to work for all libraries. Usually key-value stores offer such a nice interface where the returned value within a transaction can be a slice directly read from the database. However, SQL data cannot do that. Hence, we need to return things by value for them. This is why #652 happened. We now return a Cow object.

A better way to solve this problem would be by using an associated type in ReadOps, where the return type is defined in the trait's implementation. Something in the form:

pub trait ReadOps: for<'i> PrefixIter<'i> {
    type DataType: AsRef<[u8]>;
    /// Get value associated with given key.
    fn get(&self, idx: DbIndex, key: &[u8]) -> crate::Result<Option<Self::DataType>>;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requeststorageEverything related to storage, whether it's blockchain, wallet or otherwise

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions