summaryrefslogtreecommitdiff
path: root/engine-ecs/src
diff options
context:
space:
mode:
authorHampusM <hampus@hampusmat.com>2026-12-01 17:42:12 +0100
committerHampusM <hampus@hampusmat.com>2026-12-01 17:42:12 +0100
commitb2a130a6e30b82a7e0f80347f916265a467a4238 (patch)
tree5685399d1cf7a28df3f91e83a2d3d2eaf2eaa20b /engine-ecs/src
parent8985ff5080c34cf4b07b814ed7a757311a5a332f (diff)
refactor(engine-ecs): replace component::IntoParts with std From/Into traitsHEADmaster
Diffstat (limited to 'engine-ecs/src')
-rw-r--r--engine-ecs/src/actions.rs14
-rw-r--r--engine-ecs/src/bundle.rs6
-rw-r--r--engine-ecs/src/component.rs15
-rw-r--r--engine-ecs/src/component/local.rs8
-rw-r--r--engine-ecs/src/lib.rs23
-rw-r--r--engine-ecs/src/pair.rs35
-rw-r--r--engine-ecs/src/sole.rs4
7 files changed, 41 insertions, 64 deletions
diff --git a/engine-ecs/src/actions.rs b/engine-ecs/src/actions.rs
index f4967df..21122c8 100644
--- a/engine-ecs/src/actions.rs
+++ b/engine-ecs/src/actions.rs
@@ -3,7 +3,6 @@ use std::borrow::Cow;
use crate::bundle::Bundle;
use crate::component::{
Component,
- IntoParts,
Parts as ComponentParts,
RemovableTuple as RemovableComponentTuple,
};
@@ -67,7 +66,7 @@ impl Actions<'_>
let components_parts = bundle
.iter_component_parts()
- .chain([EntityName { name: name.into() }.into_parts()])
+ .chain([EntityName { name: name.into() }.into()])
.collect::<Vec<_>>();
if let Some(ComponentParts { id: sole_id, .. }) = components_parts
@@ -211,7 +210,7 @@ impl Actions<'_>
.relation_id(pair_id.relation())
.target_id(new_target_id)
.build()
- .into_parts(),
+ .into(),
});
}
@@ -241,7 +240,7 @@ impl Actions<'_>
.relation_id(pair_id.relation())
.target_as_data(new_target)
.build()
- .into_parts(),
+ .into(),
});
}
@@ -271,7 +270,7 @@ impl Actions<'_>
.relation_id(new_relation_id)
.target_id(pair_id.target())
.build()
- .into_parts(),
+ .into(),
});
}
@@ -301,7 +300,7 @@ impl Actions<'_>
.relation_as_data(new_relation)
.target_id(pair_id.target())
.build()
- .into_parts(),
+ .into(),
});
}
@@ -309,8 +308,7 @@ impl Actions<'_>
/// of the sole.
pub fn create_sole<SoleT: Sole>(&mut self, sole: SoleT) -> Uid
{
- self.action_queue
- .push(Action::CreateSole(sole.into_parts()));
+ self.action_queue.push(Action::CreateSole(sole.into()));
SoleT::id()
}
diff --git a/engine-ecs/src/bundle.rs b/engine-ecs/src/bundle.rs
index 4c13599..b0c0b50 100644
--- a/engine-ecs/src/bundle.rs
+++ b/engine-ecs/src/bundle.rs
@@ -1,6 +1,6 @@
use seq_macro::seq;
-use crate::component::{IntoParts as IntoComponentParts, Parts as ComponentParts};
+use crate::component::Parts as ComponentParts;
pub trait Bundle: 'static
{
@@ -31,10 +31,10 @@ seq!(C in 0..17 {
gen_tuple_impls!(C);
});
-impl<T: IntoComponentParts + 'static> Bundle for T
+impl<T: Into<ComponentParts> + 'static> Bundle for T
{
fn iter_component_parts(self) -> impl Iterator<Item = ComponentParts>
{
- [self.into_parts()].into_iter()
+ [self.into()].into_iter()
}
}
diff --git a/engine-ecs/src/component.rs b/engine-ecs/src/component.rs
index df495ce..71608b1 100644
--- a/engine-ecs/src/component.rs
+++ b/engine-ecs/src/component.rs
@@ -26,7 +26,7 @@ pub mod local;
pub(crate) mod storage;
/// A component that is not a pair and is not a sole.
-pub trait Component: WithAssociatedId + SystemInput + Any + IntoParts
+pub trait Component: WithAssociatedId + SystemInput + Any + Into<Parts>
{
fn type_reflection() -> Option<&'static TypeReflection>
where
@@ -252,11 +252,6 @@ pub enum HandleError
#[error("Failed to acquire component lock")]
pub struct AcquireLockError(#[source] LockError);
-pub trait IntoParts
-{
- fn into_parts(self) -> Parts;
-}
-
/// The parts of a component.
#[derive(Debug)]
#[non_exhaustive]
@@ -279,14 +274,6 @@ impl Parts
}
}
-impl IntoParts for Parts
-{
- fn into_parts(self) -> Parts
- {
- self
- }
-}
-
#[derive(Debug)]
pub struct PartsBuilder
{
diff --git a/engine-ecs/src/component/local.rs b/engine-ecs/src/component/local.rs
index 29afcee..c4c7083 100644
--- a/engine-ecs/src/component/local.rs
+++ b/engine-ecs/src/component/local.rs
@@ -1,11 +1,7 @@
use std::any::type_name;
use std::ops::{Deref, DerefMut};
-use crate::component::{
- HandleMut as ComponentHandleMut,
- IntoParts as _,
- Parts as ComponentParts,
-};
+use crate::component::{HandleMut as ComponentHandleMut, Parts as ComponentParts};
use crate::pair::Pair;
use crate::system::initializable::Param as InitializableParam;
use crate::system::{Metadata as SystemMetadata, Param as SystemParam};
@@ -65,7 +61,7 @@ where
.relation::<IsLocalComponent>()
.target_as_data(input)
.build()
- .into_parts(),
+ .into(),
);
}
}
diff --git a/engine-ecs/src/lib.rs b/engine-ecs/src/lib.rs
index ee2dca6..44c7aa0 100644
--- a/engine-ecs/src/lib.rs
+++ b/engine-ecs/src/lib.rs
@@ -20,7 +20,6 @@ use crate::component::storage::{
use crate::component::{
Component,
Info as ComponentInfo,
- IntoParts as IntoComponentParts,
Parts as ComponentParts,
WithAssociatedId,
};
@@ -198,7 +197,7 @@ impl World
self.create_ent(
entity_uid,
- components_parts.chain([EntityName { name: name.into() }.into_parts()]),
+ components_parts.chain([EntityName { name: name.into() }.into()]),
&ComponentAddingFlags { allow_soles: false },
);
}
@@ -249,9 +248,9 @@ impl World
self.create_ent(
SoleT::id(),
[
- sole.into_parts(),
- EntityName { name: SoleT::name() }.into_parts(),
- crate::sole::Is.into_parts(),
+ sole.into(),
+ EntityName { name: SoleT::name() }.into(),
+ crate::sole::Is.into(),
],
&ComponentAddingFlags { allow_soles: true },
);
@@ -271,11 +270,9 @@ impl World
self.create_ent(
ent_id,
- [SystemFunction { system }.into_parts()].into_iter().chain(
- ObserverT::observed_events()
- .into_iter()
- .map(IntoComponentParts::into_parts),
- ),
+ [SystemFunction { system }.into()]
+ .into_iter()
+ .chain(ObserverT::observed_events().into_iter().map(Into::into)),
&ComponentAddingFlags { allow_soles: false },
);
@@ -636,8 +633,8 @@ impl World
sole_parts.id,
[
sole_parts,
- EntityName { name: name.into() }.into_parts(),
- crate::sole::Is.into_parts(),
+ EntityName { name: name.into() }.into(),
+ crate::sole::Is.into(),
],
&mut self.data.component_storage,
&EventSubmitter::new(&self.data.new_events),
@@ -753,7 +750,7 @@ impl World
unreachable!();
}
- let comp_info_parts = comp_info.into_parts();
+ let comp_info_parts = ComponentParts::from(comp_info);
match component_storage
.add_entity_component(comp_id, (comp_info_parts.id, comp_info_parts.data))
diff --git a/engine-ecs/src/pair.rs b/engine-ecs/src/pair.rs
index d0b9179..d6c3b3d 100644
--- a/engine-ecs/src/pair.rs
+++ b/engine-ecs/src/pair.rs
@@ -8,7 +8,6 @@ use crate::component::{
HandleError as ComponentHandleError,
HandleMut as ComponentHandleMut,
Info as ComponentInfo,
- IntoParts as IntoComponentParts,
Parts as ComponentParts,
Removable as RemovableComponent,
WithAssociatedId as ComponentWithAssociatedId,
@@ -209,55 +208,55 @@ impl Pair<Uid, Uid>
}
}
-impl IntoComponentParts for Pair<Uid, Uid>
+impl From<Pair<Uid, Uid>> for ComponentParts
{
- fn into_parts(self) -> ComponentParts
+ fn from(pair: Pair<Uid, Uid>) -> Self
{
- let id = self.id();
+ let id = pair.id();
ComponentParts::builder()
.component_info(ComponentInfo::default().with_name("Pair"))
- .pair_relation_metadata(self.relation_metadata)
- .pair_target_metadata(self.target_metadata)
+ .pair_relation_metadata(pair.relation_metadata)
+ .pair_target_metadata(pair.target_metadata)
.build(id, ())
}
}
-impl<Target> IntoComponentParts for Pair<Uid, Target>
+impl<Target> From<Pair<Uid, Target>> for ComponentParts
where
Target: Component,
{
- fn into_parts(self) -> ComponentParts
+ fn from(pair: Pair<Uid, Target>) -> Self
{
let id = Uid::new_pair(&UidPairParams {
- relation: self.relation,
+ relation: pair.relation,
target: Target::id(),
});
ComponentParts::builder()
.component_info(ComponentInfo::default().with_name("Pair"))
- .pair_relation_metadata(self.relation_metadata)
- .pair_target_metadata(self.target_metadata)
- .build(id, self.target)
+ .pair_relation_metadata(pair.relation_metadata)
+ .pair_target_metadata(pair.target_metadata)
+ .build(id, pair.target)
}
}
-impl<Relation> IntoComponentParts for Pair<Relation, Uid>
+impl<Relation> From<Pair<Relation, Uid>> for ComponentParts
where
Relation: Component,
{
- fn into_parts(self) -> ComponentParts
+ fn from(pair: Pair<Relation, Uid>) -> Self
{
let id = Uid::new_pair(&UidPairParams {
relation: Relation::id(),
- target: self.target,
+ target: pair.target,
});
ComponentParts::builder()
.component_info(ComponentInfo::default().with_name("Pair"))
- .pair_relation_metadata(self.relation_metadata)
- .pair_target_metadata(self.target_metadata)
- .build(id, self.relation)
+ .pair_relation_metadata(pair.relation_metadata)
+ .pair_target_metadata(pair.target_metadata)
+ .build(id, pair.relation)
}
}
diff --git a/engine-ecs/src/sole.rs b/engine-ecs/src/sole.rs
index ee1da7a..568be3e 100644
--- a/engine-ecs/src/sole.rs
+++ b/engine-ecs/src/sole.rs
@@ -4,14 +4,14 @@ use std::fmt::Debug;
use crate::component::{
HandleMut as ComponentHandleMut,
- IntoParts as IntoComponentParts,
+ Parts as ComponentParts,
WithAssociatedId as ComponentWithAssociatedId,
};
use crate::system::{Metadata as SystemMetadata, Param as SystemParam};
use crate::{Component, World};
/// A component which has a single instance in the [`World`].
-pub trait Sole: Any + IntoComponentParts + ComponentWithAssociatedId
+pub trait Sole: Any + ComponentWithAssociatedId + Into<ComponentParts>
{
fn type_reflection() -> Option<&'static crate::reflection::Type>
where