dynpartialeq

PartialEq for trait objects

This crate provides macros for deriving PartialEq for Box<dyn Trait>, removing the boilerplate of having to provide your own implementations. Inspired by this blog post: https://dev.to/magnusstrale/rust-trait-objects-in-a-vector-non-trivial-4co5

Add the crate to your project:

sh cargo add dyn_partial_eq

```rust use dynpartialeq::*;

// Use this to add a DynPartialEq supertrait and implement PartialEq for your trait.

[dynpartialeq]

trait SomeTrait {}

// Derive DynPartialEq and PartialEq on your types that implement your trait.

[derive(DynPartialEq, PartialEq)]

struct A(usize); impl SomeTrait for A {}

[derive(DynPartialEq, PartialEq)]

struct B((usize, usize)); impl SomeTrait for B {} ```

And voila:

```rust let boxedazero: Box = Box::new(A(0)); let boxedaone: Box = Box::new(A(1)); let boxed_b: Box = Box::new(B((1, 2)));

asserteq!(&boxedazero == &boxedazero, true); asserteq!(&boxedazero == &boxedaone, false); asserteq!(&boxedazero == &boxedb, false);

asserteq!(&boxedaone == &boxedazero, false); asserteq!(&boxedaone == &boxedaone, true); asserteq!(&boxedaone == &boxedb, false);

asserteq!(&boxedb == &boxedazero, false); asserteq!(&boxedb == &boxedaone, false); asserteq!(&boxedb == &boxed_b, true); ```