#mmap #file #read #write #append #api #memory-mapped

mmap-simple

Write, read, append and delete from an mmapped file with a very simple API

3 unstable releases

0.2.0 May 16, 2024
0.1.1 May 14, 2024
0.1.0 May 13, 2024

#364 in Unix APIs

Download history 22/week @ 2024-05-07 389/week @ 2024-05-14 34/week @ 2024-05-21

445 downloads per month

MIT license

16KB
204 lines

mmap-simple

docs.rs crates.io

mmap-simple is a Rust crate for simple yet fast memory-mapping of files, providing simple APIs for writing, appending, reading and dropping from the file.

Getting Started

To use mmap-simple, add it to your Cargo.toml under [dependencies]:

[dependencies]
mmap-simple= "0.1.0"

Read the docs for a little bit of more info.


lib.rs:

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(())
}

Dependencies

~43KB