Closed
Description
I'd like to test if a Weak
is done for without potentially incrementing an atomic refcount, because doing so is slow.
I want a faster alternative to Weak.upgrade().is_some()
.
also currently have this in my code: https://play.rust-lang.org/?gist=339c2c518a2d42aee7e5a585133427eb&version=stable
// since Weaks are completely useless...
// this checks if the arc and weak point to the same value without attempting to upgrade the weak.
// this is "safer" than trying to get the strong count
fn compare_arc_weak<T>(arc: &Arc<T>, weak: &Weak<T>) -> bool {
unsafe {
// we assume arc and weak have same size and alignment as usize
let arcusize: usize = mem::transmute_copy(arc);
let weakusize: usize = mem::transmute_copy(weak);
arcusize == weakusize
}
}