sift-core 0.6.0

Indexed regex search over codebases (library + grep-like CLI)
Documentation
//! Single source of truth for memory-mapped file access.
//!
//! Every `unsafe` in `sift-core` lives here with a documented safety
//! invariant.  Other modules import [`mmap_open`] instead of duplicating
//! the call.

use std::path::Path;

use memmap2::Mmap;

/// Memory-map a file for read access.
///
/// # Safety invariant
///
/// `Mmap::map` dereferences the raw OS mapping pointer. The OS manages
/// bounds and the mapping outlives the closed `File` handle via refcount.
#[allow(unsafe_code)]
pub fn mmap_open(path: &Path) -> std::io::Result<Mmap> {
    let file = std::fs::File::open(path)?;
    unsafe { Mmap::map(&file) }
}