Skip to main content

Crate mmap_io

Crate mmap_io 

Source
Expand description

§mmap-io: memory-mapped file I/O for Rust

Safe, zero-copy memory-mapped file operations with concurrent access, segmented views, runtime-agnostic async, and atomic memory views.

§What you get

  • Zero-copy reads on read-only, read-write, and copy-on-write mappings.
  • Thread-safe interior mutability via parking_lot::RwLock.
  • Segmented and chunked access without loading whole files.
  • Cross-platform: Linux, macOS, Windows, with per-platform fast paths.
  • Anonymous mappings via AnonymousMmap for shared scratch memory.
  • Atomic views (feature = "atomic") for lock-free counters in mapped memory.
  • Runtime-agnostic async (feature = "async") on tokio, smol, async-std, or any executor.
  • bytes::Bytes integration (feature = "bytes") for the hyper/tower/tonic/axum/reqwest ecosystem.
  • Native file watching (feature = "watch") via inotify / FSEvents / ReadDirectoryChangesW.

§Quick start

use mmap_io::MemoryMappedFile;

// Opens "data.bin" if it exists; creates it at 1 MiB otherwise.
let mmap = MemoryMappedFile::open_or_create("data.bin", 1024 * 1024)?;
mmap.update_region(0, b"Hello, mmap!")?;
mmap.flush()?;

§Modules

§Feature flags

All optional features are off by default except advise and iterator. See the README for the full feature table.

Re-exports§

pub use anonymous::AnonymousMmap;
pub use errors::MmapIoError;
pub use manager::copy_mmap;
pub use manager::create_mmap;
pub use manager::delete_mmap;
pub use manager::flush;
pub use manager::load_mmap;
pub use manager::update_region;
pub use manager::write_mmap;
pub use mmap::MappedSlice;
pub use mmap::MappedSliceMut;
pub use mmap::MemoryMappedFile;
pub use mmap::MmapMode;
pub use mmap::TouchHint;
pub use advise::MmapAdvice;
pub use iterator::ChunkIterator;
pub use iterator::PageIterator;
pub use watch::ChangeEvent;
pub use watch::ChangeKind;
pub use watch::WatchHandle;

Modules§

advise
Memory advise operations for optimizing OS behavior.
anonymous
Anonymous (file-less) memory mappings. Anonymous (file-less) memory mappings.
atomic
Atomic memory views for lock-free concurrent access to specific data types.
errors
Crate-specific error types for mmap-io.
flush
Provides functions for flushing memory-mapped file changes to disk. Flush policy configuration for MemoryMappedFile.
iterator
Zero-copy iterator-based access to a memory-mapped file.
lock
Memory locking operations to prevent pages from being swapped out.
manager
High-level API for managing memory-mapped files.
mmap
Memory-mapped file support.
segment
Zero-copy segment views into a memory-mapped file.
utils
Utility helpers for alignment, page size, and safe range calculations.
watch
Native file-change watching, backed by the notify crate.