Skip to main content

Database

Trait Database 

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

    // Provided methods
    fn contains(&self, col: ColumnId, key: &[u8]) -> bool { ... }
    fn value_size(&self, col: ColumnId, key: &[u8]) -> Option<usize> { ... }
    fn with_get(&self, col: ColumnId, key: &[u8], f: &mut dyn FnMut(&[u8])) { ... }
    fn supports_ref_counting(&self) -> bool { ... }
    fn sanitize_key(&self, _key: &mut Vec<u8>) { ... }
}

Required 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 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.

Provided Methods§

Source

fn contains(&self, col: ColumnId, key: &[u8]) -> bool

Check if the value exists in the database without retrieving it.

Source

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

Check value size in the database possibly without retrieving it.

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 supports_ref_counting(&self) -> bool

Check if database supports internal ref counting for state data.

For backwards compatibility returns false by default.

Source

fn sanitize_key(&self, _key: &mut Vec<u8>)

Remove a possible path-prefix from the key.

Not all database implementations use a prefix for keys, so this function may be a noop.

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
where H: Clone + AsRef<[u8]>,