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§
Sourcetype PolicyT: IAllocPolicy
type PolicyT: IAllocPolicy
The allocation policy this ID is associated with.
Sourcetype BackID: IEntityAllocID<Self::ObjectT, Self::PolicyT>
type BackID: IEntityAllocID<Self::ObjectT, Self::PolicyT>
The backend ID type that implements the actual logic.
Required Methods§
Sourcefn from_backend(ptr: Self::BackID) -> Self
fn from_backend(ptr: Self::BackID) -> Self
Create this ID from its backend representation.
Sourcefn into_backend(self) -> Self::BackID
fn into_backend(self) -> Self::BackID
Convert this ID into its backend representation.
Provided Methods§
Sourcefn try_deref_alloc(self, alloc: &IDBoundAlloc<Self>) -> Option<&Self::ObjectT>
fn try_deref_alloc(self, alloc: &IDBoundAlloc<Self>) -> Option<&Self::ObjectT>
Try to dereference the object this ID points to, returning None if invalid.
Sourcefn try_deref_alloc_mut(
self,
alloc: &mut IDBoundAlloc<Self>,
) -> Option<&mut Self::ObjectT>
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.
Sourcefn deref_alloc(self, alloc: &IDBoundAlloc<Self>) -> &Self::ObjectT
fn deref_alloc(self, alloc: &IDBoundAlloc<Self>) -> &Self::ObjectT
Dereference the object this ID points to, panicking if invalid.
Sourcefn deref_alloc_mut(self, alloc: &mut IDBoundAlloc<Self>) -> &mut Self::ObjectT
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.