Skip to content

Commit 2b5c3bd

Browse files
committed
only slotmap allowed
1 parent de7873c commit 2b5c3bd

File tree

4 files changed

+10
-15
lines changed

4 files changed

+10
-15
lines changed

Cargo.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@ repository = "https://github.com/Nertsal/stecs"
1313
[features]
1414
default = ["slotmap", "query_mut"]
1515
query_mut = ["stecs-derive/query_mut"]
16-
slotmap = ["dep:slotmap"]
17-
dynamic = ["stecs-derive/dynamic", "dep:anymap3"]
16+
dynamic = ["stecs-derive/dynamic"]
1817

1918
[workspace]
2019
members = ["crates/*"]

crates/stecs-derive/src/split.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -743,15 +743,17 @@ The given `ids` must not repeat and must be valid and present id's in the storag
743743
#[doc = #insert_dyn_doc]
744744
pub fn insert_dyn<__T>(&mut self, id: #generic_family_name::Id, component: __T)
745745
where
746-
#generic_family_name::Storage<__T>: ::anymap3::CloneAny
746+
__T: Clone + 'static,
747+
#generic_family_name::Id: 'static,
747748
{
748749
self.r#dyn.insert(id, component)
749750
}
750751

751752
#[doc = #remove_dyn_doc]
752753
pub fn remove_dyn<__T>(&mut self, id: #generic_family_name::Id) -> Option<__T>
753754
where
754-
#generic_family_name::Storage<__T>: ::anymap3::CloneAny
755+
__T: Clone + 'static,
756+
#generic_family_name::Id: 'static,
755757
{
756758
self.r#dyn.remove(id)
757759
}

src/dynamic/mod.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::storage::{Storage, StorageFamily};
1+
use crate::storage::{sparse::Sparse, Storage, StorageFamily};
22

33
use std::marker::PhantomData;
44

@@ -15,11 +15,7 @@ pub struct DynamicStorage<F> {
1515
id: PhantomData<F>,
1616
}
1717

18-
// TODO: should really be Sparse most of the time;
19-
// maybe independent from the main storage type.
20-
// Could depend on component type via a trait,
21-
// but then we cannot match Id's freely.
22-
type InnerMap<F, T> = <F as StorageFamily>::Storage<T>;
18+
type InnerMap<F, T> = Sparse<T, <F as StorageFamily>::Id>;
2319

2420
impl<F> Clone for DynamicStorage<F> {
2521
fn clone(&self) -> Self {

src/storage/mod.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
1-
#[cfg(feature = "slotmap")]
21
pub mod dense;
3-
#[cfg(feature = "slotmap")]
42
pub mod sparse;
53

64
/// A storage of components.
75
pub trait Storage<T>: Default {
86
/// Type of the abstract family corresponding to the storages of this type.
97
type Family: StorageFamily;
108
/// Type of the identifier used for components/entities.
11-
type Id: Copy;
9+
type Id: slotmap::Key;
1210

1311
/// Insert a new component to at the specified id.
1412
fn insert(&mut self, id: Self::Id, value: T);
@@ -44,7 +42,7 @@ pub trait Storage<T>: Default {
4442
/// A family of storages for different component types.
4543
pub trait StorageFamily {
4644
/// Type of the identifier used for components/entities.
47-
type Id: Copy;
45+
type Id: slotmap::Key;
4846
/// Type of a specific storage.
4947
type Storage<T>: Storage<T, Family = Self, Id = Self::Id>;
5048
type Generator: IdGenerator<Id = Self::Id>;
@@ -59,7 +57,7 @@ pub trait StorageFamily {
5957
///
6058
pub unsafe trait IdGenerator {
6159
/// The identifier type being generated.
62-
type Id: Copy;
60+
type Id: slotmap::Key;
6361

6462
/// Returns the unique id's of all active entities in the storage in an arbitrary order.
6563
///

0 commit comments

Comments
 (0)