Struct advreader::AdvReader

source ·
pub struct AdvReader { /* private fields */ }
Expand description

Provides iteration over bytes or utf8 string of words, strings and (line) comments.

use std::path::PathBuf;
use advreader::*;

// construct our iterator from our file input
let reader = AdvReader::default(&PathBuf::from("../testdata/example.txt"));

let mut reader_ok = reader.unwrap();

// walk our item using `while` syntax
for item in reader_ok.into_iter() {
    // do something with the item, which is Result<&[u8], _>
}

For those who prefer the Iterator API, this structure implements the IntoIterator trait to provide it. This comes at the cost of an allocation of a Vec for each line in the Iterator. This is negligible in many cases, so often it comes down to which syntax is preferred:

use std::path::PathBuf;
use advreader::*;

// construct our iterator from our file input
let reader = AdvReader::default(&PathBuf::from("../testdata/example.txt"));

let mut reader_ok = reader.unwrap();

// walk our items using `for` syntax
for item in reader_ok.into_iter() {
    // do something with the item, which is Result<AdvReturnValue, Error>
}

Implementations§

source§

impl AdvReader

source

pub fn new( path: &Path, buffer_size: Option<usize>, trim: Option<bool>, line_end: Option<u8>, skip_comments: Option<bool>, encode_comments: Option<bool>, encode_strings: Option<bool>, encoder: Option<String>, allow_invalid_utf8: Option<bool>, extended_word_separation: Option<bool>, double_quote_escape: Option<bool>, convert2numbers: Option<bool>, keep_base: Option<bool>, bool_false: Option<Vec<u8>>, bool_true: Option<Vec<u8>>, block_reader: Option<Box<dyn Block + Send + Sync>> ) -> Result<Self, Error>

Constructs a new AdvReader.

source

pub fn default(path: &Path) -> Result<Self, Error>

source

pub fn with_capacity( path: &Path, buffer_size: Option<usize>, trim: Option<bool>, line_end: Option<u8>, skip_comments: Option<bool>, encode_comments: Option<bool>, encode_strings: Option<bool>, encoder: Option<String>, allow_invalid_utf8: Option<bool>, extended_word_separation: Option<bool>, double_quote_escape: Option<bool>, convert2numbers: Option<bool>, keep_base: Option<bool>, bool_false: Option<Vec<u8>>, bool_true: Option<Vec<u8>>, block_reader: Option<Box<dyn Block + Send + Sync>> ) -> Result<Self, Error>

Constructs a new AdvReader.

source

pub fn stop(&mut self) -> Result<(usize, ReaderState), Error>

Trait Implementations§

source§

impl Debug for AdvReader

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl IntoIterator for AdvReader

IntoIterator conversion for AdvReader to provide Iterator APIs.

source§

fn into_iter(self) -> Self::IntoIter

Constructs a advreaderIter to provide an Iterator API.

§

type Item = Result<AdvReturnValue, Error>

The type of the elements being iterated over.
§

type IntoIter = AdvReaderIter

Which kind of iterator are we turning this into?

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>,

§

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>,

§

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.