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§
Required Methods§
Sourcefn read_exact_at(&mut self, buf: &mut [u8], offset: u64) -> Result<(), Error>
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
.
Sourcefn write_all_at(&mut self, buf: &[u8], offset: u64) -> Result<(), Error>
fn write_all_at(&mut self, buf: &[u8], offset: u64) -> Result<(), Error>
Attempts to write an entire buf
starting from the given offset
.
Sourcefn sync(&mut self, data_only: bool) -> Result<(), Error>
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.
Sourcefn set_len(&mut self, size: u64) -> Result<(), Error>
fn set_len(&mut self, size: u64) -> Result<(), Error>
Set the database file to the specified size
. Truncates or extends the underlying storage.
Sourcefn lock(&mut self, lock: LockKind) -> Result<bool, Error>
fn lock(&mut self, lock: LockKind) -> Result<bool, Error>
Lock the database. Returns whether the requested lock could be acquired. Locking sequence:
- The lock is never moved from LockKind::None to anything higher than LockKind::Shared.
- A LockKind::Pending is never requested explicitly.
- A LockKind::Shared is always held when a LockKind::Reserved lock is requested
Sourcefn reserved(&mut self) -> Result<bool, Error>
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.
Sourcefn current_lock(&self) -> Result<LockKind, Error>
fn current_lock(&self) -> Result<LockKind, Error>
Return the current LockKind of the this handle.