forall T, 'r.
struct Allocation! { ... }
The right to free one heap block, under brand 'r.
Freeing goes through release(self, reg: Region![T, 'r]) (or release_storage, or close and Owned!::into_value), which takes no Ref: the base address comes from self, and the only producers of an Allocation! are Allocation!::adopt and adopt_value, which read it straight off the allocator's Uninit!. The record is restricted, and no exported function turns a pointer, a Ref or a Brand into one, so freeing an interior pointer projected from a Ref is not expressible.
Carries the extent as well as the base so that release can hand back an Uninit! with its size intact; without it every adopt/release round trip would reset the size to zero.
Kept separate from Region!: close/release demand the complete region back, and merging the two would put the deallocation record and the access-recovery token in one value.
Methods
method adoptsource
unsafe fn adopt(u: Uninit!) -> exists '1. (Allocation![T, '1], Region![T, '1]) { ... }
Takes ownership of u and returns an allocation record together with the Region! over the block.
The brand '1 is fresh per call and returned sealed, so no caller can name it in advance or ask for a record over a brand that already exists. The base and extent are read off u, never supplied by the caller, and kept in the linear, restricted, unprojectable record; the access side goes out separately as the Region!.
Caller: the block holds an initialized T, aligned for T, in at least sizeof[T]() bytes, since the region lets safe code read and write the block as a T (Region!::replace, share and the Ref it hands out). u's base is a malloc result, so alignment holds for every type the language has; the size and the contents are the caller's word. adopt_value checks the size and writes the T itself.
method adopt_valuesource
fn adopt_value(u: Uninit!, v: T) -> exists '1. (Allocation![T, '1], Region![T, '1]) { ... }
Writes v into the block u owns and returns an allocation record together with the Region! over it.
adopt, made safe: aborts unless u's recorded extent is at least sizeof[T]() bytes, then writes v at the block's base, so the region is over an initialized T. An Uninit! from adopt_raw records extent 0 and so aborts here for any T with bytes.
method release_storagesource
unsafe fn release_storage(self, reg: Region![T, 'r]) -> Uninit! { ... }
Retires the brand and hands back raw, unbranded storage without reading the T in the block. release is the safe form, for a Copy T; for any other, giving the block up unread would drop a linear value.
Caller: every T the block holds is accounted for: moved out, never written, or still tracked by the caller, which keeps the returned storage and what is in it (Vec! releases to grow and adopts the block again over the same elements).
Demands the complete Region![T,'r], not merely a witness. A region is consumed by share and rebuilt only by RegionResume!::resume, which demands the exact Exclusive!['r] back, so presenting one proves every access capability of this brand has been returned. self and reg must name the same 'r, which no caller can arrange for two unrelated allocations because adopt seals a fresh brand per call.
The returned Uninit! carries the extent adopt recorded, so a caller can release, grow and re-adopt without restating the size.
method closesource
fn close(self, reg: Region![T, 'r]) -> Owned![T] { ... }
Owned!::open's exact inverse: retires the brand and hands back sole ownership of the block as an Owned![T].
Demands the complete Region![T,'r]. close checks nothing; the guarantee is what can exist at the call site. The region is linear and unique, the only way to get an access capability from it is share, which consumes it, and only resume -- given the exact Exclusive!['r] share handed out -- rebuilds it. So presenting the region proves every access capability of this brand has come back, and using the region after close is rejected because close consumed it.
Drops self's extent, since Owned![T] records its size in its type. For a record from Owned!::open that is exact. For one from adopt or adopt_value over a larger block, close narrows the claim to sizeof[T](). That cannot break a free (free takes no size, and Owned!'s only terminal path is into_value -> adopt_raw -> free), and the block holds the initialized T that adopt's obligation, or adopt_value's write, put there.
method releasesource
fn release(self, reg: Region![T, 'r]) -> Uninit! { ... }
Retires the brand and hands back raw, unbranded storage; the T in the block is given up, which a Copy value may be. A linear T comes back through close and Owned!::into_value instead, or, for storage whose contents the caller tracks itself, the unsafe release_storage. Demands the complete region, as release_storage does, and the Uninit! carries the extent adopt recorded.