Trait Diff

Source
pub trait Diff: Debug {
    // Required method
    fn diff<D>(a: &Self, b: &Self, out: D) -> Result<D::Ok, D::Err>
       where D: Differ;
}
Expand description

A type that can be compared structurally to discover differences.

The job of a Diff impl is to use knowledge of the structure of some type (Self) to check two copies for differences, and report findings to a Differ.

Differ has methods for each different flavor of Rust type, and you can only call one of them (as they consume the Differ). So, the first task when implementing Diff is to decide which one to call.

Very simple types may just dispatch to same or difference, like this impl for a newtype around u32:

use visit_diff::{Diff, Differ};

#[derive(Debug)]
struct MyInt(u32);

impl Diff for MyInt {
    fn diff<D>(a: &Self, b: &Self, out: D) -> Result<D::Ok, D::Err>
    where D: Differ
    {
        if a.0 == b.0 {
            out.same(&a, &b)
        } else {
            out.difference(&a, &b)
        }
    }
}

use visit_diff::any_difference;

assert_eq!(any_difference(&MyInt(1), &MyInt(1)), false);
assert_eq!(any_difference(&MyInt(1), &MyInt(0)), true);

(Note: in reality, you’d probably want to #[derive(Diff)] for a type this simple.)

More complicated types would use other methods on Differ to describe their structure. See the documentation of that trait for more.

Required Methods§

Source

fn diff<D>(a: &Self, b: &Self, out: D) -> Result<D::Ok, D::Err>
where D: Differ,

Inspect a and b and tell out about any differences.

All (reasonable) implementations of this method have the same basic structure: they call a method on out, and then follow the instructions from that method to get a result.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl Diff for Ordering

Source§

fn diff<D>(a: &Self, b: &Self, out: D) -> Result<D::Ok, D::Err>
where D: Differ,

Source§

impl Diff for IpAddr

Source§

fn diff<D>(a: &Self, b: &Self, out: D) -> Result<D::Ok, D::Err>
where D: Differ,

Source§

impl Diff for SocketAddr

Source§

fn diff<D>(a: &Self, b: &Self, out: D) -> Result<D::Ok, D::Err>
where D: Differ,

Source§

impl Diff for SeekFrom

Source§

fn diff<D>(a: &Self, b: &Self, out: D) -> Result<D::Ok, D::Err>
where D: Differ,

Source§

impl Diff for ErrorKind

Source§

fn diff<D>(a: &Self, b: &Self, out: D) -> Result<D::Ok, D::Err>
where D: Differ,

Source§

impl Diff for bool

Source§

fn diff<D>(a: &Self, b: &Self, out: D) -> Result<D::Ok, D::Err>
where D: Differ,

Source§

impl Diff for char

Source§

fn diff<D>(a: &Self, b: &Self, out: D) -> Result<D::Ok, D::Err>
where D: Differ,

Source§

impl Diff for f32

Source§

fn diff<D>(a: &Self, b: &Self, out: D) -> Result<D::Ok, D::Err>
where D: Differ,

Source§

impl Diff for f64

Source§

fn diff<D>(a: &Self, b: &Self, out: D) -> Result<D::Ok, D::Err>
where D: Differ,

Source§

impl Diff for i8

Source§

fn diff<D>(a: &Self, b: &Self, out: D) -> Result<D::Ok, D::Err>
where D: Differ,

Source§

impl Diff for i16

Source§

fn diff<D>(a: &Self, b: &Self, out: D) -> Result<D::Ok, D::Err>
where D: Differ,

Source§

impl Diff for i32

Source§

fn diff<D>(a: &Self, b: &Self, out: D) -> Result<D::Ok, D::Err>
where D: Differ,

Source§

impl Diff for i64

Source§

fn diff<D>(a: &Self, b: &Self, out: D) -> Result<D::Ok, D::Err>
where D: Differ,

Source§

impl Diff for i128

Source§

fn diff<D>(a: &Self, b: &Self, out: D) -> Result<D::Ok, D::Err>
where D: Differ,

Source§

impl Diff for isize

Source§

fn diff<D>(a: &Self, b: &Self, out: D) -> Result<D::Ok, D::Err>
where D: Differ,

Source§

impl Diff for str

Source§

fn diff<D>(a: &Self, b: &Self, out: D) -> Result<D::Ok, D::Err>
where D: Differ,

Source§

impl Diff for u8

Source§

fn diff<D>(a: &Self, b: &Self, out: D) -> Result<D::Ok, D::Err>
where D: Differ,

Source§

impl Diff for u16

Source§

fn diff<D>(a: &Self, b: &Self, out: D) -> Result<D::Ok, D::Err>
where D: Differ,

Source§

impl Diff for u32

Source§

fn diff<D>(a: &Self, b: &Self, out: D) -> Result<D::Ok, D::Err>
where D: Differ,

Source§

impl Diff for u64

Source§

fn diff<D>(a: &Self, b: &Self, out: D) -> Result<D::Ok, D::Err>
where D: Differ,

Source§

impl Diff for u128

Source§

fn diff<D>(a: &Self, b: &Self, out: D) -> Result<D::Ok, D::Err>
where D: Differ,

Source§

impl Diff for ()

Source§

fn diff<D>(a: &Self, b: &Self, out: D) -> Result<D::Ok, D::Err>
where D: Differ,

Source§

impl Diff for usize

Source§

fn diff<D>(a: &Self, b: &Self, out: D) -> Result<D::Ok, D::Err>
where D: Differ,

Source§

impl Diff for String

Source§

fn diff<D>(a: &Self, b: &Self, out: D) -> Result<D::Ok, D::Err>
where D: Differ,

Source§

impl Diff for Ipv4Addr

Source§

fn diff<D>(a: &Self, b: &Self, out: D) -> Result<D::Ok, D::Err>
where D: Differ,

Source§

impl Diff for Ipv6Addr

Source§

fn diff<D>(a: &Self, b: &Self, out: D) -> Result<D::Ok, D::Err>
where D: Differ,

Source§

impl Diff for SocketAddrV4

Source§

fn diff<D>(a: &Self, b: &Self, out: D) -> Result<D::Ok, D::Err>
where D: Differ,

Source§

impl Diff for SocketAddrV6

Source§

fn diff<D>(a: &Self, b: &Self, out: D) -> Result<D::Ok, D::Err>
where D: Differ,

Source§

impl Diff for RangeFull

Source§

fn diff<D>(a: &Self, b: &Self, out: D) -> Result<D::Ok, D::Err>
where D: Differ,

Source§

impl Diff for Duration

Source§

fn diff<D>(a: &Self, b: &Self, out: D) -> Result<D::Ok, D::Err>
where D: Differ,

Source§

impl<'a, T> Diff for Cow<'a, T>
where T: Clone + Diff,

Diff Cow by dereferencing.

Source§

fn diff<D>(a: &Self, b: &Self, out: D) -> Result<D::Ok, D::Err>
where D: Differ,

Source§

impl<'a, T: ?Sized + Diff> Diff for Ref<'a, T>

Source§

fn diff<D>(a: &Self, b: &Self, out: D) -> Result<D::Ok, D::Err>
where D: Differ,

Source§

impl<'a, T: ?Sized + Diff> Diff for RefMut<'a, T>

Source§

fn diff<D>(a: &Self, b: &Self, out: D) -> Result<D::Ok, D::Err>
where D: Differ,

Source§

impl<A> Diff for (A,)
where A: Diff,

Source§

fn diff<DD>(a: &Self, b: &Self, out: DD) -> Result<DD::Ok, DD::Err>
where DD: Differ,

Source§

impl<A, B> Diff for (A, B)
where A: Diff, B: Diff,

Source§

fn diff<DD>(a: &Self, b: &Self, out: DD) -> Result<DD::Ok, DD::Err>
where DD: Differ,

Source§

impl<A, B, C> Diff for (A, B, C)
where A: Diff, B: Diff, C: Diff,

Source§

fn diff<DD>(a: &Self, b: &Self, out: DD) -> Result<DD::Ok, DD::Err>
where DD: Differ,

Source§

impl<A, B, C, D> Diff for (A, B, C, D)
where A: Diff, B: Diff, C: Diff, D: Diff,

Source§

fn diff<DD>(a: &Self, b: &Self, out: DD) -> Result<DD::Ok, DD::Err>
where DD: Differ,

Source§

impl<A, B, C, D, E> Diff for (A, B, C, D, E)
where A: Diff, B: Diff, C: Diff, D: Diff, E: Diff,

Source§

fn diff<DD>(a: &Self, b: &Self, out: DD) -> Result<DD::Ok, DD::Err>
where DD: Differ,

Source§

impl<A, B, C, D, E, F> Diff for (A, B, C, D, E, F)
where A: Diff, B: Diff, C: Diff, D: Diff, E: Diff, F: Diff,

Source§

fn diff<DD>(a: &Self, b: &Self, out: DD) -> Result<DD::Ok, DD::Err>
where DD: Differ,

Source§

impl<A, B, C, D, E, F, G> Diff for (A, B, C, D, E, F, G)
where A: Diff, B: Diff, C: Diff, D: Diff, E: Diff, F: Diff, G: Diff,

Source§

fn diff<DD>(a: &Self, b: &Self, out: DD) -> Result<DD::Ok, DD::Err>
where DD: Differ,

Source§

impl<A, B, C, D, E, F, G, H> Diff for (A, B, C, D, E, F, G, H)
where A: Diff, B: Diff, C: Diff, D: Diff, E: Diff, F: Diff, G: Diff, H: Diff,

Source§

fn diff<DD>(a: &Self, b: &Self, out: DD) -> Result<DD::Ok, DD::Err>
where DD: Differ,

Source§

impl<A, B, C, D, E, F, G, H, I> Diff for (A, B, C, D, E, F, G, H, I)
where A: Diff, B: Diff, C: Diff, D: Diff, E: Diff, F: Diff, G: Diff, H: Diff, I: Diff,

Source§

fn diff<DD>(a: &Self, b: &Self, out: DD) -> Result<DD::Ok, DD::Err>
where DD: Differ,

Source§

impl<K> Diff for BTreeSet<K>
where K: Ord + Diff,

Source§

fn diff<D>(a: &Self, b: &Self, out: D) -> Result<D::Ok, D::Err>
where D: Differ,

Source§

impl<K> Diff for HashSet<K>
where K: Hash + Eq + Diff,

Source§

fn diff<D>(a: &Self, b: &Self, out: D) -> Result<D::Ok, D::Err>
where D: Differ,

Source§

impl<K, V> Diff for BTreeMap<K, V>
where K: Ord + Debug, V: Diff,

Source§

fn diff<D>(a: &Self, b: &Self, out: D) -> Result<D::Ok, D::Err>
where D: Differ,

Source§

impl<K, V> Diff for HashMap<K, V>
where K: Eq + Hash + Debug, V: Diff,

Source§

fn diff<D>(a: &Self, b: &Self, out: D) -> Result<D::Ok, D::Err>
where D: Differ,

Source§

impl<T> Diff for [T; 0]
where T: Diff,

Source§

fn diff<D>(a: &Self, b: &Self, out: D) -> Result<D::Ok, D::Err>
where D: Differ,

Source§

impl<T> Diff for [T; 1]
where T: Diff,

Source§

fn diff<D>(a: &Self, b: &Self, out: D) -> Result<D::Ok, D::Err>
where D: Differ,

Source§

impl<T> Diff for [T; 2]
where T: Diff,

Source§

fn diff<D>(a: &Self, b: &Self, out: D) -> Result<D::Ok, D::Err>
where D: Differ,

Source§

impl<T> Diff for [T; 3]
where T: Diff,

Source§

fn diff<D>(a: &Self, b: &Self, out: D) -> Result<D::Ok, D::Err>
where D: Differ,

Source§

impl<T> Diff for [T; 4]
where T: Diff,

Source§

fn diff<D>(a: &Self, b: &Self, out: D) -> Result<D::Ok, D::Err>
where D: Differ,

Source§

impl<T> Diff for [T; 5]
where T: Diff,

Source§

fn diff<D>(a: &Self, b: &Self, out: D) -> Result<D::Ok, D::Err>
where D: Differ,

Source§

impl<T> Diff for [T; 6]
where T: Diff,

Source§

fn diff<D>(a: &Self, b: &Self, out: D) -> Result<D::Ok, D::Err>
where D: Differ,

Source§

impl<T> Diff for [T; 7]
where T: Diff,

Source§

fn diff<D>(a: &Self, b: &Self, out: D) -> Result<D::Ok, D::Err>
where D: Differ,

Source§

impl<T> Diff for [T; 8]
where T: Diff,

Source§

fn diff<D>(a: &Self, b: &Self, out: D) -> Result<D::Ok, D::Err>
where D: Differ,

Source§

impl<T> Diff for [T; 9]
where T: Diff,

Source§

fn diff<D>(a: &Self, b: &Self, out: D) -> Result<D::Ok, D::Err>
where D: Differ,

Source§

impl<T> Diff for [T; 10]
where T: Diff,

Source§

fn diff<D>(a: &Self, b: &Self, out: D) -> Result<D::Ok, D::Err>
where D: Differ,

Source§

impl<T> Diff for [T; 11]
where T: Diff,

Source§

fn diff<D>(a: &Self, b: &Self, out: D) -> Result<D::Ok, D::Err>
where D: Differ,

Source§

impl<T> Diff for [T; 12]
where T: Diff,

Source§

fn diff<D>(a: &Self, b: &Self, out: D) -> Result<D::Ok, D::Err>
where D: Differ,

Source§

impl<T> Diff for [T; 13]
where T: Diff,

Source§

fn diff<D>(a: &Self, b: &Self, out: D) -> Result<D::Ok, D::Err>
where D: Differ,

Source§

impl<T> Diff for [T; 14]
where T: Diff,

Source§

fn diff<D>(a: &Self, b: &Self, out: D) -> Result<D::Ok, D::Err>
where D: Differ,

Source§

impl<T> Diff for [T; 15]
where T: Diff,

Source§

fn diff<D>(a: &Self, b: &Self, out: D) -> Result<D::Ok, D::Err>
where D: Differ,

Source§

impl<T> Diff for [T; 16]
where T: Diff,

Source§

fn diff<D>(a: &Self, b: &Self, out: D) -> Result<D::Ok, D::Err>
where D: Differ,

Source§

impl<T> Diff for [T; 17]
where T: Diff,

Source§

fn diff<D>(a: &Self, b: &Self, out: D) -> Result<D::Ok, D::Err>
where D: Differ,

Source§

impl<T> Diff for [T; 18]
where T: Diff,

Source§

fn diff<D>(a: &Self, b: &Self, out: D) -> Result<D::Ok, D::Err>
where D: Differ,

Source§

impl<T> Diff for [T; 19]
where T: Diff,

Source§

fn diff<D>(a: &Self, b: &Self, out: D) -> Result<D::Ok, D::Err>
where D: Differ,

Source§

impl<T> Diff for [T; 20]
where T: Diff,

Source§

fn diff<D>(a: &Self, b: &Self, out: D) -> Result<D::Ok, D::Err>
where D: Differ,

Source§

impl<T> Diff for [T; 21]
where T: Diff,

Source§

fn diff<D>(a: &Self, b: &Self, out: D) -> Result<D::Ok, D::Err>
where D: Differ,

Source§

impl<T> Diff for [T; 22]
where T: Diff,

Source§

fn diff<D>(a: &Self, b: &Self, out: D) -> Result<D::Ok, D::Err>
where D: Differ,

Source§

impl<T> Diff for [T; 23]
where T: Diff,

Source§

fn diff<D>(a: &Self, b: &Self, out: D) -> Result<D::Ok, D::Err>
where D: Differ,

Source§

impl<T> Diff for [T; 24]
where T: Diff,

Source§

fn diff<D>(a: &Self, b: &Self, out: D) -> Result<D::Ok, D::Err>
where D: Differ,

Source§

impl<T> Diff for [T; 25]
where T: Diff,

Source§

fn diff<D>(a: &Self, b: &Self, out: D) -> Result<D::Ok, D::Err>
where D: Differ,

Source§

impl<T> Diff for [T; 26]
where T: Diff,

Source§

fn diff<D>(a: &Self, b: &Self, out: D) -> Result<D::Ok, D::Err>
where D: Differ,

Source§

impl<T> Diff for [T; 27]
where T: Diff,

Source§

fn diff<D>(a: &Self, b: &Self, out: D) -> Result<D::Ok, D::Err>
where D: Differ,

Source§

impl<T> Diff for [T; 28]
where T: Diff,

Source§

fn diff<D>(a: &Self, b: &Self, out: D) -> Result<D::Ok, D::Err>
where D: Differ,

Source§

impl<T> Diff for [T; 29]
where T: Diff,

Source§

fn diff<D>(a: &Self, b: &Self, out: D) -> Result<D::Ok, D::Err>
where D: Differ,

Source§

impl<T> Diff for [T; 30]
where T: Diff,

Source§

fn diff<D>(a: &Self, b: &Self, out: D) -> Result<D::Ok, D::Err>
where D: Differ,

Source§

impl<T> Diff for [T; 31]
where T: Diff,

Source§

fn diff<D>(a: &Self, b: &Self, out: D) -> Result<D::Ok, D::Err>
where D: Differ,

Source§

impl<T> Diff for [T; 32]
where T: Diff,

Source§

fn diff<D>(a: &Self, b: &Self, out: D) -> Result<D::Ok, D::Err>
where D: Differ,

Source§

impl<T> Diff for &T
where T: Diff + ?Sized,

Diff references by dereferencing.

Source§

fn diff<D>(a: &Self, b: &Self, out: D) -> Result<D::Ok, D::Err>
where D: Differ,

Source§

impl<T> Diff for &mut T
where T: Diff + ?Sized,

Diff references by dereferencing.

Source§

fn diff<D>(a: &Self, b: &Self, out: D) -> Result<D::Ok, D::Err>
where D: Differ,

Source§

impl<T> Diff for [T]
where T: Diff,

Source§

fn diff<D>(a: &Self, b: &Self, out: D) -> Result<D::Ok, D::Err>
where D: Differ,

Source§

impl<T> Diff for Box<T>
where T: Diff,

Diff boxes by dereferencing.

Source§

fn diff<D>(a: &Self, b: &Self, out: D) -> Result<D::Ok, D::Err>
where D: Differ,

Source§

impl<T> Diff for Rc<T>
where T: Diff,

Diff Rcs by dereferencing.

Source§

fn diff<D>(a: &Self, b: &Self, out: D) -> Result<D::Ok, D::Err>
where D: Differ,

Source§

impl<T> Diff for Arc<T>
where T: Diff,

Diff Arcs by dereferencing.

Source§

fn diff<D>(a: &Self, b: &Self, out: D) -> Result<D::Ok, D::Err>
where D: Differ,

Source§

impl<T> Diff for Range<T>
where Range<T>: PartialEq + Debug,

Source§

fn diff<D>(a: &Self, b: &Self, out: D) -> Result<D::Ok, D::Err>
where D: Differ,

Source§

impl<T> Diff for RangeFrom<T>

Source§

fn diff<D>(a: &Self, b: &Self, out: D) -> Result<D::Ok, D::Err>
where D: Differ,

Source§

impl<T> Diff for RangeTo<T>
where RangeTo<T>: PartialEq + Debug,

Source§

fn diff<D>(a: &Self, b: &Self, out: D) -> Result<D::Ok, D::Err>
where D: Differ,

Source§

impl<T> Diff for RangeToInclusive<T>

Source§

fn diff<D>(a: &Self, b: &Self, out: D) -> Result<D::Ok, D::Err>
where D: Differ,

Source§

impl<T: Copy + Diff> Diff for Cell<T>

Source§

fn diff<D>(a: &Self, b: &Self, out: D) -> Result<D::Ok, D::Err>
where D: Differ,

Source§

impl<T: Diff> Diff for Option<T>

Source§

fn diff<D>(a: &Self, b: &Self, out: D) -> Result<D::Ok, D::Err>
where D: Differ,

Source§

impl<T: Diff> Diff for Wrapping<T>

Source§

fn diff<D>(a: &Self, b: &Self, out: D) -> Result<D::Ok, D::Err>
where D: Differ,

Source§

impl<T: Diff, E: Diff> Diff for Result<T, E>

Source§

fn diff<D>(a: &Self, b: &Self, out: D) -> Result<D::Ok, D::Err>
where D: Differ,

Source§

impl<T: ?Sized + Diff> Diff for RefCell<T>

Note that this will panic if the RefCell is mutably borrowed.

Source§

fn diff<D>(a: &Self, b: &Self, out: D) -> Result<D::Ok, D::Err>
where D: Differ,

Source§

impl<T: ?Sized + Diff> Diff for ManuallyDrop<T>

Source§

fn diff<D>(a: &Self, b: &Self, out: D) -> Result<D::Ok, D::Err>
where D: Differ,

Source§

impl<T: ?Sized> Diff for *const T

Pointers diff by address, not by contents.

Source§

fn diff<D>(a: &Self, b: &Self, out: D) -> Result<D::Ok, D::Err>
where D: Differ,

Source§

impl<T: ?Sized> Diff for *mut T

Pointers diff by address, not by contents.

Source§

fn diff<D>(a: &Self, b: &Self, out: D) -> Result<D::Ok, D::Err>
where D: Differ,

Source§

impl<T: ?Sized> Diff for PhantomData<T>

Source§

fn diff<D>(a: &Self, b: &Self, out: D) -> Result<D::Ok, D::Err>
where D: Differ,

Source§

impl<V> Diff for LinkedList<V>
where V: Diff,

Source§

fn diff<D>(a: &Self, b: &Self, out: D) -> Result<D::Ok, D::Err>
where D: Differ,

Source§

impl<V> Diff for VecDeque<V>
where V: Diff,

Source§

fn diff<D>(a: &Self, b: &Self, out: D) -> Result<D::Ok, D::Err>
where D: Differ,

Source§

impl<V> Diff for Vec<V>
where V: Diff,

Source§

fn diff<D>(a: &Self, b: &Self, out: D) -> Result<D::Ok, D::Err>
where D: Differ,

Implementors§