pub struct PtrID<E, P> { /* private fields */ }Expand description
Pointer-backed ID referencing a Unit<E> inside an EntityAlloc.
PtrID is a thin, non-null wrapper around a raw NonNull<Unit<E>>. It is
intended for fast, pointer-based access to entities. The struct carries a
PhantomData<P> to associate the allocation policy at the type level.
Safety / 注意事项:
PtrIDassumes the pointer points to a properly initializedUnit<E>.- Many operations are
unsafewithout validity checks; prefer the safe conversion methods inIEntityAllocID/EntityAllocthat validate generation/index when necessary.
Implementations§
Source§impl<E, P: IAllocPolicy> PtrID<E, P>
impl<E, P: IAllocPolicy> PtrID<E, P>
Sourcepub fn check_validity(&self, alloc: &EntityAlloc<E, P>) -> bool
pub fn check_validity(&self, alloc: &EntityAlloc<E, P>) -> bool
Check whether this pointer currently refers to a valid allocated unit.
Returns true if the pointer can be resolved to a live GenIndex in
the provided alloc. This performs the same generation/index check used
by other conversion helpers.
检查此指针在给定的 EntityAlloc 中是否仍然有效(未被释放或越界)。
Sourcepub unsafe fn direct_deref<'a>(self) -> Option<&'a E>
pub unsafe fn direct_deref<'a>(self) -> Option<&'a E>
Directly dereference the underlying unit, without validity check.
§Safety
The caller must ensure the pointer is valid and the unit is initialized. 不做有效性检查,调用者必须保证指针有效且单元已初始化。
Sourcepub unsafe fn direct_deref_mut<'a>(self) -> Option<&'a mut E>
pub unsafe fn direct_deref_mut<'a>(self) -> Option<&'a mut E>
Directly dereference the underlying unit mutably, without validity check.
§Safety
The caller must ensure exclusive access and that the pointer is valid. 不做有效性检查,调用者必须保证对该内存拥有唯一可变访问权。
Trait Implementations§
Source§impl<E, P: IAllocPolicy> IEntityAllocID<E, P> for PtrID<E, P>
impl<E, P: IAllocPolicy> IEntityAllocID<E, P> for PtrID<E, P>
Source§fn from_ptr(_: &EntityAlloc<E, P>, ptr: PtrID<E, P>) -> Option<Self>
fn from_ptr(_: &EntityAlloc<E, P>, ptr: PtrID<E, P>) -> Option<Self>
Source§fn from_index(
alloc: &EntityAlloc<E, P>,
indexed: IndexedID<E, P>,
) -> Option<Self>
fn from_index( alloc: &EntityAlloc<E, P>, indexed: IndexedID<E, P>, ) -> Option<Self>
Source§fn try_deref(self, alloc: &EntityAlloc<E, P>) -> Option<&E>
fn try_deref(self, alloc: &EntityAlloc<E, P>) -> Option<&E>
None if invalid.Source§fn try_deref_mut(self, alloc: &mut EntityAlloc<E, P>) -> Option<&mut E>
fn try_deref_mut(self, alloc: &mut EntityAlloc<E, P>) -> Option<&mut E>
None if invalid.Source§fn to_index(self, alloc: &EntityAlloc<E, P>) -> Option<IndexedID<E, P>>
fn to_index(self, alloc: &EntityAlloc<E, P>) -> Option<IndexedID<E, P>>
Source§fn to_ptr(self, _alloc: &EntityAlloc<E, P>) -> Option<PtrID<E, P>>
fn to_ptr(self, _alloc: &EntityAlloc<E, P>) -> Option<PtrID<E, P>>
Source§fn allocate_from(alloc: &EntityAlloc<E, P>, val: E) -> Self
fn allocate_from(alloc: &EntityAlloc<E, P>, val: E) -> Self
MTB::Entity library is ID-driven; allocation and deallocation
must be done through IDs.Source§fn free(self, alloc: &mut EntityAlloc<E, P>) -> Option<E>
fn free(self, alloc: &mut EntityAlloc<E, P>) -> Option<E>
Source§fn deref(self, alloc: &EntityAlloc<E, P>) -> &E
fn deref(self, alloc: &EntityAlloc<E, P>) -> &E
Source§fn deref_mut(self, alloc: &mut EntityAlloc<E, P>) -> &mut E
fn deref_mut(self, alloc: &mut EntityAlloc<E, P>) -> &mut E
Source§impl<E, P: IAllocPolicy> IPoliciedID for PtrID<E, P>
impl<E, P: IAllocPolicy> IPoliciedID for PtrID<E, P>
Source§fn from_backend(ptr: Self::BackID) -> Self
fn from_backend(ptr: Self::BackID) -> Self
Source§fn into_backend(self) -> Self::BackID
fn into_backend(self) -> Self::BackID
Source§fn try_deref_alloc(self, alloc: &IDBoundAlloc<Self>) -> Option<&Self::ObjectT>
fn try_deref_alloc(self, alloc: &IDBoundAlloc<Self>) -> Option<&Self::ObjectT>
None if invalid.Source§fn 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>
None if invalid.