pub struct MmapDataSourceRw { /* private fields */ }Expand description
A read-write DataSource backed by a memory-mapped file.
Supports reading, writing, flushing, and seeking via the standard traits.
Use MmapDataSourceRw::open to map an existing file, or
MmapDataSourceRw::create to create and immediately map a new
zero-filled file of a given byte length.
§Safety
Internally this calls unsafe { MmapMut::map_mut(&file) }. The same
invariant applies as for MmapDataSource: the file must not be
accessed through any other handle while the mapping is live.
Implementations§
Source§impl MmapDataSourceRw
impl MmapDataSourceRw
Sourcepub fn open(path: impl AsRef<Path>) -> Result<Self>
pub fn open(path: impl AsRef<Path>) -> Result<Self>
Opens path for read-write memory-mapped access.
The file must already exist and be non-empty.
§Errors
Returns an error if the file cannot be opened, its metadata cannot be
read, the file is empty, or mmap_mut fails.
Sourcepub fn create(path: impl AsRef<Path>, len: usize) -> Result<Self>
pub fn create(path: impl AsRef<Path>, len: usize) -> Result<Self>
Creates a new file at path, extends it to len bytes, and maps it.
If path already exists it is truncated. The new file is zero-filled
by the OS.
§Errors
Returns an error if len == 0, the file cannot be created, set_len
fails, or mmap_mut fails.
Sourcepub fn flush(&self) -> Result<()>
pub fn flush(&self) -> Result<()>
Flushes outstanding changes to disk synchronously.
§Errors
Returns an error if msync / FlushViewOfFile fails.
Sourcepub fn as_bytes_mut(&mut self) -> &mut [u8] ⓘ
pub fn as_bytes_mut(&mut self) -> &mut [u8] ⓘ
Returns a mutable byte slice of the entire mapping.
Sourcepub fn read_at(&self, offset: usize, len: usize) -> Result<&[u8]>
pub fn read_at(&self, offset: usize, len: usize) -> Result<&[u8]>
Returns a byte slice for offset..offset+len without moving the cursor.
§Errors
Returns OxiGdalError::OutOfBounds if offset + len > self.len().
Trait Implementations§
Source§impl DataSource for MmapDataSourceRw
impl DataSource for MmapDataSourceRw
Source§impl Debug for MmapDataSourceRw
impl Debug for MmapDataSourceRw
Source§impl Read for MmapDataSourceRw
impl Read for MmapDataSourceRw
Source§fn read(&mut self, buf: &mut [u8]) -> Result<usize>
fn read(&mut self, buf: &mut [u8]) -> Result<usize>
1.36.0 · Source§fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> Result<usize, Error>
fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> Result<usize, Error>
read, except that it reads into a slice of buffers. Read moreSource§fn is_read_vectored(&self) -> bool
fn is_read_vectored(&self) -> bool
can_vector)1.0.0 · Source§fn read_to_end(&mut self, buf: &mut Vec<u8>) -> Result<usize, Error>
fn read_to_end(&mut self, buf: &mut Vec<u8>) -> Result<usize, Error>
buf. Read more1.0.0 · Source§fn read_to_string(&mut self, buf: &mut String) -> Result<usize, Error>
fn read_to_string(&mut self, buf: &mut String) -> Result<usize, Error>
buf. Read more1.6.0 · Source§fn read_exact(&mut self, buf: &mut [u8]) -> Result<(), Error>
fn read_exact(&mut self, buf: &mut [u8]) -> Result<(), Error>
buf. Read moreSource§fn read_buf(&mut self, buf: BorrowedCursor<'_>) -> Result<(), Error>
fn read_buf(&mut self, buf: BorrowedCursor<'_>) -> Result<(), Error>
read_buf)Source§fn read_buf_exact(&mut self, cursor: BorrowedCursor<'_>) -> Result<(), Error>
fn read_buf_exact(&mut self, cursor: BorrowedCursor<'_>) -> Result<(), Error>
read_buf)cursor. Read more1.0.0 · Source§fn by_ref(&mut self) -> &mut Selfwhere
Self: Sized,
fn by_ref(&mut self) -> &mut Selfwhere
Self: Sized,
Read. Read more1.0.0 · Source§fn chain<R>(self, next: R) -> Chain<Self, R>
fn chain<R>(self, next: R) -> Chain<Self, R>
Source§impl Seek for MmapDataSourceRw
impl Seek for MmapDataSourceRw
Source§fn seek(&mut self, pos: SeekFrom) -> Result<u64>
fn seek(&mut self, pos: SeekFrom) -> Result<u64>
1.55.0 · Source§fn rewind(&mut self) -> Result<(), Error>
fn rewind(&mut self) -> Result<(), Error>
Source§fn stream_len(&mut self) -> Result<u64, Error>
fn stream_len(&mut self) -> Result<u64, Error>
seek_stream_len)Source§impl Write for MmapDataSourceRw
impl Write for MmapDataSourceRw
Source§fn write(&mut self, buf: &[u8]) -> Result<usize>
fn write(&mut self, buf: &[u8]) -> Result<usize>
Source§fn flush(&mut self) -> Result<()>
fn flush(&mut self) -> Result<()>
Source§fn is_write_vectored(&self) -> bool
fn is_write_vectored(&self) -> bool
can_vector)1.0.0 · Source§fn write_all(&mut self, buf: &[u8]) -> Result<(), Error>
fn write_all(&mut self, buf: &[u8]) -> Result<(), Error>
Source§fn write_all_vectored(&mut self, bufs: &mut [IoSlice<'_>]) -> Result<(), Error>
fn write_all_vectored(&mut self, bufs: &mut [IoSlice<'_>]) -> Result<(), Error>
write_all_vectored)