Dynamically typed queries
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 1.4k
- Forks
- 107
- Avg merge
- 2h
- Merged PRs (30d)
- 6
Description
hecs could be extended with support for executing queries constructed at runtime rather than specified statically in types. This could be useful for e.g. interactively user-specified queries or for running queries in embedded scripting environments.
An implementation could look something like:
impl World {
fn query_dynamic(&self, q: DynamicQuery) -> DynamicQueryBorrow<'_>;
}
pub enum DynamicQuery {
Get(TypeId),
GetMut(TypeId),
And(Vec<DynamicQuery>),
}
where DynamicQueryBorrow<'_> contains an iterator which yields DynamicQueryItem which has
impl DynamicQueryItem<'_> {
fn get<T: Component>(&self) -> Option<&T>;
fn get_mut<T: Component>(&self) -> Option<&mut T>;
}
or perhaps
impl DynamicQueryItem<'_> {
fn get(&self, ty: TypeId) -> Option<&dyn Any>;
fn get_mut(&self, ty: TypeId) -> Option<&mut dyn Any>;
}
This is complex enough that I'm not likely to work on it unless there's significant demand, so please leave a comment describing your use case if you're interested!
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
The issue proposes a new World::query_dynamic entry point with DynamicQuery, DynamicQueryBorrow, and DynamicQueryItem types, but names no files or tests. Start by reviewing the existing query API and resolving the proposed access model; done would require an agreed design and a complete implementation for runtime-constructed queries.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- backend-api-design
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100