pub struct SegmentMut { /* private fields */ }
Expand description
Mutable view into a region of a memory-mapped file. Holds a reference to the parent map; mutable access is provided on demand.
§Examples
use std::sync::Arc;
use mmap_io::{MemoryMappedFile, segment::SegmentMut};
let mmap = Arc::new(MemoryMappedFile::create_rw("data.bin", 1024)?);
// Create a mutable segment for bytes 0-100
let segment = SegmentMut::new(mmap.clone(), 0, 100)?;
// Write data to the segment
segment.write(b"Hello from segment!")?;
Implementations§
Source§impl SegmentMut
impl SegmentMut
Sourcepub fn new(parent: Arc<MemoryMappedFile>, offset: u64, len: u64) -> Result<Self>
pub fn new(parent: Arc<MemoryMappedFile>, offset: u64, len: u64) -> Result<Self>
Create a new mutable segment view. Performs bounds checks.
§Errors
Returns MmapIoError::OutOfBounds
if the segment exceeds file bounds.
Sourcepub fn as_slice_mut(&self) -> Result<MappedSliceMut<'_>>
pub fn as_slice_mut(&self) -> Result<MappedSliceMut<'_>>
Return a write-capable guard to the underlying bytes for this segment. The guard holds the write lock for the duration of the mutable borrow.
§Errors
Returns errors from the underlying MemoryMappedFile::as_slice_mut
call.
Note: Bounds are already validated at construction, so as_slice_mut will not perform redundant validation.
Sourcepub fn write(&self, data: &[u8]) -> Result<()>
pub fn write(&self, data: &[u8]) -> Result<()>
Write bytes into this segment from the provided slice.
§Errors
Returns errors from the underlying MemoryMappedFile::update_region
call.
Sourcepub fn parent(&self) -> &MemoryMappedFile
pub fn parent(&self) -> &MemoryMappedFile
Parent mapping.
Trait Implementations§
Source§impl Clone for SegmentMut
impl Clone for SegmentMut
Source§fn clone(&self) -> SegmentMut
fn clone(&self) -> SegmentMut
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moreAuto Trait Implementations§
impl Freeze for SegmentMut
impl !RefUnwindSafe for SegmentMut
impl Send for SegmentMut
impl Sync for SegmentMut
impl Unpin for SegmentMut
impl !UnwindSafe for SegmentMut
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
Mutably borrows from an owned value. Read more