Crate mmap_simple

Source
Expand description

A simple API for treating a file basically as an infinite vector that can be written to at any point, appended to, read from and shrinken at will and in a very fast way.

The file is memory-mapped with a libc call specifying basically an infinite memory size. But it doesn’t consume that amount of memory. Should only be used on Linux and from a single caller/process. All write calls immediately call sync_all after them, which is not ideal, but maybe we’ll improve later.

§Example

use std::path::Path;
use mmap_simple::Mmap;

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let mut mmap = Mmap::new(Path::new("example.txt"))?;
    mmap.append(b"Hello, world!")?;
    mmap.overwrite(0, b"Goodbye")?;
    mmap.drop_from_tail(6)?;
    mmap.append(b", world!")?;
    Ok(())
}

Structs§

Mmap
A struct that represents a memory-mapped file.