summaryrefslogtreecommitdiff
path: root/ecs/src/pair.rs
diff options
context:
space:
mode:
Diffstat (limited to 'ecs/src/pair.rs')
-rw-r--r--ecs/src/pair.rs29
1 files changed, 13 insertions, 16 deletions
diff --git a/ecs/src/pair.rs b/ecs/src/pair.rs
index 27e535e..2055d5e 100644
--- a/ecs/src/pair.rs
+++ b/ecs/src/pair.rs
@@ -1,12 +1,10 @@
use std::convert::Infallible;
-use crate::component::storage::Storage as ComponentStorage;
use crate::component::{IntoParts as IntoComponentParts, Parts as ComponentParts};
use crate::entity::{
Handle as EntityHandle,
MatchingComponentIter as EntityMatchingComponentIter,
};
-use crate::lock::ReadGuard;
use crate::query::{
TermWithField as QueryTermWithField,
TermsBuilder as QueryTermsBuilder,
@@ -24,14 +22,16 @@ pub struct Pair<RelationElem: Element, TargetElem: Element>
impl Pair<Uid, Uid>
{
+ #[must_use]
pub fn new<Relation: WithUid>(target: Uid) -> Self
{
Self { relation: Relation::uid(), target }
}
+ #[must_use]
pub fn id(&self) -> Uid
{
- Uid::new_pair(UidPairParams {
+ Uid::new_pair(&UidPairParams {
relation: self.relation,
target: self.target,
})
@@ -72,7 +72,6 @@ where
Handle {
world,
- component_storage_lock: world.data.component_storage.read_nonblock().unwrap(),
pair_uid: first_matching_comp.id(),
}
}
@@ -85,7 +84,7 @@ where
{
fn uid() -> Uid
{
- Uid::new_pair(UidPairParams {
+ Uid::new_pair(&UidPairParams {
relation: Relation::uid(),
target: Target::uid(),
})
@@ -121,21 +120,25 @@ where
pub struct Handle<'world>
{
world: &'world World,
- component_storage_lock: ReadGuard<'world, ComponentStorage>,
pair_uid: Uid,
}
impl Handle<'_>
{
+ #[must_use]
pub fn get_target_entity(&self) -> Option<EntityHandle<'_>>
{
let archetype = self
- .component_storage_lock
+ .world
+ .data
+ .component_storage
.get_entity_archetype(self.pair_uid.target_entity())?;
- let archetype_entity = archetype
- .get_entity_by_id(self.pair_uid.target_entity())
- .expect("Not possible");
+ let Some(archetype_entity) =
+ archetype.get_entity_by_id(self.pair_uid.target_entity())
+ else {
+ unreachable!();
+ };
Some(EntityHandle::new(self.world, archetype, archetype_entity))
}
@@ -157,12 +160,6 @@ impl<'a> Iterator for HandleIter<'a>
Some(Handle {
world: self.world,
- component_storage_lock: self
- .world
- .data
- .component_storage
- .read_nonblock()
- .unwrap(),
pair_uid: matching_comp.id(),
})
}