[][src]Struct fcc::Concat

pub struct Concat<P: AsRef<Path>> { /* fields omitted */ }

A structure for configuring how files are concatenated.

Generally speaking, when using Concat, you'll first call new, then chain calls to methods to set each configuration, then call open, passing the paths of files you're trying to concatenate. And eventually, call write to actually concatenate files and write the result.

Examples

Concatenates the contents of two CSV files and prints the result:

use fcc::{Concat, Result};

fn main() -> Result<()> {
    let paths = vec!["foo.csv", "bar.csv"];
    let concat = Concat::new().newline(true).header(true).pad_with(b"---delimiter---\n").open(paths);
    concat.write(&mut std::io::stdout());
    Ok(())
}

Implementations

impl<P: AsRef<Path>> Concat<P>[src]

pub fn new() -> Self[src]

Constructs a new empty Concat instance.

Examples

use fcc::{Concat, Result};

fn main() -> Result<()> {
    let mut concat = Concat::new();
    let concat = concat.newline(true).header(true).open(vec!["foo.csv", "bar.csv"]);
    concat.write(&mut std::io::stdout())?;
    Ok(())
}

pub fn open(&self, paths: Vec<P>) -> Self[src]

Fills the Concat instance with the given paths.

Note that this function does not check the validities of the given paths.

Examples

use fcc::{Concat, Result};

fn main() -> Result<()> {
    let mut concat = Concat::new();
    let concat = concat.newline(true).header(true).open(vec!["foo.csv", "bar.csv"]);
    concat.write(&mut std::io::stdout())?;
    Ok(())
}

pub fn newline(&mut self, newline: bool) -> &mut Self[src]

Sets the option to append a newline ('\n') for each file if the file is not already ended with a newline.

Examples

use fcc::{Concat, Result};

fn main() -> Result<()> {
    let mut concat = Concat::new();
    let concat = concat.header(true).open(vec!["foo.csv", "bar.csv"]);
    concat.write(&mut std::io::stdout())?;
    Ok(())
}

pub fn skip_start(&mut self, skip: usize) -> &mut Self[src]

Controls how many lines are skipped from the beginning of each file while concatenating.

Examples

use fcc::{Concat, Result};

fn main() -> Result<()> {
    let mut concat = Concat::new();
    let concat = concat.skip_start(1).open(vec!["foo.csv", "bar.csv"]);
    concat.write(&mut std::io::stdout())?;
    Ok(())
}

pub fn skip_end(&mut self, skip: usize) -> &mut Self[src]

Controls how many lines are skipped from the end of each file while concatenating.

Examples

use fcc::{Concat, Result};

fn main() -> Result<()> {
    let mut concat = Concat::new();
    let concat = concat.skip_end(1).open(vec!["foo.csv", "bar.csv"]);
    concat.write(&mut std::io::stdout())?;
    Ok(())
}

pub fn header(&mut self, header: bool) -> &mut Self[src]

Sets the option to extract the header of each file and put the first extracted header to the beginning of concatenation result.

Note that this method will also set skip_start to 1 simultaneously due to its semantics. In other words, header(true) is equivalent to header(true).skip_start(1). If you are intended to skip more than one line from the beginning of each file, remember to set skip_start option after setting header(true).

Examples

use fcc::{Concat, Result};

fn main() -> Result<()> {
    let mut concat = Concat::new();
    let concat = concat.header(true).open(vec!["foo.csv", "bar.csv"]);
    concat.write(&mut std::io::stdout())?;
    Ok(())
}

pub fn pad_with(&mut self, padding: &[u8]) -> &mut Self[src]

Fills some padding between the contents of each file.

Examples

use fcc::{Concat, Result};

fn main() -> Result<()> {
    let mut concat = Concat::new();
    let concat = concat.pad_with(b"some padding").open(vec!["foo.csv", "bar.csv"]);
    concat.write(&mut std::io::stdout())?;
    Ok(())
}

pub fn use_crlf(&mut self, crlf: bool) -> &mut Self[src]

Use \r\n for newline instead of \n.

Examples

use fcc::{Concat, Result};

fn main() -> Result<()> {
    let mut concat = Concat::new();
    let concat = concat.newline(true).use_crlf(true).open(vec!["foo.csv", "bar.csv"]);
    concat.write(&mut std::io::stdout())?;
    Ok(())
}

pub fn get_header(&self) -> Result<Vec<u8>>[src]

Retrieves the header of the first passed-in file.

Example

use fcc::{Concat, Result};
fn main() -> Result<()> {
    let concat = Concat::new().open(vec!["foo.csv", "bar.csv"]);
    let header = concat.get_header()?;
    println!("{:?}", header);
    Ok(())
}

pub fn write<W: Write>(self, writer: &mut W) -> Result<()>[src]

Triggers the file concatenation process and writes the result.

Examples

use fcc::{Concat, Result};

fn main() -> Result<()> {
    let mut concat = Concat::new();
    let concat = concat.header(true).pad_with(b"some padding").open(vec!["foo.csv", "bar.csv"]);
    concat.write(&mut std::io::stdout())?;
    Ok(())
}

Trait Implementations

impl<P: Clone + AsRef<Path>> Clone for Concat<P>[src]

impl<P: Debug + AsRef<Path>> Debug for Concat<P>[src]

Auto Trait Implementations

impl<P> RefUnwindSafe for Concat<P> where
    P: RefUnwindSafe

impl<P> Send for Concat<P> where
    P: Send

impl<P> Sync for Concat<P> where
    P: Sync

impl<P> Unpin for Concat<P> where
    P: Unpin

impl<P> UnwindSafe for Concat<P> where
    P: UnwindSafe

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,