mmap_io/lib.rs
1//! # mmap-io: High-performance memory-mapped file I/O for Rust
2//!
3//! This crate provides a safe, efficient interface for memory-mapped file operations
4//! with support for concurrent access, segmented views, and optional async operations.
5//!
6//! ## Features
7//!
8//! - **Zero-copy I/O**: Direct memory access without buffer copying
9//! - **Thread-safe**: Concurrent read/write access with proper synchronization
10//! - **Segmented access**: Work with file regions without loading entire files
11//! - **Cross-platform**: Works on Windows, Linux, macOS via memmap2
12//! - **Async support**: Optional Tokio integration for async file operations
13//!
14//! ## Quick Start
15//!
16//! ```no_run
17//! use mmap_io::{create_mmap, update_region, flush};
18//!
19//! // Create a 1MB memory-mapped file
20//! let mmap = create_mmap("data.bin", 1024 * 1024)?;
21//!
22//! // Write data at offset 100
23//! update_region(&mmap, 100, b"Hello, mmap!")?;
24//!
25//! // Ensure data is persisted
26//! flush(&mmap)?;
27//! # Ok::<(), mmap_io::MmapIoError>(())
28//! ```
29//!
30//! ## Modules
31//!
32//! - [`errors`]: Error types for all mmap operations
33//! - [`utils`]: Utility functions for alignment and bounds checking
34//! - [`mmap`]: Core `MemoryMappedFile` implementation
35//! - [`segment`]: Segmented views for working with file regions
36//! - [`manager`]: High-level convenience functions
37//!
38//! ## Feature Flags
39//!
40//! - `async`: Enables Tokio-based async file operations
41
42#![cfg_attr(not(test), deny(clippy::unwrap_used))]
43#![deny(missing_docs)]
44#![doc(html_root_url = "https://docs.rs/mmap-io")]
45
46pub mod errors;
47pub mod manager;
48/// Memory-mapped file support.
49pub mod mmap;
50pub mod segment;
51pub mod utils;
52
53/// Provides functions for flushing memory-mapped file changes to disk.
54pub mod flush;
55
56#[cfg(feature = "advise")]
57pub mod advise;
58
59#[cfg(feature = "iterator")]
60pub mod iterator;
61
62#[cfg(feature = "locking")]
63pub mod lock;
64
65#[cfg(feature = "atomic")]
66pub mod atomic;
67
68#[cfg(feature = "watch")]
69pub mod watch;
70
71pub use errors::MmapIoError;
72pub use manager::{
73 copy_mmap, create_mmap, delete_mmap, flush, load_mmap, update_region, write_mmap,
74};
75pub use mmap::{MemoryMappedFile, MmapMode, TouchHint};
76
77#[cfg(feature = "advise")]
78pub use advise::MmapAdvice;
79
80#[cfg(feature = "iterator")]
81pub use iterator::{ChunkIterator, PageIterator};
82
83#[cfg(feature = "watch")]
84pub use watch::{ChangeEvent, ChangeKind, WatchHandle};