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
impl Reader
pub fn new() -> Self
sourcepub fn with_option(self, option: ReaderOption) -> Self
pub fn with_option(self, option: ReaderOption) -> Self
Build with reader option
sourcepub fn consume_dquote(self, tv: bool) -> Self
pub fn consume_dquote(self, tv: bool) -> Self
Consumes double quote in csv file
sourcepub fn ignore_empty_row(self, tv: bool) -> Self
pub fn ignore_empty_row(self, tv: bool) -> Self
Ignore empty rows
This prevents reader from panicking on empty row.
sourcepub fn allow_invalid_string(self, allow: bool) -> Self
pub fn allow_invalid_string(self, allow: bool) -> Self
Allow invalid string while parsing csv values
sourcepub fn has_header(self, has_header: bool) -> Self
pub fn has_header(self, has_header: bool) -> Self
Whether csv data has header or not
sourcepub fn custom_header<T: AsRef<str>>(self, headers: &[T]) -> Self
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.
sourcepub fn clear_reader_option(&mut self)
pub fn clear_reader_option(&mut self)
Clear reader option and set to default
sourcepub fn use_delimiter(self, delimiter: char) -> Self
pub fn use_delimiter(self, delimiter: char) -> Self
Use given delimiter instead of default one : “,”.
sourcepub fn use_space_delimiter(self, tv: bool) -> Self
pub fn use_space_delimiter(self, tv: bool) -> Self
Use space delimiter
sourcepub fn use_line_delimiter(self, delimiter: char) -> Self
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.
sourcepub fn data_from_stream(
&mut self,
csv_stream: impl BufRead
) -> DcsvResult<VirtualData>
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
sourcepub fn array_from_stream(
&mut self,
csv_stream: impl BufRead
) -> DcsvResult<VirtualArray>
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