Struct csv_pipeline::Pipeline

source ·
pub struct Pipeline<'a> {
    pub headers: Headers,
    /* private fields */
}
Expand description

The main thing

Fields§

§headers: Headers

Implementations§

Create a pipeline from a CSV or TSV file.

Adds a column with values computed from the closure for each row.

Example
use csv_pipeline::Pipeline;

Pipeline::from_path("test/AB.csv")
  .unwrap()
  .add_col("C", |headers, row| {
    Ok("1".to_string())
  });

Maps each row.

Example
use csv_pipeline::Pipeline;

let csv = Pipeline::from_path("test/AB.csv")
  .unwrap()
  .map(|headers, row| {
    Ok(row.into_iter().map(|field| field.to_string() + "0").collect())
  })
  .collect_into_string()
  .unwrap();

assert_eq!(csv, "A,B\n10,20\n"
);

Maps each field of a column.

Example
use csv_pipeline::Pipeline;

let csv = Pipeline::from_path("test/Countries.csv")
  .unwrap()
  .map_col("Country", |field| Ok(field.to_uppercase()))
  .collect_into_string()
  .unwrap();

assert_eq!(
  csv,
  "ID,Country\n\
    1,NORWAY\n\
    2,TUVALU\n"
);

Panics if a new name already exists

Example
use csv_pipeline::Pipeline;

let csv = Pipeline::from_path("test/AB.csv")
  .unwrap()
  .rename_col("A", "X")
  .collect_into_string()
  .unwrap();

assert_eq!(csv, "X,B\n1,2\n");

Panics if a new name already exists

Example
use csv_pipeline::Pipeline;

let csv = Pipeline::from_path("test/AB.csv")
  .unwrap()
  .rename_cols(|i, name| {
    match name {
      "A" => "X",
      name => name,
    }
  })
  .collect_into_string()
  .unwrap();

assert_eq!(csv, "X,B\n1,2\n");

Group and reduce rows into. Panics if the transform results in duplicate column names.

Example
use csv_pipeline::Pipeline;

let csv = Pipeline::from_path("test/AB.csv")
  .unwrap()
  .rename_cols(|i, name| {
    match name {
      "A" => "X",
      name => name,
    }
  })
  .collect_into_string()
  .unwrap();

assert_eq!(csv, "X,B\n1,2\n");

Write to the specified Target.

Example
use csv_pipeline::{Pipeline, Target};

let mut csv = String::new();
Pipeline::from_path("test/AB.csv")
  .unwrap()
  .flush(Target::string(&mut csv))
  .run()
  .unwrap();

assert_eq!(csv, "A,B\n1,2\n");

Turn the pipeline into an iterator. You can also do this using pipeline.into_iter().

Shorthand for .build().run().

Trait Implementations§

The type of the elements being iterated over.
Which kind of iterator are we turning this into?
Creates an iterator from a value. Read more

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.