pub struct Arena<T> { /* private fields */ }Expand description
A generational arena: dense storage with reuse of freed slots and stale-handle detection. 代际 arena:密集存储,支持空闲槽位复用与过期句柄检测。
This is the ownership primitive behind meshes, textures, and render objects. 这是网格、纹理和渲染对象背后的所有权原语。 It is intentionally a small self-contained type so it can be swapped for an external slot map without touching call sites. 它刻意做成一个小而自包含的类型,以便可以在不改动调用方的情况下替换为外部的槽位映射。
Implementations§
Source§impl<T> Arena<T>
impl<T> Arena<T>
Sourcepub fn with_capacity(capacity: usize) -> Self
pub fn with_capacity(capacity: usize) -> Self
Create an empty arena with storage reserved for capacity values.
创建一个预留 capacity 个值存储空间的空 arena。
Sourcepub fn insert(&mut self, value: T) -> Id<T>
pub fn insert(&mut self, value: T) -> Id<T>
Insert a value and return its handle. 插入一个值并返回其句柄。
§Panics
当活跃槽位数量超过 u32 上限时 panic(实践中不可能达到)。
Panics if the number of live slots exceeds the u32 index space.
Sourcepub fn get_mut(&mut self, id: Id<T>) -> Option<&mut T>
pub fn get_mut(&mut self, id: Id<T>) -> Option<&mut T>
Fetch a live value by handle, for mutation. 按句柄获取存活的值,用于修改。
Sourcepub fn contains(&self, id: Id<T>) -> bool
pub fn contains(&self, id: Id<T>) -> bool
Whether id currently refers to a live value.
id 当前是否指向一个存活的值。
Sourcepub fn remove(&mut self, id: Id<T>) -> Option<T>
pub fn remove(&mut self, id: Id<T>) -> Option<T>
Remove a value, invalidating the handle. 移除一个值,并使该句柄失效。