Struct csvsc::input::InputStreamBuilder
source · [−]pub struct InputStreamBuilder { /* private fields */ }
Implementations
sourceimpl InputStreamBuilder
impl InputStreamBuilder
sourcepub fn from_readers<I>(readers: I) -> InputStreamBuilder where
I: IntoIterator<Item = ReaderSource>,
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();
sourcepub fn from_paths<I, P>(paths: I) -> Result<InputStreamBuilder> where
I: IntoIterator<Item = P>,
P: AsRef<Path>,
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.
sourcepub fn with_encoding(self, encoding: EncodingRef) -> Self
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();
sourcepub fn with_source_col(self, colname: &str) -> Self
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"]));
sourcepub fn build(self) -> Result<InputStream>
pub fn build(self) -> Result<InputStream>
Build the InputStream
from the parameters of this builder and return
it.
Auto Trait Implementations
impl !RefUnwindSafe for InputStreamBuilder
impl Send for InputStreamBuilder
impl Sync for InputStreamBuilder
impl Unpin for InputStreamBuilder
impl !UnwindSafe for InputStreamBuilder
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more