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

    pub struct Mmap { /* fields omitted */ }

An immutable memory mapped buffer.

A `Mmap` may be backed by a file, or it can be anonymous map, backed by volatile memory.

Use `MmapOptions` to configure and create a file-backed memory map. To create an immutable anonymous memory map, first create a mutable anonymous memory map using `MmapOptions`, and then make it immutable with `MmapMut::make_read_only`.

# Example

    use memmap::MmapOptions;
    use std::io::Write;
    use std::fs::File;

    let file = File::open("README.md")?;
    let mmap = unsafe { MmapOptions::new().map(&file)? };
    assert_eq!(b"# memmap", &mmap[0..8]);

See `MmapMut` for the mutable version.

## Methods

### `impl Mmap`[src]

#### `pub unsafe fn map(file: &File) -> Result<Mmap>`[src]

Creates a read-only memory map backed by a file.

This is equivalent to calling `MmapOptions::new().map(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 permissions.

# Example

    use std::fs::File;
    use std::io::Read;

    use memmap::Mmap;

    let mut file = File::open("README.md")?;

    let mut contents = Vec::new();
    file.read_to_end(&mut contents)?;

    let mmap = unsafe { Mmap::map(&file)?  };

    assert_eq!(&contents[..], &mmap[..]);

#### `pub fn make_mut(self) -> Result<MmapMut>`[src]

Transition the memory map to be writable.

If the memory map is file-backed, the file must have been opened with write 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 is not open with writable permissions.

# Example

    use memmap::Mmap;
    use std::ops::DerefMut;
    use std::io::Write;

    let file = /* file opened with write permissions */
    let mmap = unsafe { Mmap::map(&file)? };
    // ... use the read-only memory map ...
    let mut mut_mmap = mmap.make_mut()?;
    mut_mmap.deref_mut().write_all(b"hello, world!")?;

## Trait Implementations

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

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

Performs the conversion.

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

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

The resulting type after dereferencing.

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

Dereferences the value.

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

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

Formats the value using the given formatter. Read more

## Auto Trait Implementations

### `impl Send for Mmap`

### `impl Unpin for Mmap`

### `impl Sync for Mmap`

### `impl UnwindSafe for Mmap`

### `impl RefUnwindSafe for Mmap`

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