[−][src]Struct memmap::MmapMut
A mutable memory mapped buffer.
A file-backed MmapMut
buffer may be used to read from or write to a file. An anonymous
MmapMut
buffer may be used any place that an in-memory byte buffer is needed. Use
MmapOptions
for creating memory maps.
See Mmap
for the immutable version.
Implementations
impl MmapMut
[src]
pub unsafe fn map_mut(file: &File) -> Result<MmapMut>
[src]
Creates a writeable memory map backed by a file.
This is equivalent to calling MmapOptions::new().map_mut(file)
.
Errors
This method returns an error when the underlying system call fails, which can happen for a variety of reasons, such as when the file is not open with read and write permissions.
Example
use std::fs::OpenOptions; use std::path::PathBuf; use memmap::MmapMut; let path: PathBuf = /* path to file */ let file = OpenOptions::new() .read(true) .write(true) .create(true) .open(&path)?; file.set_len(13)?; let mut mmap = unsafe { MmapMut::map_mut(&file)? }; mmap.copy_from_slice(b"Hello, world!");
pub fn map_anon(length: usize) -> Result<MmapMut>
[src]
Creates an anonymous memory map.
This is equivalent to calling MmapOptions::new().len(length).map_anon()
.
Errors
This method returns an error when the underlying system call fails.
pub fn flush(&self) -> Result<()>
[src]
Flushes outstanding memory map modifications to disk.
When this method returns with a non-error result, all outstanding changes to a file-backed memory map are guaranteed to be durably stored. The file's metadata (including last modification timestamp) may not be updated.
Example
use std::fs::OpenOptions; use std::io::Write; use std::path::PathBuf; use memmap::MmapMut; let path: PathBuf = /* path to file */ let file = OpenOptions::new().read(true).write(true).create(true).open(&path)?; file.set_len(128)?; let mut mmap = unsafe { MmapMut::map_mut(&file)? }; (&mut mmap[..]).write_all(b"Hello, world!")?; mmap.flush()?;
pub fn flush_async(&self) -> Result<()>
[src]
Asynchronously flushes outstanding memory map modifications to disk.
This method initiates flushing modified pages to durable storage, but it will not wait for the operation to complete before returning. The file's metadata (including last modification timestamp) may not be updated.
pub fn flush_range(&self, offset: usize, len: usize) -> Result<()>
[src]
Flushes outstanding memory map modifications in the range to disk.
The offset and length must be in the bounds of the memory map.
When this method returns with a non-error result, all outstanding changes to a file-backed memory in the range are guaranteed to be durable stored. The file's metadata (including last modification timestamp) may not be updated. It is not guaranteed the only the changes in the specified range are flushed; other outstanding changes to the memory map may be flushed as well.
pub fn flush_async_range(&self, offset: usize, len: usize) -> Result<()>
[src]
Asynchronously flushes outstanding memory map modifications in the range to disk.
The offset and length must be in the bounds of the memory map.
This method initiates flushing modified pages to durable storage, but it will not wait for the operation to complete before returning. The file's metadata (including last modification timestamp) may not be updated. It is not guaranteed that the only changes flushed are those in the specified range; other outstanding changes to the memory map may be flushed as well.
pub fn make_read_only(self) -> Result<Mmap>
[src]
Returns an immutable version of this memory mapped buffer.
If the memory map is file-backed, the file must have been opened with read permissions.
Errors
This method returns an error when the underlying system call fails, which can happen for a variety of reasons, such as when the file has not been opened with read permissions.
Example
use std::io::Write; use std::path::PathBuf; use memmap::{Mmap, MmapMut}; let mut mmap = MmapMut::map_anon(128)?; (&mut mmap[..]).write(b"Hello, world!")?; let mmap: Mmap = mmap.make_read_only()?;
pub fn make_exec(self) -> Result<Mmap>
[src]
Transition the memory map to be readable and executable.
If the memory map is file-backed, the file must have been opened with execute permissions.
Errors
This method returns an error when the underlying system call fails, which can happen for a variety of reasons, such as when the file has not been opened with execute permissions.
Trait Implementations
impl AsMut<[u8]> for MmapMut
[src]
impl AsRef<[u8]> for MmapMut
[src]
impl Debug for MmapMut
[src]
impl Deref for MmapMut
[src]
impl DerefMut for MmapMut
[src]
Auto Trait Implementations
impl RefUnwindSafe for MmapMut
impl Send for MmapMut
impl Sync for MmapMut
impl Unpin for MmapMut
impl UnwindSafe for MmapMut
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,