pub struct Segment { /* private fields */ }
Expand description
Immutable view into a region of a memory-mapped file.
§Examples
use std::sync::Arc;
use mmap_io::{MemoryMappedFile, segment::Segment};
let mmap = Arc::new(MemoryMappedFile::open_ro("data.bin")?);
// Create a segment for bytes 100-200
let segment = Segment::new(mmap.clone(), 100, 100)?;
// Read the segment data
let data = segment.as_slice()?;
Implementations§
Source§impl Segment
impl Segment
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 immutable segment view. Performs bounds checks.
§Errors
Returns MmapIoError::OutOfBounds
if the segment exceeds file bounds.
Sourcepub fn as_slice(&self) -> Result<&[u8]>
pub fn as_slice(&self) -> Result<&[u8]>
Return the segment as a read-only byte slice.
§Errors
Returns errors from the underlying MemoryMappedFile::as_slice
call.
Note: Bounds are already validated at construction, so as_slice will not perform redundant validation.
Sourcepub fn parent(&self) -> &MemoryMappedFile
pub fn parent(&self) -> &MemoryMappedFile
Parent mapping.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Segment
impl !RefUnwindSafe for Segment
impl Send for Segment
impl Sync for Segment
impl Unpin for Segment
impl !UnwindSafe for Segment
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