You can upgrade it to an Rc, use into_raw to obtain a pointer, then use from_raw to avoid leaking the Rc. You can then cache this pointer next to your Weak.
is that the redundancy of having the pointer twice (since a Weak<T> is currently implemented as a *const T pointer but with an offset), can be transparently removed in the implementation without affecting the API, once rc::Weak::as_raw gets stabilized:
impl<T> CanHashWeak<T> {
// pub /* if you want */
fn ptr (self: &'_ Self) -> *const T
{
self.weak.as_raw()
}
}
Note that if you impl Hash on some type T, any operation works with &T must not change its hash value. The std::collection::HashMap's api is built on this assumption. This is why the RefCell<T> doesn't impl Hash. Approach using Weak::upgrade() is not valid for this reason