import Std.Rc
Types
Rc
type Rc t =
ptr: Ptr (U32, t)
A non-threadsafe reference-counted pointer.
Rc.of
Rc.of (value: t): Rc t
Rc.as_ref
Rc.as_ref (rc: imm Rc t): ref t
Returns a shared reference into the inner element. Since other Rc clones of
the same value may exist and may mutate the element via [Rc.as_mut], this
can only be a shared ref reference instead of a fully immutable imm
reference. Similarly, requiring a uniq Rc t ensures this Rc is not dropped
while the returned reference is still alive.
Rc.as_mut
Rc.as_mut (rc: uniq Rc t): mut t
Returns a shared, mutable reference into the inner element. Since other Rc
clones of the same value may exist and may mutate the element through this
function, this can only give a shared mut reference instead of a uniq
reference. Similarly, requiring a uniq Rc t ensures this Rc is not dropped
while the returned reference is still alive.
Rc.try_unwrap
Rc.try_unwrap (var rc: Rc t): Result t (Rc t)
If the reference count is 1, unwraps the Rc returning the value directly.
Otherwise, returns Error rc with the original Rc value.
If you always need to extract the inner value from the Rc, consider
using Rc.unwrap_or_clone which will clone the inner value in the shared case
instead of returning an error.
Rc.unwrap_or_clone
Rc.unwrap_or_clone (rc: Rc t) {_: Clone t}: t
If the reference count is 1, unwraps the Rc returning the value directly. Otherwise, clones the inner value.
Functions
ref_count
ref_count (rc: ref Rc t): U32
inc_ref_count
inc_ref_count (rc: mut Rc t): Unit
dec_ref_count
dec_ref_count (rc: mut Rc t): Unit