pub struct MmapYamlReader {
mmap: Mmap,
position: usize,
}Expand description
Memory-mapped YAML file reader
Fields§
§mmap: Mmap§position: usizeImplementations§
Source§impl MmapYamlReader
impl MmapYamlReader
Sourcepub fn new<P: AsRef<Path>>(path: P) -> Result<Self>
pub fn new<P: AsRef<Path>>(path: P) -> Result<Self>
Create a new memory-mapped reader for the file at path.
§Warning
Memory mapping ties the process to the file’s backing storage for
the lifetime of the reader. If the file is truncated or modified
by another process while mapped, touching the now-invalid pages
raises SIGBUS on Linux/macOS — an unrecoverable signal that
terminates the process.
Only use MmapYamlReader with trusted, stable files that no
other process will modify concurrently (a TOCTOU hazard). For
untrusted or volatile inputs, read the file into memory instead.
Sourcepub fn try_read_chunk(&mut self, size: usize) -> Result<Option<&str>>
pub fn try_read_chunk(&mut self, size: usize) -> Result<Option<&str>>
Read a chunk from the current position, propagating UTF-8 errors.
Returns Ok(None) at end of input, Ok(Some(chunk)) for a valid
chunk of text, and Err(..) when the file holds invalid UTF-8.
This is the error-propagating counterpart of read_chunk, which
reports a malformed file as None, indistinguishable from EOF.
The returned chunk always ends on a UTF-8 character boundary: a
multi-byte sequence straddling size is never split, so a valid
file is read to completion rather than silently truncated. The
chunk may therefore be a few bytes longer than size (#25).
Sourcepub fn read_chunk(&mut self, size: usize) -> Option<&str>
pub fn read_chunk(&mut self, size: usize) -> Option<&str>
Read a chunk from the current position.
Returns None at end of input. Like try_read_chunk, the chunk
never splits a multi-byte UTF-8 sequence. A None cannot be told
apart from a file containing invalid UTF-8 — prefer
try_read_chunk when that distinction matters (#25).