Skip to main content

IPoliciedID

Trait IPoliciedID 

Source
pub trait IPoliciedID:
    Copy
    + Eq
    + Debug {
    type ObjectT: Sized;
    type PolicyT: IAllocPolicy;
    type BackID: IEntityAllocID<Self::ObjectT, Self::PolicyT>;

    // Required methods
    fn from_backend(ptr: Self::BackID) -> Self;
    fn into_backend(self) -> Self::BackID;

    // Provided methods
    fn try_deref_alloc(
        self,
        alloc: &IDBoundAlloc<Self>,
    ) -> Option<&Self::ObjectT> { ... }
    fn try_deref_alloc_mut(
        self,
        alloc: &mut IDBoundAlloc<Self>,
    ) -> Option<&mut Self::ObjectT> { ... }
    fn deref_alloc(self, alloc: &IDBoundAlloc<Self>) -> &Self::ObjectT { ... }
    fn deref_alloc_mut(
        self,
        alloc: &mut IDBoundAlloc<Self>,
    ) -> &mut Self::ObjectT { ... }
}
Expand description

Trait for ID wrappers that carry an associated object type and allocation policy.

This trait provides a uniform interface for ID types used by the crate’s APIs. An implementor represents an ID type that is bound to a concrete ObjectT and PolicyT. The BackID associated type is a backend ID that actually implements the conversion and dereference logic (for example PtrID or IndexedID).

Implementations must be Copy and Eq. The trait exposes helpers to convert to/from the backend representation and to dereference given an IDBoundAlloc (an EntityAlloc specialized to the ID’s object/policy).

该 trait 用于将不同的 ID 表示(指针型或索引型)抽象为统一的接口,绑定对象类型与分配策略, 便于上层 API 泛化处理 ID。

Required Associated Types§

Source

type ObjectT: Sized

The object type this ID references.

Source

type PolicyT: IAllocPolicy

The allocation policy this ID is associated with.

Source

type BackID: IEntityAllocID<Self::ObjectT, Self::PolicyT>

The backend ID type that implements the actual logic.

Required Methods§

Source

fn from_backend(ptr: Self::BackID) -> Self

Create this ID from its backend representation.

Source

fn into_backend(self) -> Self::BackID

Convert this ID into its backend representation.

Provided Methods§

Source

fn try_deref_alloc(self, alloc: &IDBoundAlloc<Self>) -> Option<&Self::ObjectT>

Try to dereference the object this ID points to, returning None if invalid.

Source

fn try_deref_alloc_mut( self, alloc: &mut IDBoundAlloc<Self>, ) -> Option<&mut Self::ObjectT>

Try to mutably dereference the object this ID points to, returning None if invalid.

Source

fn deref_alloc(self, alloc: &IDBoundAlloc<Self>) -> &Self::ObjectT

Dereference the object this ID points to, panicking if invalid.

Source

fn deref_alloc_mut(self, alloc: &mut IDBoundAlloc<Self>) -> &mut Self::ObjectT

Mutably dereference the object this ID points to, panicking if invalid.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§