Struct admerge::FileMerger[][src]

pub struct FileMerger<'a>(_);

Simliar to RsMerger but provides dedicated methods to work with Paths and Files.

Implementations

impl<'a> FileMerger<'a>[src]

pub fn new() -> Self[src]

Creates a new FileMerger builder.

pub fn skip_head(&mut self, skip: Skip<'a>) -> &mut Self[src]

Configures this merger to skip partial of contents from the head of each file.

pub fn skip_tail(&mut self, skip: Skip<'a>) -> &mut Self[src]

Configures this merger to skip partial of contents from the tail of each file.

pub fn pad_with(&mut self, padding: Pad<'a>) -> &mut Self[src]

Configures this merger to fill some padding before, between or after the file contents.

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

Configures this merger to force the presence of ending newline after each file.

pub fn with_paths<P, W>(&self, paths: Vec<P>, writer: &mut W) -> Result<()> where
    P: AsRef<Path>,
    W: Write
[src]

Opens file paths given and merges file contents into the given writer according to the given configrations.

Nothing that this method will return an error if any path given is not point to a regular file. For an variant that ignores invalid paths, see with_paths_lossy.

Example

use admerge::{FileMerger, Skip, Pad, Newline, Result};
use std::fs::OpenOptions;

fn main() -> Result<()> {
    let mut file = OpenOptions::new().append(true).create(true).open("merged.txt")?;

    // Configures merger.
    let mut merger = FileMerger::new();
    merger.skip_tail(Skip::LinesOnce(1));
    merger.pad_with(Pad::Before(b"leading contents\n"));
    merger.force_ending_newline(Newline::Lf);

    // Merges sources into one.
    merger.with_paths(vec!["foo.txt", "bar.txt", "baz.txt"], &mut file)?;

    Ok(())
}

Errors

Returns an error variant of ErrorKind::NothingPassed if the given path vector is empty;

Returns an error variant of ErrorKind::InvalidPath if the given paths contain invalid path.

Returns an error variant of ErrorKind::InvalidSkip if the given Skips cannot applied to the given sources;

Returns an error variant of ErrorKind::Io if any I/O errors were encountered.

pub fn with_paths_lossy<P, W>(
    &self,
    paths: Vec<P>,
    writer: &mut W
) -> Result<()> where
    P: AsRef<Path>,
    W: Write
[src]

Opens every file path given if path points to a regular file, and then merges file contents into the given writer according to the given configrations.

See also with_paths.

Example

use admerge::{FileMerger, Skip, Pad, Newline, Result};
use std::fs::OpenOptions;

fn main() -> Result<()> {
    let mut file = OpenOptions::new().append(true).create(true).open("merged.txt")?;

    // Configures merger.
    let mut merger = FileMerger::new();
    merger.skip_tail(Skip::LinesOnce(1));
    merger.pad_with(Pad::Before(b"leading contents\n"));
    merger.force_ending_newline(Newline::Lf);

    // Merges sources into one.
    merger.with_paths_lossy(vec!["foo.txt", "bar.txt", "not a file path"], &mut file)?;

    Ok(())
}

Errors

Returns an error variant of ErrorKind::NothingPassed if the given path vector is empty;

Returns an error variant of ErrorKind::InvalidSkip if the given Skips cannot applied to the given sources;

Returns an error variant of ErrorKind::Io if any I/O errors were encountered.

pub fn with_files<W>(&self, files: Vec<File>, writer: &mut W) -> Result<()> where
    W: Write
[src]

Reads sequentially from the given files and merges their contents into the given writer according to the given configrations.

Example

use admerge::{FileMerger, Skip, Pad, Newline, Result};
use std::fs::{File, OpenOptions};

fn main() -> Result<()> {
    let f1 = File::open("foo.txt")?;
    let f2 = File::open("bar.txt")?;
    let f3 = File::open("baz.txt")?;
    let mut file = OpenOptions::new().append(true).create(true).open("merged.txt")?;

    // Configures merger.
    let mut merger = FileMerger::new();
    merger.skip_tail(Skip::LinesOnce(1));
    merger.pad_with(Pad::Before(b"leading contents\n"));
    merger.force_ending_newline(Newline::Lf);

    // Merges sources into one.
    merger.with_files(vec![f1, f2, f3], &mut file)?;

    Ok(())
}

Errors

Returns an error variant of ErrorKind::NothingPassed if the given path vector is empty;

Returns an error variant of ErrorKind::InvalidSkip if the given Skips cannot applied to the given sources;

Returns an error variant of ErrorKind::Io if any I/O errors were encountered.

Trait Implementations

impl<'a> Clone for FileMerger<'a>[src]

impl<'a> Debug for FileMerger<'a>[src]

impl<'a> Default for FileMerger<'a>[src]

Auto Trait Implementations

impl<'a> RefUnwindSafe for FileMerger<'a>

impl<'a> Send for FileMerger<'a>

impl<'a> Sync for FileMerger<'a>

impl<'a> Unpin for FileMerger<'a>

impl<'a> UnwindSafe for FileMerger<'a>

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.