Flecs-Rust icon indicating copy to clipboard operation
Flecs-Rust copied to clipboard

Shorthand for Singleton adding

Open tynberry opened this issue 1 year ago • 5 comments

When you want to add a singleton to query, you need to choose a term using term_at or filter using with and then say it is a singleton.

However it would be nice to have a simpler way to annotate singletons.

I propose two possible solutions, either add with_singleton and singleton that takes term index to merge the two calls or add Singleton<T> generic struct which can take a component to mark as singleton, similar to Option<T> marking as optional.

tynberry avatar Oct 08 '24 07:10 tynberry

@tynberry Singleton<T> should be possible with_singleton and singleton are out of the question. Sander, flecs itself, is opposed against those sort of small utility functions as it adds maintenance burden and I'd like to stick close enough to the CPP API as well.

also note there's the DSL macro exactly for this reason:

    system!(
        "processing_xxx_system",
        world,
        &mut ProcessingState ($), //singleton
        &AsyncTaskSender,
    )
    ```

Indra-db avatar Oct 15 '24 07:10 Indra-db

@tynberry do you want to PR Singleton<T> or should I add it to the backlog for myself?

Indra-db avatar Oct 15 '24 07:10 Indra-db

I might look at it but you can keep it on backlog.

I know about the DSL macros, but from my experience of a low end computer user, rust analyzer does not work very well or at least as fast with them. I might look at them as well, but macros are still magic to me.

tynberry avatar Oct 15 '24 08:10 tynberry

@tynberry yeah RA with macro's don't work great until the macro is somewhat finished. Be sure to use the vs-code expand macro in case you're wondering what it produces

image

Indra-db avatar Oct 15 '24 08:10 Indra-db

the DSL macro mostly follows the convention from here https://www.flecs.dev/flecs/md_docs_2FlecsQueryLanguage.html

but with some small differences (documented)

Indra-db avatar Oct 15 '24 08:10 Indra-db

replaced with trait usage.

Indra-db avatar Oct 27 '25 12:10 Indra-db