pub trait DatabaseHandle: Sync {
    type WalIndex: WalIndex;

    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>;

    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

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

Required Methods

Return the current size in bytes of the database.

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

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

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.

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

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

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

Return the current LockKind of the this handle.

Provided Methods

Unlock the database.

Change the chunk size of the database to chunk_size.

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