-
-
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
static assert that bundles do not have duplicate types #2388
static assert that bundles do not have duplicate types #2388
Conversation
As a quick note, this is sort of a first pass solution. |
Another option would be to have |
This is how the current implementation is conducted... 🙃 (I'm pretty sure?) |
Oops, I thought it used a trait method and then error on ambiguity or something like that. |
This should now also work with nested bundles!! :) Edit: nvm, cross-crate implementations are giving me problems..... |
Currently this implementation only support a single layer of checking. #[derive(Bundle)]
struct A {
a: usize,
b: usize,
} will fail to compile because However, #[derive(Bundle)]
struct A {
a: usize,
}
#[derive(Bundle)]
struct A {
#[bundle]
a: A,
b: usize,
} will still compile since you cannot implement traits for foreign types... I still think this addition is a nice QOL improvement, however we should keep an issue open to track nested bundle static checking. |
@TheRawMeatball I'm curious what your thoughts are with this issue. |
IMO failing if we know something is incorrect is worth doing, even if we can't catch every case. |
Going on a tangent about nested bundles: is the possibility to do it really worth it? I'm not completely convinced. The issues raised in #1588 and #2331 when trying to use it are valid, and if we don't even use it in standard Bevy I would argue this should be removed. I would prefer having bundles be statically checked over having nested bundles. |
I'd strongly prefer nested bundles over fully static assertions personally. They're very useful for spawning more complex entities. |
#[derive(Bundle, Debug)]
pub struct Position {
pub x: u8,
pub y: u8,
} gives:
|
Looks pretty good to me! Hopefully in the far future when more rust features are stable we can make it work for nested stuff too, but for now this seems like a useful compromise. |
I just realized, this impl may not work with generic bundles.... |
There's a few problems with the PR, including generic bundles, and not being able to recurse and check nested bundles. |
Objective
Solution
#[derive(Bundle)]
will fail to compile if any of the inner types are duplicates.