[][src]Trait csvsc::RowStream

pub trait RowStream: IntoIterator<Item = RowResult> {
    fn headers(&self) -> &Headers;

    fn add(self, column: ColSpec) -> Result<Add<Self>, BuildError>
    where
        Self: Sized
, { ... }
fn del(self, columns: Vec<&str>) -> Del<Self>
    where
        Self: Sized
, { ... }
fn add_with<F>(
        self,
        colname: &str,
        f: F
    ) -> Result<AddWith<Self, F>, BuildError>
    where
        Self: Sized,
        F: FnMut(&Headers, &Row) -> Result<String, BuildError>
, { ... }
fn reduce(
        self,
        columns: Vec<Box<dyn Aggregate>>
    ) -> Result<Reduce<Self>, BuildError>
    where
        Self: Sized
, { ... }
fn adjacent_group<H, F, R>(
        self,
        header_map: H,
        f: F,
        grouping: &[&str]
    ) -> Result<AdjacentGroup<Self, F>, GroupBuildError>
    where
        H: FnMut(Headers) -> Headers,
        F: FnMut(MockStream<IntoIter<RowResult>>) -> R,
        R: RowStream,
        Self: Sized
, { ... }
fn group<H, F, R>(
        self,
        header_map: H,
        f: F,
        grouping: &[&str]
    ) -> Result<Group<Self, F>, GroupBuildError>
    where
        H: FnMut(Headers) -> Headers,
        F: FnMut(MockStream<IntoIter<RowResult>>) -> R,
        R: RowStream,
        Self: Sized
, { ... }
fn flush(self, target: FlushTarget) -> Result<Flush<Self>, Error>
    where
        Self: Sized
, { ... }
fn inspect<F>(self, f: F) -> Inspect<Self, F>
    where
        Self: Sized,
        F: FnMut(&Headers, &RowResult)
, { ... }
fn rename(self, name_map: &HashMap<&str, &str>) -> Rename<Self>
    where
        Self: Sized
, { ... }
fn map_row<F>(self, f: F) -> MapRow<Self, F>
    where
        Self: Sized,
        F: Fn(&Headers, &Row) -> RowResult
, { ... }
fn map_col<F>(self, col: String, f: F) -> MapCol<Self, F>
    where
        Self: Sized,
        F: Fn(&str) -> Result<String, BuildError>
, { ... } }

This trait describes de behaviour of every component in the CSV transformation chain. Functions provided by this trait help construct the chain and can be chained.

Implement this trait to extend csvsc with your own processors.

Required methods

fn headers(&self) -> &Headers

Must return headers as they are in this point of the chain. For example if implementor adds a column, its headers() function must return the new headers including the one just added.

Loading content...

Provided methods

fn add(self, column: ColSpec) -> Result<Add<Self>, BuildError> where
    Self: Sized

Allows adding columns to each row of the stream.

fn del(self, columns: Vec<&str>) -> Del<Self> where
    Self: Sized

Deletes the specified columns from each row of the stream

fn add_with<F>(
    self,
    colname: &str,
    f: F
) -> Result<AddWith<Self, F>, BuildError> where
    Self: Sized,
    F: FnMut(&Headers, &Row) -> Result<String, BuildError>, 

Adds a column to each row of the stream using a closure to compute its value

fn reduce(
    self,
    columns: Vec<Box<dyn Aggregate>>
) -> Result<Reduce<Self>, BuildError> where
    Self: Sized

Group by one or more columns, compute aggregates and output the resulting columns

fn adjacent_group<H, F, R>(
    self,
    header_map: H,
    f: F,
    grouping: &[&str]
) -> Result<AdjacentGroup<Self, F>, GroupBuildError> where
    H: FnMut(Headers) -> Headers,
    F: FnMut(MockStream<IntoIter<RowResult>>) -> R,
    R: RowStream,
    Self: Sized

fn group<H, F, R>(
    self,
    header_map: H,
    f: F,
    grouping: &[&str]
) -> Result<Group<Self, F>, GroupBuildError> where
    H: FnMut(Headers) -> Headers,
    F: FnMut(MockStream<IntoIter<RowResult>>) -> R,
    R: RowStream,
    Self: Sized

fn flush(self, target: FlushTarget) -> Result<Flush<Self>, Error> where
    Self: Sized

When consumed, writes to destination specified by the column given in the first argument. Other than that this behaves like an id(x) function so you can specify more links in the chain and even more flushers.

fn inspect<F>(self, f: F) -> Inspect<Self, F> where
    Self: Sized,
    F: FnMut(&Headers, &RowResult), 

Mostly for debugging, calls a closure on each element. Behaves like the identity function on the stream returning each row untouched.

fn rename(self, name_map: &HashMap<&str, &str>) -> Rename<Self> where
    Self: Sized

Renames some columns

fn map_row<F>(self, f: F) -> MapRow<Self, F> where
    Self: Sized,
    F: Fn(&Headers, &Row) -> RowResult

Apply a function to an entire row

fn map_col<F>(self, col: String, f: F) -> MapCol<Self, F> where
    Self: Sized,
    F: Fn(&str) -> Result<String, BuildError>, 

Apply a function to a single column of the stream, this function dones't fail if the column dones't exist.

Loading content...

Implementors

impl RowStream for InputStream[src]

impl<'a, I> RowStream for Del<'a, I> where
    I: RowStream
[src]

impl<I> RowStream for Add<I> where
    I: RowStream
[src]

impl<I> RowStream for MockStream<I> where
    MockStream<I>: IntoIterator<Item = RowResult>, 
[src]

impl<I> RowStream for Reduce<I> where
    Reduce<I>: IntoIterator<Item = RowResult>, 
[src]

impl<I> RowStream for Rename<I> where
    I: RowStream
[src]

impl<I, F> RowStream for AddWith<I, F> where
    I: RowStream,
    F: FnMut(&Headers, &Row) -> Result<String, BuildError>, 
[src]

impl<I, F> RowStream for Inspect<I, F> where
    I: RowStream,
    F: FnMut(&Headers, &RowResult), 
[src]

impl<I, F> RowStream for MapCol<I, F> where
    I: RowStream,
    F: Fn(&str) -> Result<String, BuildError>, 
[src]

impl<I, F> RowStream for MapRow<I, F> where
    I: RowStream,
    F: Fn(&Headers, &Row) -> RowResult
[src]

impl<I, F, R> RowStream for AdjacentGroup<I, F> where
    I: RowStream,
    F: FnMut(MockStream<IntoIter<RowResult>>) -> R,
    R: RowStream
[src]

impl<I, F, R> RowStream for Group<I, F> where
    I: RowStream,
    F: FnMut(MockStream<IntoIter<RowResult>>) -> R,
    R: RowStream
[src]

Loading content...