-
-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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
#[derive(WorldQuery)] on Foo produces FooState which docs don't really mention #6264
Comments
This is a bit tougher, I think, because some of the types generated by An API solution for this (as opposed to just updating docs) would probably require adding a capability to customize the names of all those generated types.e.g.: #[derive(WorldQuery)]
#[world_query(mutable, state_type_name = "ActionWorldQueryState")] // item_type_name=, ro_item_type_name="" etc.
struct Action { ... } I've seen this done by other proc-macro crates, such as derive_builder with its |
There isn't any reason that you should need access to the The case of adding accessors to the That is, we should avoid creating any new structs in the local namespace under any circumstances, but allow the user's own struct which matches the correct layout to be used if desired. |
What's the point in making users create their own |
Broadly, to mitigate the issue that tooling does not like it when item names collide, and fails to provide adequate diagnostics/suggestions when that case does occur. I thought it was therefore unidiomatic to create new items in a derive macro, although the docs I can find don't suggest that. In addition, a number of My point is more broadly that we should not be in the business of choosing names to pollute the local namespace with. My updated position would be that we can have three cases:
I would predict that ~75% of cases should use the first form, so polluting the local scope is not a good default. |
I think im on board with those 3 points you listed, ive definitely wanted something like 3 in the past. when gats land |
This seems to be resolved as of #6877. Is there something else that this issue still requires addressing? |
no, that PR doesn't do anything about the |
Bevy version
bevy v0.8.1
What you did
I was trying to make a
WorldQuery
item (and theSystemParam
) forbig_brain
's common query item:Both
Actor
andActionState
are types frombig_brain
.What went wrong
Got very confusing compilation errors about
ActionState
not implementingComponent
, even thoughbig_brain::ActionState
does implement it.It was doubly-confusing because when I tried to see the definition of
ActionState
to check, rust-analyzer would point me back to my ownAction
struct. It basically looked like rust-analyzer was confused and/or broke.Additional information
I have since traced the problem to the fact that
WorldQuery
derive produces a-State
type in addition to-Item
and-ReadOnly
. This is touched upon very lightly inWorldQuery
docs that say:but it doesn't explicitly mention their names (which, in addition to
FooState
, I presume also includesFooFetch
).Suggestion
Any derive macro that introduces new symbols to the module namespace should have all those symbols clearly outlined in the docs, preferably close to the beginning, and possibly as a prominent note/warning.
The text was updated successfully, but these errors were encountered: