pub struct SectionedStorage { /* private fields */ }Implementations§
Source§impl SectionedStorage
impl SectionedStorage
Sourcepub fn is_sectioned_file(path: &Path) -> bool
pub fn is_sectioned_file(path: &Path) -> bool
Check if a file is a sectioned file without opening it
This is a lightweight check that only reads the file header to verify the magic number. It doesn’t validate the entire file structure.
Sourcepub fn open(path: &Path) -> Result<Self>
pub fn open(path: &Path) -> Result<Self>
Open an existing sectioned file
Reads header and section table, validates structure integrity. Returns error if validation fails.
Sourcepub fn create_section(
&mut self,
name: &str,
capacity: u64,
flags: u32,
) -> Result<()>
pub fn create_section( &mut self, name: &str, capacity: u64, flags: u32, ) -> Result<()>
Create a new section with IMMEDIATE physical reservation
This method:
- Validates the name
- Gets current file length
- Computes allocation_base = max(next_data_offset, file_len)
- Allocates from allocation_base
- Physically extends file to reserve capacity
- Updates header.next_data_offset
Fails if:
- Name is empty
- Name exceeds 32 UTF-8 bytes
- Section with same name exists
- Addition would overflow
- File extension fails
Sourcepub fn write_section(&mut self, name: &str, data: &[u8]) -> Result<()>
pub fn write_section(&mut self, name: &str, data: &[u8]) -> Result<()>
Write data to an existing section
TASK 4 CAPACITY BEHAVIOR: Fails loudly with explicit error on overflow. Never silently loses data.
Fails if:
- Section doesn’t exist
- data.len() > section.capacity (explicit capacity error)
Sourcepub fn read_section(&mut self, name: &str) -> Result<Vec<u8>>
pub fn read_section(&mut self, name: &str) -> Result<Vec<u8>>
Read data from a section
Fails if:
- Section doesn’t exist
- Checksum mismatch
Sourcepub fn get_section(&self, name: &str) -> Option<&Section>
pub fn get_section(&self, name: &str) -> Option<&Section>
Get section metadata without reading data
Sourcepub fn list_sections(&self) -> Vec<Section>
pub fn list_sections(&self) -> Vec<Section>
List all sections
Sourcepub fn section_count(&self) -> usize
pub fn section_count(&self) -> usize
Get the number of sections
Sourcepub fn header(&self) -> &GeoFileHeader
pub fn header(&self) -> &GeoFileHeader
Get a reference to the header
Sourcepub fn flush(&mut self) -> Result<()>
pub fn flush(&mut self) -> Result<()>
Flush section table to EOF
Phase A behavior:
- Appends a FRESH section table at current EOF
- Updates header.section_table_offset to point to new table
- Old section tables become dead bytes in file
- File size grows with each flush
File layout after flush():
[0..128) - header
[128..next_data_offset) - section payload area
[section_table_offset..EOF) - current section tableBecause create_section() guarantees EOF >= next_data_offset,
the section table is always placed after all section payloads.
Compaction (reclaiming dead tables) is deferred to a later phase.
Sourcepub fn validate(&mut self) -> Result<()>
pub fn validate(&mut self) -> Result<()>
Validate file structure integrity
IMPORTANT: If self.dirty == true, returns an error.
Unflushed state cannot be validated against disk.
Sourcepub fn validate_required_sections(&self, required: &[&str]) -> Result<()>
pub fn validate_required_sections(&self, required: &[&str]) -> Result<()>
Validate that required sections exist
Sourcepub fn resize_section(&mut self, name: &str, new_capacity: u64) -> Result<()>
pub fn resize_section(&mut self, name: &str, new_capacity: u64) -> Result<()>
Resize a section to a new (larger) capacity
This method:
- Reads the current section data
- Creates a new section with the larger capacity at EOF
- Copies the data to the new location
- Removes the old section (becomes dead space)
- Flushes to disk
Fails if:
- Section doesn’t exist
- New capacity is smaller than current data length
- Read/write operations fail
Note: The old section’s space becomes dead space in the file. A future compaction operation could reclaim this space.
Trait Implementations§
Source§impl Debug for SectionedStorage
Sectioned file storage container
impl Debug for SectionedStorage
Sectioned file storage container
File layout (Phase A - Append-Only with Dead Tables):
[0..128) - header
[various offsets] - live section payloads (may have gaps)
[header.section_table_offset..) - current live section table
[section_table_offset..file_len) - dead bytes (old tables) may existAuto Trait Implementations§
impl Freeze for SectionedStorage
impl RefUnwindSafe for SectionedStorage
impl Send for SectionedStorage
impl Sync for SectionedStorage
impl Unpin for SectionedStorage
impl UnsafeUnpin for SectionedStorage
impl UnwindSafe for SectionedStorage
Blanket Implementations§
impl<T> Allocation for T
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> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
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