Trait DatabaseHandle

Source
pub trait DatabaseHandle: Sync {
    type WalIndex: WalIndex;

    // Required methods
    fn size(&self) -> Result<u64, Error>;
    fn read_exact_at(
        &mut self,
        buf: &mut [u8],
        offset: u64,
    ) -> Result<(), Error>;
    fn write_all_at(&mut self, buf: &[u8], offset: u64) -> Result<(), Error>;
    fn sync(&mut self, data_only: bool) -> Result<(), Error>;
    fn set_len(&mut self, size: u64) -> Result<(), Error>;
    fn lock(&mut self, lock: LockKind) -> Result<bool, Error>;
    fn reserved(&mut self) -> Result<bool, Error>;
    fn current_lock(&self) -> Result<LockKind, Error>;
    fn wal_index(&self, readonly: bool) -> Result<Self::WalIndex, Error>;

    // Provided methods
    fn unlock(&mut self, lock: LockKind) -> Result<bool, Error> { ... }
    fn set_chunk_size(&self, _chunk_size: usize) -> Result<(), Error> { ... }
    fn moved(&self) -> Result<bool, Error> { ... }
}
Expand description

A file opened by Vfs.

Required Associated Types§

Source

type WalIndex: WalIndex

An optional trait used to store a WAL (write-ahead log).

Required Methods§

Source

fn size(&self) -> Result<u64, Error>

Return the current size in bytes of the database.

Source

fn read_exact_at(&mut self, buf: &mut [u8], offset: u64) -> Result<(), Error>

Reads the exact number of byte required to fill buf from the given offset.

Source

fn write_all_at(&mut self, buf: &[u8], offset: u64) -> Result<(), Error>

Attempts to write an entire buf starting from the given offset.

Source

fn sync(&mut self, data_only: bool) -> Result<(), Error>

Make sure all writes are committed to the underlying storage. If data_only is set to true, only the data and not the metadata (like size, access time, etc) should be synced.

Source

fn set_len(&mut self, size: u64) -> Result<(), Error>

Set the database file to the specified size. Truncates or extends the underlying storage.

Source

fn lock(&mut self, lock: LockKind) -> Result<bool, Error>

Lock the database. Returns whether the requested lock could be acquired. Locking sequence:

Source

fn reserved(&mut self) -> Result<bool, Error>

Check if the database this handle points to holds a LockKind::Reserved, LockKind::Pending or LockKind::Exclusive lock.

Source

fn current_lock(&self) -> Result<LockKind, Error>

Return the current LockKind of the this handle.

Source

fn wal_index(&self, readonly: bool) -> Result<Self::WalIndex, Error>

Provided Methods§

Source

fn unlock(&mut self, lock: LockKind) -> Result<bool, Error>

Unlock the database.

Source

fn set_chunk_size(&self, _chunk_size: usize) -> Result<(), Error>

Change the chunk size of the database to chunk_size.

Source

fn moved(&self) -> Result<bool, Error>

Check if the underlying data of the handle got moved or deleted. When moved, the handle can still be read from, but not written to anymore.

Implementors§