Expand description
Type alias for a local reference counting pointer.
Provided to ease migrating from std::rc::Rc
.
See the module-level documentation for more details.
The inherent methods of Rc
are all associated functions, which means that you have to call
them as e.g. Rc::to_shared(&x)
instead of x.to_shared()
. This avoids conflicts with
methods of the inner type T
.
Implementations
sourceimpl<T: ?Sized> Rc<T>
impl<T: ?Sized> Rc<T>
Creates a new shared reference (Arc
) for the referenced value.
Example
use hybrid_rc::{Rc, Arc};
let local = Rc::new(42i32);
let shared = Rc::to_shared(&local);
// `shared` can be safely transferred to another thread
std::thread::spawn(move || assert_eq!(*shared, 42i32)).join()?;
Creates a new pinned shared reference for the referenced value.
Example
use hybrid_rc::{Rc, Weak};
let strong = Rc::pin(42i32);
let shared = Rc::to_shared_pin(&strong);
assert!(Rc::ptr_eq_pin(&strong, &shared));
sourcepub unsafe fn increment_local_strong_count(ptr: *const T)
pub unsafe fn increment_local_strong_count(ptr: *const T)
Increments the local strong reference count on the Rc<T>
associated by the given pointer
Increases the local strong reference count as if a new Rc
was cloned and kept alive.
May panic in the unlikely case the platform-specific maximum for the reference count is
reached.
Safety
The pointer must have been obtained through HybridRc<T, Local>::into_raw()
, the value
must still be live and have a local strong count of at least 1 when this method is invoked
and this call must be performed on the same thread as where the original Rc
was created.
sourcepub unsafe fn decrement_local_strong_count(ptr: *const T)
pub unsafe fn decrement_local_strong_count(ptr: *const T)
Decrements the local strong reference count on the Rc<T>
associated by the given pointer
If the local strong reference counter reaches 0, the value is no longer considered owned by the calling thread and if there are no shared strong references to keep the value alive, it will be dropped.
Safety
The pointer must have been obtained through HybridRc<T, Local>::into_raw()
, the value
must still be live and have a local strong count of at least 1 when this method is invoked
and this call must be performed on the same thread as where the original Rc
was created.