pub struct SmartReader { /* private fields */ }Expand description
Smart file reader that chooses optimal reading strategy based on file size.
For files smaller than the threshold, uses std::fs::read_to_string for simplicity.
For larger files, uses memory-mapped files to avoid loading entire content into heap.
Implementations§
Source§impl SmartReader
impl SmartReader
Sourcepub const fn new() -> Self
pub const fn new() -> Self
Creates a new SmartReader with the default threshold (512KB).
§Examples
use fast_yaml_parallel::SmartReader;
use std::path::Path;
let reader = SmartReader::new();
let content = reader.read(temp_file.path())?;
let yaml = content.as_str()?;
assert!(yaml.contains("key"));Sourcepub const fn with_threshold(threshold: u64) -> Self
pub const fn with_threshold(threshold: u64) -> Self
Creates a new SmartReader with a custom threshold.
§Examples
use fast_yaml_parallel::SmartReader;
// Use mmap for files larger than 1MB
let reader = SmartReader::with_threshold(1024 * 1024);Sourcepub fn read(&self, path: &Path) -> Result<FileContent>
pub fn read(&self, path: &Path) -> Result<FileContent>
Reads file content using the optimal strategy based on file size.
Returns FileContent and automatically chooses between:
read_to_stringfor files < thresholdmmapfor files >= threshold
Falls back to read_to_string if mmap fails.
§Errors
Returns Error::Io if:
- Path does not exist
- Path is a directory
- Insufficient permissions
Trait Implementations§
Source§impl Debug for SmartReader
impl Debug for SmartReader
Auto Trait Implementations§
impl Freeze for SmartReader
impl RefUnwindSafe for SmartReader
impl Send for SmartReader
impl Sync for SmartReader
impl Unpin for SmartReader
impl UnwindSafe for SmartReader
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more