Skip to main content

MmapYamlReader

Struct MmapYamlReader 

Source
pub struct MmapYamlReader {
    mmap: Mmap,
    position: usize,
}
Expand description

Memory-mapped YAML file reader

Fields§

§mmap: Mmap§position: usize

Implementations§

Source§

impl MmapYamlReader

Source

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.

Source

pub fn as_str(&self) -> Result<&str>

Get the entire content as a string slice

Source

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).

Source

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).

Source

pub fn reset(&mut self)

Reset position to beginning

Source

pub fn remaining(&self) -> usize

Get remaining bytes

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.