pub struct Region(/* private fields */);Expand description
Named region within a database providing isolated storage space.
Regions grow dynamically as data is written and can be moved within the database file to optimize space usage. Each region has a unique ID for lookup.
Implementations§
Source§impl Region
impl Region
pub fn new( db: &Database, id: String, index: usize, start: usize, len: usize, reserved: usize, ) -> Self
pub fn from(db: &Database, index: usize, meta: RegionMetadata) -> Self
Sourcepub fn create_reader(&self) -> Reader
pub fn create_reader(&self) -> Reader
Creates a reader for zero-copy access to this region’s data.
The Reader holds read locks on both the memory map and region metadata, blocking writes until dropped. Drop the reader as soon as you’re done reading to avoid blocking other operations.
pub fn open_db_read_only_file(&self) -> Result<File>
Sourcepub fn write(&self, data: &[u8]) -> Result<()>
pub fn write(&self, data: &[u8]) -> Result<()>
Appends data to the end of the region.
The region will automatically grow and relocate if needed.
Data is written to the mmap but not durable until flush() is called.
Sourcepub fn write_at(&self, data: &[u8], at: usize) -> Result<()>
pub fn write_at(&self, data: &[u8], at: usize) -> Result<()>
Writes data at a specific offset within the region.
The offset must be within the current region length.
Data written past the current end will extend the length.
Data is written to the mmap but not durable until flush() is called.
Sourcepub fn batch_write_each<T, F>(
&self,
iter: impl Iterator<Item = (usize, T)>,
value_len: usize,
write_fn: F,
)
pub fn batch_write_each<T, F>( &self, iter: impl Iterator<Item = (usize, T)>, value_len: usize, write_fn: F, )
Writes values directly to the mmap with dirty range tracking.
All writes must be within the current region length (no extension). Tracks dirty ranges to avoid flushing unchanged data.
iter: Iterator yielding (offset, value) pairs where offset is relative to region startvalue_len: The byte size of each valuewrite_fn: Called for each (value, slice) to serialize the value into the slice
Sourcepub fn truncate(&self, from: usize) -> Result<()>
pub fn truncate(&self, from: usize) -> Result<()>
Truncates the region to the specified length.
This reduces the logical length but doesn’t modify existing data bytes.
The truncated data becomes inaccessible even though the bytes remain in the mmap.
Changes are not durable until flush() is called.
Sourcepub fn truncate_write(&self, at: usize, data: &[u8]) -> Result<()>
pub fn truncate_write(&self, at: usize, data: &[u8]) -> Result<()>
Truncates the region to a specific offset and writes data there.
This is an atomic truncate + write operation. The final length will be
exactly at + data.len() regardless of the previous length.
Changes are not durable until flush() is called.
Sourcepub fn rename(&self, new_id: &str) -> Result<()>
pub fn rename(&self, new_id: &str) -> Result<()>
Renames the region to a new ID.
The new ID must not already be in use.
Changes are not durable until flush() is called.
Sourcepub fn remove(self) -> Result<()>
pub fn remove(self) -> Result<()>
Removes the region from the database.
The space is marked as a pending hole that will become reusable after
the next flush(). This consumes the region to prevent use-after-free.
Sourcepub fn flush(&self) -> Result<bool>
pub fn flush(&self) -> Result<bool>
Flushes this region’s dirty data and metadata to disk.
Flushes if any data writes or metadata-only changes (truncate, rename) were made.
Returns Ok(true) if anything was flushed, Ok(false) if nothing was dirty.
pub fn arc(&self) -> &Arc<RegionInner>
pub fn index(&self) -> usize
pub fn meta(&self) -> RwLockReadGuard<'_, RegionMetadata>
pub fn db(&self) -> Database
Sourcepub fn mark_dirty(&self, offset: usize, len: usize)
pub fn mark_dirty(&self, offset: usize, len: usize)
Marks a range as dirty (needing flush).
offset is relative to region start.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Region
impl !RefUnwindSafe for Region
impl Send for Region
impl Sync for Region
impl Unpin for Region
impl !UnwindSafe for Region
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more