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

Source

pub fn with_capacity(capacity: usize) -> Self

Source

pub fn insert(&mut self, value: T) -> Id<T>

Insert a value and return its handle. 插入一个值并返回其句柄。

Source

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

Source

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

Source

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

Source

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

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

Source

pub fn len(&self) -> usize

Source

pub fn is_empty(&self) -> bool

Source

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

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.