diff --git a/src/lib.rs b/src/lib.rs index c00789c..faba1b5 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -309,7 +309,25 @@ impl HConsed { pub fn uid(&self) -> u64 { self.uid } - /// Turns a hashconsed thing in a weak hashconsed thing. + + /// Clones the underlying reference. + #[inline] + pub fn to_arc(&self) -> Arc { + self.elm.clone() + } + + /// Exposes the underlying reference. + #[inline] + pub fn as_arc(&self) -> &Arc { + &self.elm + } + + /// Generates a weak version of the underlying reference. + pub fn to_weak_ref(&self) -> Weak { + Arc::downgrade(&self.elm) + } + + /// Creates a weak version of itself. #[inline] pub fn to_weak(&self) -> WHConsed { WHConsed { @@ -318,15 +336,14 @@ impl HConsed { } } - /// Weak reference version. - pub fn to_weak_ref(&self) -> Weak { - Arc::downgrade(&self.elm) - } - /// Number of (strong) references to this term. pub fn arc_count(&self) -> usize { Arc::strong_count(&self.elm) } + /// Number of weak references to this term. + pub fn weak_count(&self) -> usize { + Arc::weak_count(&self.elm) + } } impl fmt::Debug for HConsed { @@ -351,18 +368,22 @@ impl PartialEq for HConsed { } } impl Eq for HConsed {} + +#[allow(clippy::non_canonical_partial_ord_impl)] impl PartialOrd for HConsed { #[inline] fn partial_cmp(&self, other: &Self) -> Option { self.uid.partial_cmp(&other.uid) } } + impl Ord for HConsed { #[inline] fn cmp(&self, other: &Self) -> Ordering { self.uid.cmp(&other.uid) } } + impl Hash for HConsed { #[inline] fn hash(&self, state: &mut H) @@ -438,6 +459,8 @@ impl PartialEq for WHConsed { } } impl Eq for WHConsed {} + +#[allow(clippy::non_canonical_partial_ord_impl)] impl PartialOrd for WHConsed { #[inline] fn partial_cmp(&self, other: &Self) -> Option { diff --git a/tests/try_build/issue_1.stderr b/tests/try_build/issue_1.stderr index 379a339..32ece33 100644 --- a/tests/try_build/issue_1.stderr +++ b/tests/try_build/issue_1.stderr @@ -33,7 +33,7 @@ note: required because it's used within this closure 37 | s.spawn(move |_| { | ^^^^^^^^ note: required by a bound in `crossbeam_utils::thread::Scope::<'env>::spawn` - --> $CARGO/crossbeam-utils-0.8.16/src/thread.rs + --> $CARGO/crossbeam-utils-0.8.19/src/thread.rs | | pub fn spawn<'scope, F, T>(&'scope self, f: F) -> ScopedJoinHandle<'scope, T> | ----- required by a bound in this associated function