I've a set of layers over other layers, where the basemost layer structure is a one-element tuple struct over a std::rc::Weak
.
According to the ByAddress's README, the ByAddress
type works for any type that implements Deref
.
I've gave a little look at this part of the source code:
impl<T> ByAddress<T>
where
T: ?Sized + Deref,
{
/// Convenience method for pointer casts.
fn addr(&self) -> *const T::Target {
&*self.0
}
/// Convert `&T` to `&ByAddress<T>`.
pub fn from_ref(r: &T) -> &Self {
// SAFETY: `struct ByAddress` is `repr(transparent)`.
unsafe {
&*(r as *const T as *const Self)
}
}
}
Will something like ByAddress(weak_pointer)
and ByAddress(Layer2(Layer1(weak_pointer))
work for taking the address of weak_pointer
rather than what the layers directly dereference to?