forall T, 'r.
struct Region! { ... }
The right to access one block holding a T, under brand 'r.
Allocation! (alloc::owned) is the right to free a block; Region! is the right to access it, under the same brand.
Methods
method from_rawsource
unsafe fn from_raw(ptr: *T, cap: Exclusive!['r]) -> Region![T, 'r] { ... }
A region over the T at ptr, under the capability cap.
The way into a region over memory this module did not allocate: alloc::owned's Allocation!::adopt, or a program's own storage. Caller: ptr is not null, also for a zero-size T (share makes a Ref of it, which is never null), and points at an initialized T, aligned for T, in at least sizeof[T]() bytes, that nothing else can reach while 'r lives; and cap is the only capability over 'r -- in practice, fresh from Exclusive!::fresh, so no existing Ref of brand 'r describes other memory. The region's replace and share read and write the T with no further check.
method retiresource
fn retire(self) -> () { ... }
Ends the region and its domain: the capability is retired, so no Ref of brand 'r can be used again. The storage is untouched; whoever holds the matching Allocation! decides what happens to it, which is why release and close take the whole region.
method replacesource
fn replace(&self, val: T) -> T { ... }
Reads the contained T out and writes a new one in, exactly once each way: the only access operation a region has that does not give the region up. There is no Region!::with, because Ref::with already has that shape, and getting to a Ref is what share (below) is for.
No witness parameter: holding a Region![T,'r] is already proof that nothing else can touch this block, because a region is linear, unique, and consumed by every operation that could hand out a second capability over the same brand -- and Allocation!::close/release, which reclaim the storage, demand the region itself.
Sound for any T, Copy or linear, for Ref::with's reason: the previous value is moved out and returned to the caller, val is moved in, and neither is duplicated or discarded here.
method splitsource
fn split(self) -> (Restore![T, 'r], foreach *F of *T => exists 'f. (Region![F, 'f], Link!['f, 'r])) { ... }
Splits the region into the receipt that merges it back and one sub-region per field of T, each under a fresh brand and tied to the parent by a Link!.
Each sub-region is usable (ordinarily via Region!::share) without any two sub-regions' Exclusive!s being interchangeable. split gives up the region's capability to the receipt and builds every Link! from the parent brand read from that capability, so the parts of one split are made once, here.
A part does NOT bundle an Exclusive! (exists 'f. (Exclusive!['f], Region![F,'f], Link!['f,'r])): a caller could Region::share the part's region to mint a SECOND live Exclusive!['f] beside the bundled one, and two live writers for one brand is a safe use-after-free and double free. A part's writer is obtained the ordinary way, by calling share on its Region![F,'f].
No new brand for 'r: the caller's Region![T,'r] already proves everything needed. The fresh brands the parts are minted under are the per-field ones, each strictly smaller in scope than 'r.