pub struct Rooted<'s> { /* private fields */ }Expand description
A GcRef proven rooted for 's — the only input to a &mut Payload
accessor.
A Rooted<'s> cannot outlive the NativeScope that produced it, and the
accessors’ results cannot outlive the Rooted, so the whole chain is bounded
by a scope that is itself in the collector’s root set. An accessor taking a
bare GcRef and handing back a &'static mut Payload would say the payload
outlives the program, and let a helper keep writing through one across an
allocation that reclaimed its owner.
It carries the reference by value, and that is what makes it survive the
store’s growth. A Rooted that held a *mut GcRef into
NativeRootStore would be the natural shape — Drop could then clear its
own slot — and it would be wrong: the store reallocs, so a later root() in
any live scope can move the array out from under every Rooted handed out
before it. Holding the value instead means growth is invisible here. What the
store owes a Rooted is not an address but a promise — that the reference is
somewhere in [0, len) for as long as the scope lives — and moving the array
does not break that promise.