Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 29 additions & 6 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,25 @@ impl<T> HConsed<T> {
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<T> {
self.elm.clone()
}

/// Exposes the underlying reference.
#[inline]
pub fn as_arc(&self) -> &Arc<T> {
&self.elm
}

/// Generates a weak version of the underlying reference.
pub fn to_weak_ref(&self) -> Weak<T> {
Arc::downgrade(&self.elm)
}

/// Creates a weak version of itself.
#[inline]
pub fn to_weak(&self) -> WHConsed<T> {
WHConsed {
Expand All @@ -318,15 +336,14 @@ impl<T> HConsed<T> {
}
}

/// Weak reference version.
pub fn to_weak_ref(&self) -> Weak<T> {
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<T: fmt::Debug> fmt::Debug for HConsed<T> {
Expand All @@ -351,18 +368,22 @@ impl<T> PartialEq for HConsed<T> {
}
}
impl<T> Eq for HConsed<T> {}

#[allow(clippy::non_canonical_partial_ord_impl)]
impl<T> PartialOrd for HConsed<T> {
#[inline]
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
self.uid.partial_cmp(&other.uid)
}
}

impl<T> Ord for HConsed<T> {
#[inline]
fn cmp(&self, other: &Self) -> Ordering {
self.uid.cmp(&other.uid)
}
}

impl<T: Hash> Hash for HConsed<T> {
#[inline]
fn hash<H>(&self, state: &mut H)
Expand Down Expand Up @@ -438,6 +459,8 @@ impl<T> PartialEq for WHConsed<T> {
}
}
impl<T> Eq for WHConsed<T> {}

#[allow(clippy::non_canonical_partial_ord_impl)]
impl<T> PartialOrd for WHConsed<T> {
#[inline]
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
Expand Down
2 changes: 1 addition & 1 deletion tests/try_build/issue_1.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down