I am trying to make my own custom typed pointer but I can't seem to make it comparable. I narrowed my code to this:
use std::marker::PhantomData;
#[derive(PartialEq, Copy, Clone)]
pub struct PhantomPair<PHANTOM, REAL: Copy + Clone + PartialEq> {
real: REAL,
phantom: PhantomData<PHANTOM>,
}
impl<PHANTOM, REAL: Copy + Clone + PartialEq> PhantomPair<PHANTOM, REAL> {
pub fn new(data: REAL) -> Self {
PhantomPair {
real: data,
phantom: PhantomData,
}
}
}
fn is_eq<PHANTOM, REAL: Copy + Clone + PartialEq>(
a: PhantomPair<PHANTOM, REAL>,
b: PhantomPair<PHANTOM, REAL>,
) -> bool {
a == b
}
fn main() {}
The compiler gives the following error:
error[E0369]: binary operation `==` cannot be applied to type `PhantomPair<PHANTOM, REAL>`
--> src/main.rs:22:5
|
22 | a == b
| ^^^^^^
|
= note: an implementation of `std::cmp::PartialEq` might be missing for `PhantomPair<PHANTOM, REAL>`
I expected PhantomPair
to have a derived PartialEq
that uses REAL
's PartialEq
. As far as I know, PhantomData
also implements PartialEq
basically assuming equality.
The same issue happens when I try to add PartialOrd
to #[derive]
and to REAL
's constraints.