You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This PR introduces entity-scoped query/property-bundle construction with with!(Entity, ...) and Entity while preserving compatibility with the legacy tuple-based query API.
What Changed
Added and documented with!(Entity, ...) as the preferred public constructor for:
entity initialization bundles passed to add_entity(...)
entity-scoped queries
Kept EntityPropertyTuple<E, T> as the public wrapper for entity-scoped property bundles
Moved tuple query behavior behind an internal QueryTuple<E> trait in query_impls.rs
Added Query::is_empty_query() so whole-population queries can be handled explicitly
Made entity ZSTs implement Query<E> and PropertyList<E> so callers can use Person / with!(Person) for whole-population operations
Updated query/count/sample code paths to use is_empty_query() instead of special-casing ()
Updated docs and tests to use the entity-scoped forms consistently
Backward Compatibility
Legacy query forms are still supported:
Bare query tuples like (Age(42),) and (Age(42), RiskCategory::High) continue to work
Empty tuple queries () are still supported where type inference is available or the entity type is specified explicitly
This keeps older code working while allowing newer call sites to use the clearer with!(Entity, ...) form.
Why
The previous API relied heavily on raw tuples and () for queries, which made entity scope implicit. This change makes the public API more explicit and readable:
with!(Person, Age(42)) is clearly a Person query
with!(Person) and Person clearly represent whole-population queries
Tuple-specific machinery remains internal, while compatibility is preserved
Testing
Added and updated tests to cover:
with!(Entity) empty-query behavior
with!(Entity, ...) single- and multi-property queries
Direct use of EntityPropertyTuple
Continued support for legacy tuple queries
Continued support for legacy empty tuple whole-population queries
It also introduces the private trait QueryTuple, which mirrors Query, though it's not clear what its purpose is. QueryTuple is implemented for tuples up to size 20.
What this PR doesn't do is remove tuple queries. Query is still implemented for () and for tuples of properties up to length 20. I think the intention of the issue was that we'd remove the Query impl for all tuples and require client code to use the with! macro (and thus EntityPropertyTuple).
Because you already have a blanket impl<E: Entity, T: QueryTuple<E>> Query<E> for EntityPropertyTuple<E, T>, you can achieve this by just removing the implementation
from the impl_query! macro definition. Then QueryTuple<E> would make sense: it allows EntityPropertyTuple<E, T> to implement Query without the tuple T implementing Query.
We have a blanket implementation of PropertyList for EntityPropertyTuple<E, T> whenever T: PropertyList. We could also require users to use the with! macro for property lists (adding new entities), in which case we would remove the implementation of PropertyList for tuples up to size 20 as well. We could use the same hypothetical mechanism as for tuples: introduce a private PropertyListTuple trait that mirrors PropertyList and provide a blanket impl<E: Entity, T: PropertyListTuple<E>> PropertyList<E> for EntityPropertyTuple<E, T> that delegates to PropertyListTuple<E>.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR introduces entity-scoped query/property-bundle construction with
with!(Entity, ...)andEntitywhile preserving compatibility with the legacy tuple-based query API.What Changed
with!(Entity, ...)as the preferred public constructor for:add_entity(...)EntityPropertyTuple<E, T>as the public wrapper for entity-scoped property bundlesQueryTuple<E>trait inquery_impls.rsQuery::is_empty_query()so whole-population queries can be handled explicitlyQuery<E>andPropertyList<E>so callers can usePerson/with!(Person)for whole-population operationsis_empty_query()instead of special-casing()Backward Compatibility
Legacy query forms are still supported:
(Age(42),)and(Age(42), RiskCategory::High)continue to work()are still supported where type inference is available or the entity type is specified explicitlyThis keeps older code working while allowing newer call sites to use the clearer
with!(Entity, ...)form.Why
The previous API relied heavily on raw tuples and
()for queries, which made entity scope implicit. This change makes the public API more explicit and readable:with!(Person, Age(42))is clearly aPersonquerywith!(Person)andPersonclearly represent whole-population queriesTesting
Added and updated tests to cover:
with!(Entity)empty-query behaviorwith!(Entity, ...)single- and multi-property queriesEntityPropertyTuple