pub struct SharedFileMapping { /* private fields */ }Expand description
A retained mapping, without a second file descriptor or borrowed Rust slices. Mapping ownership may move between threads; byte access requires external exclusion, extent validation and memory barriers at the lock boundary.
Implementations§
Sourcepub fn new(file: &File, length: usize) -> Result<Self>
pub fn new(file: &File, length: usize) -> Result<Self>
Map an existing prefix, reserving sparse holes before writable access. The caller must serialize this operation with file writes and resizing. The existing file bytes and length are preserved, as is its seek position. Unsupported filesystems or allocation failures should use positioned I/O.
pub fn mapped_len(&self) -> usize
pub fn contains(&self, offset: u64, length: usize) -> bool
Sourcepub unsafe fn read(&self, offset: u64, bytes: &mut [u8]) -> bool
pub unsafe fn read(&self, offset: u64, bytes: &mut [u8]) -> bool
Copy a mapped range, returning false if it is outside this mapping.
§Safety
The underlying file must still cover the mapped extent. Exclude writes and resizing in every process for the complete copy, with an acquire barrier after taking the external lock. The destination must not alias the mapping. No reference into the mapped memory escapes this call.
Sourcepub unsafe fn write(&self, offset: u64, bytes: &[u8]) -> bool
pub unsafe fn write(&self, offset: u64, bytes: &[u8]) -> bool
Replace a mapped range, returning false if it is outside this mapping.
§Safety
The underlying file must still cover the reserved mapped extent. Exclude all other access and resizing until the copy completes, then issue a release barrier before unlocking. The source must not alias the mapping. This publishes coordination bytes; it does not provide crash durability.
Sourcepub unsafe fn write_published(
&self,
offset: u64,
bytes: &[u8],
state: usize,
pending: u8,
) -> bool
pub unsafe fn write_published( &self, offset: u64, bytes: &[u8], state: usize, pending: u8, ) -> bool
Replace a record while publishing its state byte last. An interrupted
copy leaves pending, so a peer never decodes a partially written record.
Returns false without mutation when either range is invalid.
§Safety
The exclusion, extent and source requirements of write apply. pending
must describe a valid unpublished record in the caller’s format, regardless
of its remaining bytes. Its state byte must be independently writable.