summaryrefslogtreecommitdiff
path: root/engine-ecs
diff options
context:
space:
mode:
authorHampusM <hampus@hampusmat.com>2026-07-21 13:04:32 +0200
committerHampusM <hampus@hampusmat.com>2026-07-21 14:28:05 +0200
commit67bb995ffdd201997758701eeda35b4373b51104 (patch)
tree3da282f2d3763f4f492ef77363962cdd99fd89ae /engine-ecs
parentd094b413b1960e45e16ff2a2247439357ed517bf (diff)
feat(engine-ecs): add pair macro
Diffstat (limited to 'engine-ecs')
-rw-r--r--engine-ecs/src/pair.rs73
1 files changed, 73 insertions, 0 deletions
diff --git a/engine-ecs/src/pair.rs b/engine-ecs/src/pair.rs
index eff0332..cede364 100644
--- a/engine-ecs/src/pair.rs
+++ b/engine-ecs/src/pair.rs
@@ -680,6 +680,79 @@ impl ComponentOrWildcard for Wildcard
impl sealed::Sealed for Wildcard {}
+#[macro_export]
+macro_rules! pair {
+ ($relation: ty, $target: ty) => {
+ $crate::pair!(@build, $relation, $target)
+ };
+
+ ($relation: ty, { $target: expr }) => {
+ $crate::pair!(@build, $relation, { $target })
+ };
+
+ ({ $relation: expr }, $target: ty) => {
+ $crate::pair!(@build, { $relation }, $target)
+ };
+
+ ({ $relation: expr }, { $target: expr }) => {
+ $crate::pair!(@build, { $relation }, { $target })
+ };
+
+ ($relation: ty, ={ $target: expr }) => {
+ {
+ fn get_type_uid<T: $crate::pair::ComponentOrWildcard>()
+ -> $crate::uid::Uid
+ {
+ T::uid()
+ }
+
+ $crate::pair::Pair::builder()
+ .relation_id(get_type_uid::<$relation>())
+ .target_as_data({ $target })
+ .build()
+ }
+ };
+
+ (={ $relation: expr }, $target: ty) => {
+ {
+ fn get_type_uid<T: $crate::pair::ComponentOrWildcard>()
+ -> $crate::uid::Uid
+ {
+ T::uid()
+ }
+
+ $crate::pair::Pair::builder()
+ .relation_as_data($relation)
+ .target_id(get_type_uid::<$target>())
+ .build()
+ }
+ };
+
+ (@build, $relation: tt, $target: tt) => {
+ {
+ #[allow(dead_code)]
+ fn get_type_uid<T: $crate::pair::ComponentOrWildcard>()
+ -> $crate::uid::Uid
+ {
+ T::uid()
+ }
+
+ $crate::pair::Pair::builder()
+ .relation_id($crate::pair!(@get_uid, $relation))
+ .target_id($crate::pair!(@get_uid, $target))
+ .build()
+ }
+ };
+
+ (@get_uid, $src: ty) => {
+ get_type_uid::<$src>()
+ };
+
+ (@get_uid, { $src: expr }) => {
+ $src
+ };
+}
+
mod sealed
{
pub trait Sealed {}