Say I've got the following code
- From a library
struct OtherParent(..);
struct OtherChild(..);
impl Deref for OtherParent {
type Target = OtherChild;
// ...
}
- and then in my own code
#[repr(transparent)]
struct Parent(OtherParent);
#[repr(transparent)]
struct Child(OtherChild);
impl Deref for Parent {
type Target = Child;
fn deref(&self) -> &Self::Target {
unsafe { mem::transmute::<&OtherChild, &Child>(&*self.0) }
}
}
So I'm derefing to OtherChild
and then just reinterpreting that as Child
since their representation is the same? Is this correct? Is there a better way of achieving what I'm trying to achieve (shadowing the Deref with my newtypes)?