pub trait DiffInPlace<T, const N: usize>where
    T: PartialEq,{
    // Required method
    fn try_diff_in_place<F, R>(&self, other: &[T; N], func: F) -> Result<(), R>
       where F: FnMut(usize, &[T]) -> Result<(), R>;

    // Provided method
    fn diff_in_place<F>(&self, other: &[T; N], func: F)
       where F: FnMut(usize, &[T]) { ... }
}

Required Methods§

source

fn try_diff_in_place<F, R>(&self, other: &[T; N], func: F) -> Result<(), R>where F: FnMut(usize, &[T]) -> Result<(), R>,

Fallible version of diff_in_place for propagating errors. Perform an in-place diff between two const-size arrays, invoking the given function for each run of different elements, with the index into the array and the slice of different elements from the other array.

Arguments
  • other - The other array to compare against.
  • func - The function to call for each run of different elements.
Example
    use diff_in_place::DiffInPlace;
    let a = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
    let mut b = [0, 0, 1, 2, 0, 0, 0, 3, 4, 5];

    a.try_diff_in_place(&b, |idx, diff| -> Result<(), ()> {
        // println!("{}: {:?}", idx, diff);
        // Prints:
        // 2: [1, 2]
        // 7: [3, 4, 5]
        Ok(())
    }).unwrap();

Provided Methods§

source

fn diff_in_place<F>(&self, other: &[T; N], func: F)where F: FnMut(usize, &[T]),

Perform an in-place diff between two const-size arrays, invoking the given function for each run of different elements, with the index into the array and the slice of different elements from the other array.

Arguments
  • other - The other array to compare against.
  • func - The function to call for each run of different elements.
Example
    use diff_in_place::DiffInPlace;
    let a = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
    let mut b = [0, 0, 1, 2, 0, 0, 0, 3, 4, 5];

    a.diff_in_place(&b, |idx, diff| {
        // println!("{}: {:?}", idx, diff);
        // Prints:
        // 2: [1, 2]
        // 7: [3, 4, 5]
    });

Object Safety§

This trait is not object safe.

Implementations on Foreign Types§

source§

impl<T, const N: usize> DiffInPlace<T, N> for [T; N]where T: PartialEq + Copy,

source§

fn try_diff_in_place<F, R>(&self, other: &[T; N], func: F) -> Result<(), R>where F: FnMut(usize, &[T]) -> Result<(), R>,

Implementors§