diff options
author | HampusM <hampus@hampusmat.com> | 2024-04-10 22:45:35 +0200 |
---|---|---|
committer | HampusM <hampus@hampusmat.com> | 2024-04-10 22:45:35 +0200 |
commit | e028d89e15fd219854cbd7122d63ebd2fa37d390 (patch) | |
tree | 90a87429e3851bde1678a5902e96f8e61ef85f9c /ecs/src/lib.rs | |
parent | 50fb3122a2a141f1b78a874c139b097459a09408 (diff) |
feat(ecs): add weak ref single
Diffstat (limited to 'ecs/src/lib.rs')
-rw-r--r-- | ecs/src/lib.rs | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/ecs/src/lib.rs b/ecs/src/lib.rs index db82d91..8a5de64 100644 --- a/ecs/src/lib.rs +++ b/ecs/src/lib.rs @@ -353,12 +353,12 @@ pub struct SoleAlreadyExistsError(pub &'static str); #[derive(Debug, Default)] struct SoleStorage { - storage: HashMap<TypeId, Lock<Box<dyn Sole>>>, + storage: HashMap<TypeId, Arc<Lock<Box<dyn Sole>>>>, } impl SoleStorage { - fn get<SoleT: Sole>(&self) -> Option<&Lock<Box<dyn Sole>>> + fn get<SoleT: Sole>(&self) -> Option<&Arc<Lock<Box<dyn Sole>>>> { self.storage.get(&TypeId::of::<SoleT>()) } @@ -371,7 +371,10 @@ impl SoleStorage return Err(SoleAlreadyExistsError(type_name::<SoleT>())); } - self.storage.insert(sole_type_id, Lock::new(Box::new(sole))); + // TODO: Reconsider this maybe? + #[allow(clippy::arc_with_non_send_sync)] + self.storage + .insert(sole_type_id, Arc::new(Lock::new(Box::new(sole)))); Ok(()) } |