Skip to main content

Database

Trait Database 

Source
pub trait Database<H: Clone>: Send + Sync {
    // Required methods
    fn get(&self, col: ColumnId, key: &[u8]) -> Option<Vec<u8>>;
    fn lookup(&self, hash: &H) -> Option<Vec<u8>>;

    // Provided methods
    fn commit(&self, transaction: Transaction<H>) -> Result<()> { ... }
    fn commit_ref<'a>(
        &self,
        transaction: &mut dyn Iterator<Item = ChangeRef<'a, H>>,
    ) -> Result<()> { ... }
    fn with_get(&self, col: ColumnId, key: &[u8], f: &mut dyn FnMut(&[u8])) { ... }
    fn set(&self, col: ColumnId, key: &[u8], value: &[u8]) -> Result<()> { ... }
    fn remove(&self, col: ColumnId, key: &[u8]) -> Result<()> { ... }
    fn with_lookup(&self, hash: &H, f: &mut dyn FnMut(&[u8])) { ... }
    fn store(&self, hash: &H, preimage: &[u8]) -> Result<()> { ... }
    fn release(&self, hash: &H) -> Result<()> { ... }
}

Required Methods§

Source

fn get(&self, col: ColumnId, key: &[u8]) -> Option<Vec<u8>>

Retrieve the value previously stored against key or None if key is not currently in the database.

Source

fn lookup(&self, hash: &H) -> Option<Vec<u8>>

Retrieve the first preimage previously stored for hash or None if no preimage is currently stored.

Provided Methods§

Source

fn commit(&self, transaction: Transaction<H>) -> Result<()>

Commit the transaction to the database atomically. Any further calls to get or lookup will reflect the new state.

Source

fn commit_ref<'a>( &self, transaction: &mut dyn Iterator<Item = ChangeRef<'a, H>>, ) -> Result<()>

Commit the transaction to the database atomically. Any further calls to get or lookup will reflect the new state.

Source

fn with_get(&self, col: ColumnId, key: &[u8], f: &mut dyn FnMut(&[u8]))

Call f with the value previously stored against key.

This may be faster than get since it doesn’t allocate. Use with_get helper function if you need f to return a value from f

Source

fn set(&self, col: ColumnId, key: &[u8], value: &[u8]) -> Result<()>

Set the value of key in col to value, replacing anything that is there currently.

Source

fn remove(&self, col: ColumnId, key: &[u8]) -> Result<()>

Remove the value of key in col.

Source

fn with_lookup(&self, hash: &H, f: &mut dyn FnMut(&[u8]))

Call f with the preimage stored for hash and return the result, or None if no preimage is currently stored.

This may be faster than lookup since it doesn’t allocate. Use with_lookup helper function if you need f to return a value from f

Source

fn store(&self, hash: &H, preimage: &[u8]) -> Result<()>

Store the preimage of hash into the database, so that it may be looked up later with Database::lookup. This may be called multiple times, but Database::lookup but subsequent calls will ignore preimage and simply increase the number of references on hash.

Source

fn release(&self, hash: &H) -> Result<()>

Release the preimage of hash from the database. An equal number of these to the number of corresponding stores must have been given before it is legal for Database::lookup to be unable to provide the preimage.

Trait Implementations§

Source§

impl<H> Debug for dyn Database<H>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

Source§

impl<H> Database<H> for MemDb<H>
where H: Clone + Send + Sync + Eq + PartialEq + Default + Hash,