-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Why use strings as labels? #103
Comments
This is a reasonable proposal. I'll need to give it some thought (and maybe some experimentation to see how it affects ergonomics). But the points you make are all valid and I don't think it would cause any "usability regressions". |
Just my 2c, making a const str then using that would solve your type checking & documentation points, and possibly also scoping but I haven't thought about it too much. |
This is similar to The way I approached this in It might be possible to use the same tricks here, with effectively no API change from the perspective of a user - other than providing them with the option to use something other than strings to differentiate between stages. |
There are some problems with serializing type IDs over time / across crates, see #32. I think the const str approach is alright, those actually exist for the default stages. It's simple and straightforward to understand, and the user doesn't have to deal with wacky reflection issues / generics, which can be a big barrier for inexperienced rust users. Imo a good compromise would be strings + documentation of the "use a const string" best practice. |
I'd probably consider the scoping the most valuable part of this. Allowing the reader to understand a system locally using the privacy of the types could enable better abstractions, by providing guarantees about the Bevy's state within the private stages. More API considerations would need to be made to get the most out of this kind of privacy of course. I suppose I'm saying it's a trade-off, and types-as-ids have interesting properties for developers As I understand it, the ECS stages would never need to be serialized, so that shouldn't be an issue. Am I mistaken? |
Lots of good conversation here. Something that I haven't called out yet: stages must have human readable string names for the (eventual) editor schedule visualization tools. We could still have that with typed stages, but we would need them to implement a trait that returns a name. |
Maybe you could just allow anything that's |
What about a combined approach, type ID + the hash? This allows using ZSTs as well as sized types (which can also be module-local), allowing scoping and things like strings. Name-providing trait would still be necessary, but possibly can be blanket implemented on many of the applicable types. (Side note: the Edit re: side note. There won't be any need in dummy handle tricks if stages are keyed by literally |
There was some detailed discussion and analysis on this in #1021 starting here. @cart's tentative conclusion was "any key + type constraints + derives" seems to be the best solution, but this is worth considering a bit further I think. In addition, we're running into a virtually identical issue with system labels, relevant to #1144. We will probably want to mirror the solution we settle on to system labels as well. |
I implemented a version of this here: https://github.com/TheRawMeatball/bevy/tree/zst-labels |
In the interest of having options conscisely listed in one place, here's an example (and implementation driving it) of that "any key + type constraints + derives" pattern (which I've been referring to as "heterogeneous key trick"). A "real" implementation would also include a derive macro for |
Fixed in 0.5. |
add a system to run the enter schedule of the initial state
Why have you opted to use strings as labels in Bevy's APIs? It seems strictly less expressive than using ZSTs for the same purpose.
The text was updated successfully, but these errors were encountered: