I have a struct that all store readonly references, for example:
struct Pt { x : f32, y : f32, }
struct Tr<'a> { a : &'a Pt }
I want to impl Eq
for Tr
to test if the underlaying a
reference to exactly the same Pt
:
let trBase1 = Pt::new(0.0, 0.0);
let trBase2 = Pt::new(0.0, 0.0);
assert!(trBase1 == trBase2); // ok.
let tr1 = Tr::new(&trBase1);
let tr2 = Tr::new(&trBase2);
let tr3 = Tr::new(&trBase1);
assert!(tr1 == tr3); // ok.
assert!(tr1.a == te2.a); // ok. Using Eq for Pt that compare values.
assert!(tr1 != tr2); // panicked! Not intended.
so now I have
impl<'a> PartialEq for Tr<'a> {
fn eq(&self, v : &Tr<'a>) -> bool {
// self.a == v.a // doesn't work.
}
}
what should I write?