Skip to content

Commit 7212359

Browse files
committed
Add [strong|weak]_count to [A]RcBorrow
1 parent b948db0 commit 7212359

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

crates/rc-borrow/src/lib.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,18 @@ macro_rules! rc_borrow {
162162
unsafe { &*this.raw.as_ptr() }
163163
}
164164

165+
/// Get the number of strong owning pointers to this allocation.
166+
$vis fn strong_count(this: Self) -> usize {
167+
let rc = unsafe { ManuallyDrop::new($Rc::from_raw(Self::into_raw(this))) };
168+
$Rc::strong_count(&rc)
169+
}
170+
171+
/// Get the number of weak owning pointers to this allocation.
172+
$vis fn weak_count(this: Self) -> usize {
173+
let rc = unsafe { ManuallyDrop::new($Rc::from_raw(Self::into_raw(this))) };
174+
$Rc::weak_count(&rc)
175+
}
176+
165177
/// Get a raw pointer that can be used with `from_raw`.
166178
$vis fn into_raw(this: Self) -> *const T {
167179
ManuallyDrop::new(this).raw.as_ptr()

0 commit comments

Comments
 (0)