Std.Rc

import Std.Rc

Source


Types


Rc

type Rc t =
    ptr: Ptr (U32, t)

A non-threadsafe reference-counted pointer.

source


Rc.of

Rc.of (value: t): Rc t

source


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.

source


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.

source


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.

source


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.

source


Functions


ref_count

ref_count (rc: ref Rc t): U32

source


inc_ref_count

inc_ref_count (rc: mut Rc t): Unit

source


dec_ref_count

dec_ref_count (rc: mut Rc t): Unit

source


Implicits


Show Implicits

clone_rc

impl clone_rc: Clone (Rc t)

source


drop_rc

impl drop_rc {_: Drop t e}: Drop (Rc t) e

source