tim-harding / soa-rs

An SoA library for Rust
MIT License
113 stars 2 forks source link

Add support for cases when PartialEq is not implemented #8

Closed PPakalns closed 7 months ago

PPakalns commented 7 months ago

Allow Soars derive macro to be used with types that do not implement PartialEq for all fields

tim-harding commented 7 months ago

This is a nice convenience, but there is a correctness issue with it. PartialEq guarantees transitivity, which may not hold, depending on the implementation for T. For example:

#[derive(Soars)]
struct Example(u8);

impl PartialEq for Example {
    fn eq(&self, other: &Self) -> bool {
        true
    }
}

fn main() {
    assert_eq!(Example(0), Example(1)); // okay
    assert_eq!(Example(1), ExampleRef(1)); // okay
    assert_eq!(Example(0), ExampleRef(1)); // panic
}

This project has taught me there are a lot of subtleties like this to be wary of in Rust.