Skip to content

Commit

Permalink
Switching to manual implementation for those Debug traits
Browse files Browse the repository at this point in the history
  • Loading branch information
recatek committed Aug 12, 2024
1 parent dea5aff commit e55af6f
Showing 1 changed file with 55 additions and 4 deletions.
59 changes: 55 additions & 4 deletions src/entity.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
use std::hash::{Hash, Hasher};
use std::marker::PhantomData;

#[cfg(debug_assertions)]
use std::fmt::{Debug, Formatter, Result as FmtResult};

use crate::error::EcsError;
use crate::index::{TrimmedIndex, MAX_DATA_INDEX};
use crate::traits::{Archetype, EntityKey};
Expand Down Expand Up @@ -30,7 +33,6 @@ pub(crate) const ARCHETYPE_ID_BITS: u32 = ArchetypeId::BITS;
/// enable the `wrapping_version` crate feature instead. Note that this could
/// allow invalid entity access, but doing so will not access invalid memory,
/// and the chances of this happening are infinitesimally small.
#[cfg_attr(debug_assertions, derive(Debug))]
pub struct Entity<A: Archetype> {
inner: EntityAny,
_type: PhantomData<fn() -> A>,
Expand All @@ -53,7 +55,6 @@ pub struct Entity<A: Archetype> {
/// `wrapping_version` crate feature instead. Note that this could allow
/// invalid entity access, but doing so will not access invalid memory, and
/// the chances of this happening are infinitesimally small.
#[cfg_attr(debug_assertions, derive(Debug))]
pub struct EntityRaw<A: Archetype> {
inner: EntityRawAny,
_type: PhantomData<fn() -> A>,
Expand All @@ -66,7 +67,6 @@ pub struct EntityRaw<A: Archetype> {
/// generated by the `ecs_world!` declaration to convert the `EntityAny` into
/// an enum with each possible archetype outcome.
#[derive(Clone, Copy, Eq, PartialEq)]
#[cfg_attr(debug_assertions, derive(Debug))]
pub struct EntityAny {
key: u32, // [ slot_index (u24) | archetype_id (u8) ]
version: SlotVersion,
Expand All @@ -79,7 +79,6 @@ pub struct EntityAny {
/// generated by the `ecs_world!` declaration to convert the `EntityRawAny` into
/// an enum with each possible archetype outcome.
#[derive(Clone, Copy, Eq, PartialEq)]
#[cfg_attr(debug_assertions, derive(Debug))]
pub struct EntityRawAny {
key: u32, // [ dense_index (u24) | archetype_id (u8) ]
version: ArchetypeVersion,
Expand Down Expand Up @@ -447,6 +446,58 @@ impl EntityKey for EntityRawAny {
type DestroyOutput = bool;
}

#[cfg(debug_assertions)]
impl<A: Archetype> Debug for Entity<A> {
fn fmt(&self, f: &mut Formatter<'_>) -> FmtResult {
write!(
f,
"Entity<_> {{ archetype_id: {}, slot_index: {}, version: {} }}",
self.archetype_id(),
u32::from(self.slot_index()),
self.version().get(),
)
}
}

#[cfg(debug_assertions)]
impl<A: Archetype> Debug for EntityRaw<A> {
fn fmt(&self, f: &mut Formatter<'_>) -> FmtResult {
write!(
f,
"EntityRaw<_> {{ archetype_id: {}, dense_index: {}, version: {} }}",
self.archetype_id(),
u32::from(self.dense_index()),
self.version().get(),
)
}
}

#[cfg(debug_assertions)]
impl Debug for EntityAny {
fn fmt(&self, f: &mut Formatter<'_>) -> FmtResult {
write!(
f,
"EntityAny {{ archetype_id: {}, slot_index: {}, version: {} }}",
self.archetype_id(),
u32::from(self.slot_index()),
self.version().get(),
)
}
}

#[cfg(debug_assertions)]
impl Debug for EntityRawAny {
fn fmt(&self, f: &mut Formatter<'_>) -> FmtResult {
write!(
f,
"EntityRawAny {{ archetype_id: {}, dense_index: {}, version: {} }}",
self.archetype_id(),
u32::from(self.dense_index()),
self.version().get(),
)
}
}

#[doc(hidden)]
pub mod __internal {
use super::*;
Expand Down

0 comments on commit e55af6f

Please sign in to comment.