pub struct Key<T> { /* private fields */ }Expand description
A handle into an Arena<T>.
Phantom-typed, so a Key<Face> cannot be used to index an Arena<Edge>.
The marker is fn() -> T so the key stays Copy, Send and Sync
regardless of T.
Implementations§
Source§impl<T> Key<T>
impl<T> Key<T>
Sourcepub const fn scope(self) -> u32
pub const fn scope(self) -> u32
Which arena issued this key.
UNSCOPED for a key that has not been bound to one.
Sourcepub const fn with_scope(self, scope: u32) -> Self
pub const fn with_scope(self, scope: u32) -> Self
This key, bound to the arena with the given identifier.
For a deserializer, which rebuilds handles before it has an arena to bind them to. Nothing else should need it: a key that came from an arena already names the right one, and moving a key between arenas is the mistake the scope exists to catch.
Sourcepub const fn generation(self) -> u32
pub const fn generation(self) -> u32
Generation stamp, used to detect a key outliving its slot.
Sourcepub const fn from_parts(index: u32, generation: u32) -> Self
pub const fn from_parts(index: u32, generation: u32) -> Self
A key naming a given slot, for reading a document back from a file.
Deliberately narrow. Forging a handle is precisely what generations
exist to prevent, and Arena::insert is what issues one within a
process. But a file records the handles a document was written with, and
a reader that could not rebuild them would have to renumber everything,
which is to say, hand back a different document.
A key made this way is not trusted: it resolves through Arena::get
like any other, so a stale or out-of-range one comes back None rather
than aliasing whatever sits at that index.