Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
feat(API): unify ID and name handlers
some further API reduction:

with_name variants  (with_first_name etc) will also got merged with with
set_second_name and set_second merged into set_second
set_first_name set_first merged into set_first
set_src set_src_name merged into set_src
  • Loading branch information
Indra-db committed May 16, 2025
commit 11fc91ca0ef1a97f8ec6ff293aab0c8f602f9df0
4 changes: 2 additions & 2 deletions flecs_ecs/examples/flecs/queries/query_cyclic_variables.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ fn main() {
let rule = world
.query::<()>()
.with((id::<Likes>(), "$Y"))
.set_src_name("$X")
.set_src("$X")
.with((id::<Likes>(), "$X"))
.set_src_name("$Y")
.set_src("$Y")
.build();

// Lookup the index of the variables. This will let us quickly lookup their
Expand Down
4 changes: 2 additions & 2 deletions flecs_ecs/examples/flecs/queries/query_facts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ fn main() {
let mut friends = world
.query::<()>()
.with((id::<Likes>(), "$Y"))
.set_src_name("$X")
.set_src("$X")
.with((id::<Likes>(), "$X"))
.set_src_name("$Y")
.set_src("$Y")
.build();

let x_var = friends.find_var("X").unwrap();
Expand Down
4 changes: 2 additions & 2 deletions flecs_ecs/examples/flecs/queries/query_setting_variables.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,9 @@ fn main() {
.query::<()>()
.with(id::<RangedUnit>())
.with(id::<&Platoon>())
.set_second_name("$platoon")
.set_second("$platoon")
.with((id::<Player>(), "$player"))
.set_src_name("$platoon")
.set_src("$platoon")
.build();

// If we would iterate this query it would return all ranged units for all
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ fn main() {
.with(id::<&Person>())
.with((id::<LocatedIn>(), "$Location"))
.with(id::<&Country>())
.set_src_name("$Location")
.set_src("$Location")
.build();

// Lookup the index of the variable. This will let us quickly lookup its
Expand Down
2 changes: 1 addition & 1 deletion flecs_ecs/examples/flecs/queries/query_variables.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ fn main() {
// same entity.
.with((id::<Eats>(), "$food"))
.with(id::<&Healthy>())
.set_src_name("$food")
.set_src("$food")
.build();

// Lookup the index of the variable. This will let us quickly lookup its
Expand Down
11 changes: 6 additions & 5 deletions flecs_ecs/src/core/query_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -337,18 +337,19 @@ pub trait QueryBuilderImpl<'a>: TermBuilderImpl<'a> {
self.init_current_term(ecs_pair(*rel, *target));
}
AccessTarget::Name(name) => {
self.set_first(name);
self.set_first::<&'static str>(name);
}
AccessTarget::PairName(rel, target) => {
self.set_first(rel).set_second(target);
self.set_first::<&'static str>(rel)
.set_second::<&'static str>(target);
}
AccessTarget::PairEntityName(rel, target) => {
self.init_current_term(rel);
self.set_second(target);
self.set_second::<&'static str>(target);
}
AccessTarget::PairNameEntity(rel, target) => {
self.set_first(rel);
self.set_second(target);
self.set_first::<&'static str>(rel);
self.set_second::<Entity>(target);
}
}

Expand Down
10 changes: 5 additions & 5 deletions flecs_ecs/src/core/term.rs
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ pub trait TermBuilderImpl<'a>: Sized + WorldProvider<'a> + internals::QueryConfi
///
/// * initialize it with entity id or
/// * initialize it with name. If name starts with a $
/// the name is interpreted as a variable.
/// the name is interpreted as a variable.
///
/// # Arguments
///
Expand Down Expand Up @@ -421,10 +421,10 @@ pub trait TermBuilderImpl<'a>: Sized + WorldProvider<'a> + internals::QueryConfi
///
/// * initialize with id or
/// * initialize it with name. If name starts with a $
/// the name is interpreted as a variable.
fn set_first<T: SingleAccessArg>(&mut self, id: T) -> &mut Self
/// the name is interpreted as a variable.
fn set_first<Q: SingleAccessArg>(&mut self, id: Q) -> &mut Self
where
Access: FromAccessArg<T>,
Access: FromAccessArg<Q>,
{
check_term_access_validity(self);
let access = Access::from_access_arg(id, self.world());
Expand Down Expand Up @@ -457,7 +457,7 @@ pub trait TermBuilderImpl<'a>: Sized + WorldProvider<'a> + internals::QueryConfi
///
/// * initialize with id or
/// * initialize it with name. If name starts with a $
/// the name is interpreted as a variable.
/// the name is interpreted as a variable.
fn set_second<T: SingleAccessArg>(&mut self, id: T) -> &mut Self
where
Access: FromAccessArg<T>,
Expand Down
10 changes: 3 additions & 7 deletions flecs_ecs/src/core/utility/traits/into_id.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::core::*;

/// Extracts the Ecs ID from_access_arg a type.
/// Extension trait from_access_arg [`Into<Entity>`] for tuples that implement `Into<Entity>`.
/// Extracts the Ecs ID a type.
/// Extension trait [`Into<Entity>`] for tuples that implement `Into<Entity>`.
/// These types can be [`Id`], [`IdView`], [`Entity`], [`EntityView`], [`Component`], [`UntypedComponent`].
pub trait IntoId: InternalIntoEntity
where
Expand Down Expand Up @@ -131,13 +131,9 @@ where
{
}

// impl<T: ComponentId> SingleAccessArg for &crate::core::utility::id::Id<T> {}
// impl<T: ComponentId> SingleAccessArg for &mut crate::core::utility::id::Id<T> {}
impl SingleAccessArg for &'static str {}
//impl<T: IntoEntity> SingleAccessArg for T where Access: FromAccessArg<T> {}
impl<T: IntoEntity> SingleAccessArg for T where Access: FromAccessArg<T> {}

impl<T: ComponentId> AccessArg for &crate::core::utility::id::Id<T> {}
impl<T: ComponentId> AccessArg for &mut crate::core::utility::id::Id<T> {}
impl AccessArg for &'static str {}
impl<T: IntoId> AccessArg for T where Access: FromAccessArg<T> {}
impl AccessArg for (&'static str, &'static str) {}
Expand Down
22 changes: 11 additions & 11 deletions flecs_ecs/tests/flecs/flecs_docs_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -594,8 +594,8 @@ fn flecs_query_docs_compile_test() {
let q = world
.query::<()>()
.term()
.set_first_name("Eats")
.set_second_name("Apples")
.set_first("Eats")
.set_second("Apples")
.build();

let q = world
Expand Down Expand Up @@ -776,11 +776,11 @@ fn flecs_query_docs_compile_test() {
.without((id::<flecs::PredEq>(), id::<Bar>()))
// $this == "Foo"
.with(id::<flecs::PredEq>())
.set_second_name("Foo")
.set_second("Foo")
.flags(sys::EcsIsName)
// $this ~= "Fo"
.with(id::<flecs::PredMatch>())
.set_second_name("Fo")
.set_second("Fo")
.flags(sys::EcsIsName)
.build();

Expand Down Expand Up @@ -890,9 +890,9 @@ fn flecs_query_docs_compile_test() {
let q = world
.query::<(&SimConfig, &SimTime)>()
.term_at(0)
.set_src_name("cfg")
.set_src("cfg")
.term_at(1)
.set_src_name("game")
.set_src("game")
.build();

let q = world
Expand Down Expand Up @@ -1038,9 +1038,9 @@ fn flecs_query_docs_compile_test() {
.query::<()>()
.with(id::<SpaceShip>())
.with(id::<DockedTo>())
.set_second_name("$Location")
.set_second("$Location")
.with(id::<Planet>())
.set_src_name("$Location")
.set_src("$Location")
.build();

let q = world
Expand Down Expand Up @@ -1208,7 +1208,7 @@ fn flecs_query_docs_compile_test() {
let q = world
.query::<()>()
.with(id::<LocatedIn>())
.set_second_name("$Place")
.set_second("$Place")
.build();

#[derive(Component)]
Expand All @@ -1225,9 +1225,9 @@ fn flecs_query_docs_compile_test() {
let q = world
.query::<()>()
.with(id::<LocatedIn>())
.set_second_name("$Place")
.set_second("$Place")
.with(id::<City>())
.set_src_name("$Place")
.set_src("$Place")
.build();

let tree = world.entity();
Expand Down
6 changes: 3 additions & 3 deletions flecs_ecs/tests/flecs/query_builder_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4843,7 +4843,7 @@ fn query_builder_var_src_w_prefixed_name() {
let r = world
.query::<()>()
.with(id::<&Foo>())
.set_src_name("$Var")
.set_src("$Var")
.set_cache_kind(QueryCacheKind::Auto)
.build();

Expand All @@ -4868,7 +4868,7 @@ fn query_builder_var_first_w_prefixed_name() {
.query::<()>()
.with(id::<&Foo>())
.term()
.set_first_name("$Var")
.set_first("$Var")
.set_cache_kind(QueryCacheKind::Auto)
.build();

Expand All @@ -4894,7 +4894,7 @@ fn query_builder_var_second_w_prefixed_name() {
let r = world
.query::<()>()
.with(id::<&Foo>())
.set_second_name("$Var")
.set_second("$Var")
.set_cache_kind(QueryCacheKind::Auto)
.build();

Expand Down
Loading