Struct CsvByteDiff

Source
pub struct CsvByteDiff<T: CsvHashTaskSpawner> { /* private fields */ }
Expand description

Compare two CSVs lazily with each other (for the eager-/blocking-based variant, see CsvByteDiffLocal).

Use this instead of CsvByteDiffLocal, when:

  • you own your CSV data and you want to use an Iterator for the differences, so you don’t have to read all differences into memory
  • your CSV data structure does not support Seek.

By default, CsvByteDiff uses a rayon thread-pool to compare differences. If you already have an existing rayon thread-pool that you want to use for CsvByteDiff, you can construct it with a builder (see also rayon_thread_pool on CsvByteDiffBuilder). for using an existing rayon thread-pool when creating CsvByteDiff.

§Example: create CsvByteDiff with default values and compare two CSVs byte-wise lazily

use csv_diff::{csv_diff::CsvByteDiff, csv::Csv};
use csv_diff::diff_row::{ByteRecordLineInfo, DiffByteRecord};
use std::collections::HashSet;
use std::iter::FromIterator;
// some csv data with a header, where the first column is a unique id
let csv_left = "\
header1,header2,header3\n\
a,b,c";
let csv_right = "\
header1,header2,header3\n\
a,b,d";

let csv_diff = CsvByteDiff::new()?;

let mut diff_iterator = csv_diff.diff(
    Csv::with_reader(csv_left.as_bytes()),
    Csv::with_reader(csv_right.as_bytes()),
);

let diff_row_actual = diff_iterator
    .next()
    .ok_or("Expected a difference between the two CSVs, but got none".to_string())??;

let diff_row_expected = DiffByteRecord::Modify {
    delete: ByteRecordLineInfo::new(csv::ByteRecord::from(vec!["a", "b", "c"]), 2),
    add: ByteRecordLineInfo::new(csv::ByteRecord::from(vec!["a", "b", "d"]), 2),
    field_indices: vec![2],
};

assert_eq!(diff_row_actual, diff_row_expected);

Ok(())

Implementations§

Source§

impl CsvByteDiff<CsvHashTaskSpawnerRayon>

Source

pub fn new() -> Result<Self, CsvDiffNewError>

Source§

impl<T> CsvByteDiff<T>

Source

pub fn diff<R: Read + Send + 'static>( &self, csv_left: Csv<R>, csv_right: Csv<R>, ) -> DiffByteRecordsIterator ⓘ

Trait Implementations§

Source§

impl<T: Debug + CsvHashTaskSpawner> Debug for CsvByteDiff<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<T> !Freeze for CsvByteDiff<T>

§

impl<T> !RefUnwindSafe for CsvByteDiff<T>

§

impl<T> Send for CsvByteDiff<T>
where T: Send,

§

impl<T> !Sync for CsvByteDiff<T>

§

impl<T> Unpin for CsvByteDiff<T>
where T: Unpin,

§

impl<T> UnwindSafe for CsvByteDiff<T>
where T: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

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

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> ToOwned for T

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.