substrate-archive icon indicating copy to clipboard operation
substrate-archive copied to clipboard

Remove dynamic dispatch for `ReadOnlyDB` `iter()`

Open emostov opened this issue 3 years ago • 0 comments

We could get rid of the Box<dyn ...> here as well:

pub trait ReadOnlyDB: Send + Sync {
    /// Iterator type to be returned
    type Iter: Iterator<Item = KeyValuePair>;
    /// Read key/value pairs from the database
    fn get(&self, col: u32, key: &[u8]) -> Option<Vec<u8>>;
    /// Iterate over all blocks in the database
    fn iter(&self, col: u32) -> Self::Iter;

Unfortunately, kvdb_rocksdb uses impl Iterator as a return type which obfuscates the concrete iterator type it's returning, which breaks defining the associated type on the trait impl. This would be a small thing to fix as a separate PR later on if the signature is fixed upstream.

Relys on https://github.com/paritytech/parity-common/issues/437

Originally posted by @maciejhirsz in https://github.com/paritytech/substrate-archive/pull/108#discussion_r514096408

emostov avatar Oct 29 '20 18:10 emostov