Crate memmap2

source ·
Expand description

A cross-platform Rust API for memory mapped buffers.

The core functionality is provided by either Mmap or MmapMut, which correspond to mapping a File to a &[u8] or &mut [u8] respectively. Both function by dereferencing to a slice, allowing the Mmap/MmapMut to be used in the same way you would the equivalent slice types.

§Examples

For simple cases Mmap can be used directly:

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

use memmap2::Mmap;

let mut file = File::open("LICENSE-APACHE")?;

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

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

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

However for cases which require configuration of the mapping, then you can use MmapOptions in order to further configure a mapping before you create it.

Modules§

Structs§

Enums§

Traits§