Skip to main content

Arena

Struct Arena 

Source
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>

Source

pub fn new() -> Self

Create an empty arena. 创建一个空 arena。

Source

pub fn with_capacity(capacity: usize) -> Self

Create an empty arena with storage reserved for capacity values. 创建一个预留 capacity 个值存储空间的空 arena。

Source

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.

Source

pub fn get(&self, id: Id<T>) -> Option<&T>

Fetch a live value by handle. 按句柄获取存活的值。

Source

pub fn get_mut(&mut self, id: Id<T>) -> Option<&mut T>

Fetch a live value by handle, for mutation. 按句柄获取存活的值,用于修改。

Source

pub fn contains(&self, id: Id<T>) -> bool

Whether id currently refers to a live value. id 当前是否指向一个存活的值。

Source

pub fn remove(&mut self, id: Id<T>) -> Option<T>

Remove a value, invalidating the handle. 移除一个值,并使该句柄失效。

Source

pub fn len(&self) -> usize

The number of live values. 存活值的数量。

Source

pub fn is_empty(&self) -> bool

Whether the arena holds no live values. arena 是否不含任何存活值。

Source

pub fn iter(&self) -> impl Iterator<Item = (Id<T>, &T)>

Iterate over all live (id, value) pairs in slot order. 按槽位顺序遍历所有存活的 (id, value) 对。

Source

pub fn iter_mut(&mut self) -> impl Iterator<Item = (Id<T>, &mut T)>

Mutably iterate over all live (id, value) pairs in slot order. 按槽位顺序可变地遍历所有存活的 (id, value) 对。

Trait Implementations§

Source§

impl<T: Clone> Clone for Arena<T>

Source§

fn clone(&self) -> Arena<T>

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T: Debug> Debug for Arena<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T> Default for Arena<T>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<T> Freeze for Arena<T>
where Vec<Slot<T>>: Freeze,

§

impl<T> RefUnwindSafe for Arena<T>
where Vec<Slot<T>>: RefUnwindSafe,

§

impl<T> Send for Arena<T>
where Vec<Slot<T>>: Send,

§

impl<T> Sync for Arena<T>
where Vec<Slot<T>>: Sync,

§

impl<T> Unpin for Arena<T>
where Vec<Slot<T>>: Unpin,

§

impl<T> UnsafeUnpin for Arena<T>
where Vec<Slot<T>>: UnsafeUnpin,

§

impl<T> UnwindSafe for Arena<T>
where Vec<Slot<T>>: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.