Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion src/archetype.rs
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,7 @@ impl Hasher for TypeIdHasher {
/// faster no-op hash.
pub(crate) type TypeIdMap<V> = HashMap<TypeId, V, BuildHasherDefault<TypeIdHasher>>;

struct OrderedTypeIdMap<V>(Box<[(TypeId, V)]>);
pub(crate) struct OrderedTypeIdMap<V>(Box<[(TypeId, V)]>);

impl<V> OrderedTypeIdMap<V> {
fn new(iter: impl Iterator<Item = (TypeId, V)>) -> Self {
Expand Down Expand Up @@ -560,6 +560,16 @@ impl TypeInfo {
pub fn drop_shim(&self) -> unsafe fn(*mut u8) {
self.drop
}

#[cfg(debug_assertions)]
pub(crate) fn name(&self) -> Option<&str> {
Some(self.type_name)
}

#[cfg(not(debug_assertions))]
pub(crate) fn name(&self) -> Option<&str> {
None
}
}

impl PartialOrd for TypeInfo {
Expand Down
25 changes: 21 additions & 4 deletions src/bundle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,19 +95,36 @@ impl DynamicClone {
}

/// Error indicating that an entity did not have a required component
#[derive(Debug, Clone, Eq, PartialEq, Hash)]
pub struct MissingComponent(&'static str);
#[derive(Debug, Clone, Eq, PartialEq)]
pub enum MissingComponent {
/// Compile-time name string
Static(&'static str),
/// Name string sourced from TypeInfo
Dynamic(TypeInfo),
}

impl MissingComponent {
/// Construct an error representing a missing `T`
pub fn new<T: Component>() -> Self {
Self(type_name::<T>())
Self::Static(type_name::<T>())
}

/// Construct an error representing a missing type described by TypeInfo
pub fn new_dynamic(ty: TypeInfo) -> Self {
Self::Dynamic(ty)
}
}

impl fmt::Display for MissingComponent {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "missing {} component", self.0)
write!(
f,
"missing {} component",
match self {
MissingComponent::Static(name) => name,
MissingComponent::Dynamic(type_info) => type_info.name().unwrap_or("unknown"),
}
)
}
}

Expand Down
12 changes: 8 additions & 4 deletions src/entities.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,8 @@ impl<'a> Iterator for ReserveEntitiesIterator<'a> {
impl<'a> ExactSizeIterator for ReserveEntitiesIterator<'a> {}

#[derive(Default)]
pub(crate) struct Entities {
#[doc(hidden)]
pub struct Entities {
pub meta: Vec<EntityMeta>,

// The `pending` and `free_cursor` fields describe three sets of Entity IDs
Expand Down Expand Up @@ -530,7 +531,8 @@ impl Entities {
}

#[derive(Copy, Clone)]
pub(crate) struct EntityMeta {
#[doc(hidden)]
pub struct EntityMeta {
pub generation: NonZeroU32,
pub location: Location,
}
Expand All @@ -549,7 +551,8 @@ impl EntityMeta {
}

#[derive(Copy, Clone)]
pub(crate) struct Location {
#[doc(hidden)]
pub struct Location {
pub archetype: u32,
pub index: u32,
}
Expand All @@ -568,7 +571,8 @@ impl fmt::Display for NoSuchEntity {
impl Error for NoSuchEntity {}

#[derive(Clone)]
pub(crate) struct AllocManyState {
#[doc(hidden)]
pub struct AllocManyState {
pub pending_end: usize,
fresh: Range<u32>,
}
Expand Down
6 changes: 3 additions & 3 deletions src/entity_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ use crate::{align, Component, ComponentRef, ComponentRefShared, DynamicBundle};
/// ```
#[derive(Default)]
pub struct EntityBuilder {
inner: Common<()>,
pub(crate) inner: Common<()>,
}

impl EntityBuilder {
Expand Down Expand Up @@ -277,7 +277,7 @@ impl From<BuiltEntityClone> for EntityBuilderClone {
}
}

struct Common<M> {
pub(crate) struct Common<M> {
storage: NonNull<u8>,
layout: Layout,
cursor: usize,
Expand Down Expand Up @@ -336,7 +336,7 @@ impl<M> Common<M> {
}
}

unsafe fn add(&mut self, ptr: *mut u8, ty: TypeInfo, meta: M) {
pub(crate) unsafe fn add(&mut self, ptr: *mut u8, ty: TypeInfo, meta: M) {
match self.indices.entry(ty.id()) {
Entry::Occupied(occupied) => {
let index = *occupied.get();
Expand Down
Loading