Re-exported from core::mem::Ref.
forall T, 'k.
struct Ref { ... }
A description of the place of a T in domain 'k, read or written by presenting that domain's capability.
Ref only ever stores a pointer, never T inline, so it is Copy whatever T is: both Ref[u32, 'k] and Ref[Owned!, 'k] are Copy.
Ref is restricted because pairing an arbitrary pointer with an arbitrary brand is itself authority once one capability covers a whole domain (Exclusive!['k], StaticRead). Without it, safe code could re-brand any pointer it can read off a view (Slice::into_parts, Ref::into_parts) -- e.g. wrap a stale slice's pointer as a Ref of a live brand and read it through an unrelated Exclusive! of that brand, or forge a 'static view of heap memory. from_raw below is the only way in from another module.
The pointer is a NonNull: a Ref always describes a live T, so an Option[Ref[T, 'k]] (or a list's link) is one word.
Methods
method from_rawsource
unsafe fn from_raw(ptr: *T, marker: Brand['k]) -> Ref[T, 'k] { ... }
A Ref to the T at ptr, in the domain marker names.
The one way to build a Ref outside this module. Caller: ptr points at a live T inside the domain marker names, so that presenting that domain's capability (with, copy, read) really authorizes the access. So ptr is never null.
method into_partssource
fn into_parts(self) -> (*T, Brand['k]) { ... }
The pointer and brand of this Ref.
The safe inverse of from_raw, like Slice::into_parts: the pointer and brand grant nothing by themselves, and turning them back into a Ref needs from_raw again.
method addresssource
fn address(self) -> usize { ... }
The address this Ref describes, for identity comparisons (a.address() == b.address()). Safe: it reads no memory, and turning an address back into a pointer needs an unsafe cast. Values of a zero-size T have no bytes and may share an address.
method withsource
forall Ret, C, R where Access[C -> 'k, R], Sized[T].
fn with(self, &cx: C, f: closure(T) -> (T, Ret)) -> Ret { ... }
Calls f on the value, moved out, and puts back the value f returns, under the capability cx lends.
Requires presenting the live Exclusive! of the matching brand, lent by a context that holds it (core::cap::Access); nothing about self or the capability is inspected at runtime, the brand match is already enforced by the call's own type-check.
method updatesource
forall Ret, C, R where Access[C -> 'k, R], Sized[T].
fn update(self, &cx: C, f: closure(&_: T) -> Ret) -> Ret { ... }
Calls f on the value where it lives: f gets it through & and its changes land in place, with no copy of the value in or out. The same witness as with.
method replacesource
forall C, R where Access[C -> 'k, R], Sized[T].
fn replace(self, &cx: C, val: T) -> T { ... }
Puts val in the place and hands back the value that was there: with's store, with no closure. The same witness as with.
method update_insource
forall X, Ret, C, R where Access[C -> 'k, R], Sized[T].
fn update_in(self, &cx: C, &other: X, f: closure(&_: T, &_: X) -> Ret) -> Ret { ... }
update, with a second place other lent to f beside the value (lend_in).
method copysource
forall C, R where Access[C -> 'k, R].
fn copy(self, &cx: C) -> T { ... }
A copy of the value, read under the capability cx lends.
with's most common case: read the current value without changing it. T comes from r's own type, so a bare r.copy(&tag) needs no annotation. Needs T: Copy because the value is handed back as the result while also staying in place, which duplicates it.
method setsource
forall C, R where Access[C -> 'k, R].
fn set(self, &cx: C, val: T) { ... }
Puts val in the place; the value there before is dropped, which T: Copy allows. replace hands it back.
method readsource
forall 'q.
fn read(self, &cx: Shared!['k, 'q]) -> T { ... }
A copy of the value, read through one node of the domain's shared-read tree. Any node will do: they all permit reading, and none permits writing.