Struct InputStreamBuilder

Source
pub struct InputStreamBuilder { /* private fields */ }

Implementations§

Source§

impl InputStreamBuilder

Source

pub fn from_readers<I>(readers: I) -> InputStreamBuilder
where I: IntoIterator<Item = ReaderSource>,

Start a transformation chain from a set of csv creaders.

This is what you need in case your CSVs are not comma separated or you need to adjust some parameters like escape character.

§Example
use csvsc::prelude::*;
use csv::ReaderBuilder;
use encoding::all::UTF_8;

let mut chain = InputStreamBuilder::from_readers(vec![
    ReaderBuilder::new()
        .delimiter(b';')
        .from_path("test/assets/1.csv")
        .unwrap().into(),
    ReaderBuilder::new()
        .delimiter(b';')
        .from_path("test/assets/2.csv")
        .unwrap().into(),
]).build().unwrap();
Source

pub fn from_paths<I, P>(paths: I) -> Result<InputStreamBuilder>
where I: IntoIterator<Item = P>, P: AsRef<Path>,

Start a transformation chain from a set of paths in the filesystem.

This is probably the easiest way to get started. It assumes comma separated fields, double quotes as field wrap and some other sensible defaults from csv crate

§Example
use csvsc::prelude::*;

let mut chain = InputStreamBuilder::from_paths(&[
    "test/assets/chicken_north.csv",
    "test/assets/chicken_south.csv",
]).unwrap().build().unwrap();

From there you can chain the methods of the RowStream trait.

Source

pub fn with_encoding(self, encoding: EncodingRef) -> Self

Use this encoding to decode the input files

§Example
use csvsc::prelude::*;
use encoding::all::WINDOWS_1252;

let mut chain = InputStreamBuilder::from_paths(&[
    "test/assets/windows1252/data.csv",
]).unwrap().with_encoding(WINDOWS_1252).build().unwrap();
Source

pub fn with_source_col(self, colname: &str) -> Self

Add a column with this name to every row with the path to the file where it comes from.

§Example
use csvsc::prelude::*;

let mut chain = InputStreamBuilder::from_paths(&[
    "test/assets/1.csv",
]).unwrap().with_source_col("source").build().unwrap().into_iter();

assert_eq!(chain.next().unwrap().unwrap(), Row::from(vec!["1", "3", "test/assets/1.csv"]));
Source

pub fn build(self) -> Result<InputStream>

Build the InputStream from the parameters of this builder and return it.

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.