# [−][src]Struct memmap::MmapMut

    pub struct MmapMut { /* fields omitted */ }

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.

## Methods

### `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]

#### `fn as_mut(&mut self) -> &mut [u8]`[src]

Performs the conversion.

### `impl AsRef<[u8]> for MmapMut`[src]

#### `fn as_ref(&self) -> &[u8]`[src]

Performs the conversion.

### `impl DerefMut for MmapMut`[src]

#### `fn deref_mut(&mut self) -> &mut [u8]`[src]

Mutably dereferences the value.

### `impl Deref for MmapMut`[src]

#### `type Target = [u8]`

The resulting type after dereferencing.

#### `fn deref(&self) -> &[u8]`[src]

Dereferences the value.

### `impl Debug for MmapMut`[src]

#### `fn fmt(&self, fmt: &mut Formatter) -> Result`[src]

Formats the value using the given formatter. Read more

## Auto Trait Implementations

### `impl Send for MmapMut`

### `impl Unpin for MmapMut`

### `impl Sync for MmapMut`

### `impl UnwindSafe for MmapMut`

### `impl RefUnwindSafe for MmapMut`

## Blanket Implementations

### `impl<T, U> Into<U> for T where
U: From<T>,` [src]

#### `fn into(self) -> U`[src]

Performs the conversion.

### `impl<T> From<T> for T`[src]

#### `fn from(t: T) -> T`[src]

Performs the conversion.

### `impl<T, U> TryFrom<U> for T where
U: Into<T>,` [src]

#### `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]

Performs the conversion.

### `impl<T, U> TryInto<U> for T where
U: TryFrom<T>,` [src]

#### `type Error = <U as TryFrom<T>>::Error`

The type returned in the event of a conversion error.

#### `fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>`[src]

Performs the conversion.

### `impl<T> BorrowMut<T> for T where
T: ?Sized,` [src]

#### `fn borrow_mut(&mut self) -> &mut T`[src]

Mutably borrows from an owned value. Read more

### `impl<T> Borrow<T> for T where
T: ?Sized,` [src]

#### `fn borrow(&self) -> &T`[src]

Immutably borrows from an owned value. Read more

### `impl<T> Any for T where
T: 'static + ?Sized,` [src]

#### `fn type_id(&self) -> TypeId`[src]

Gets the `TypeId` of `self`. Read more

# Help

## Keyboard Shortcuts

`?`
  Show this help dialog
`S`
  Focus the search field
`↑`
  Move up in search results
`↓`
  Move down in search results
`↹`
  Switch tab
`⏎`
  Go to active search result
`+`
  Expand all sections
`-`
  Collapse all sections

## Search Tricks

Prefix searches with a type followed by a colon (e.g., `fn:`) to restrict the search to a given type.

Accepted types are: `fn`, `mod`, `struct`, `enum`, `trait`, `type`, `macro`, and `const`.

Search functions by type signature (e.g., `vec -> usize` or `* -> vec`)

Search multiple things at once by splitting your query with comma (e.g., `str,u8` or `String,struct:Vec,test`)