Struct dcsv::Reader

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

Csv Reader

User can set various reader option to configure a reading behaviour. Reader’s options are not dropped after a read but persists for reader’s lifetime.

Usage

use dcsv::Reader;

let csv_value = "a,b,c
1,2,3";

let data = Reader::new()
   .trim(true)
   .ignore_empty_row(true)
   .has_header(true)
   .data_from_stream(csv_value.as_bytes());

Implementations§

source§

impl Reader

source

pub fn new() -> Self

source

pub fn with_option(self, option: ReaderOption) -> Self

Build with reader option

source

pub fn consume_dquote(self, tv: bool) -> Self

Consumes double quote in csv file

source

pub fn ignore_empty_row(self, tv: bool) -> Self

Ignore empty rows

This prevents reader from panicking on empty row.

source

pub fn trim(self, tv: bool) -> Self

Trim all read values

source

pub fn allow_invalid_string(self, allow: bool) -> Self

Allow invalid string while parsing csv values

source

pub fn has_header(self, has_header: bool) -> Self

Whether csv data has header or not

source

pub fn custom_header<T: AsRef<str>>(self, headers: &[T]) -> Self

Set custom header

This will override “has_header” option and create header from given values.

source

pub fn clear_reader_option(&mut self)

Clear reader option and set to default

source

pub fn use_delimiter(self, delimiter: char) -> Self

Use given delimiter instead of default one : “,”.

source

pub fn use_space_delimiter(self, tv: bool) -> Self

Use space delimiter

source

pub fn use_line_delimiter(self, delimiter: char) -> Self

Use given line delimiter instead of default one : “\n, \r\n”.

Only default state will detect both “\n” and “\r\n”. If you set “\n” manually, “\r\n” will be ignored.

source

pub fn data_from_stream( &mut self, csv_stream: impl BufRead ) -> DcsvResult<VirtualData>

Read csv value from buf read stream

This returns read value as virtual data struct

source

pub fn array_from_stream( &mut self, csv_stream: impl BufRead ) -> DcsvResult<VirtualArray>

Read csv value from buf read stream

This returns read value as virtual array struct

Trait Implementations§

source§

impl Default for Reader

source§

fn default() -> Self

Returns the “default value” for a type. Read more

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.