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 utils;
48pub mod mmap;
49pub mod segment;
50pub mod manager;
51
52/// Provides functions for flushing memory-mapped file changes to disk.
53pub mod flush;
54
55#[cfg(feature = "advise")]
56pub mod advise;
57
58#[cfg(feature = "iterator")]
59pub mod iterator;
60
61#[cfg(feature = "locking")]
62pub mod lock;
63
64#[cfg(feature = "atomic")]
65pub mod atomic;
66
67#[cfg(feature = "watch")]
68pub mod watch;
69
70pub use errors::MmapIoError;
71pub use mmap::{MemoryMappedFile, MmapMode};
72pub use manager::{
73 copy_mmap, create_mmap, delete_mmap, flush, load_mmap, update_region, write_mmap,
74};
75
76#[cfg(feature = "advise")]
77pub use advise::MmapAdvice;
78
79#[cfg(feature = "iterator")]
80pub use iterator::{ChunkIterator, PageIterator};
81
82#[cfg(feature = "watch")]
83pub use watch::{ChangeEvent, ChangeKind, WatchHandle};