Comments (4)
is it possible in the derive macro to detect the lacking default impl and report on it?
Unfortunately no. Macros don't have any type information available to them, including what traits a type implements.
Opt out of FromReflect by adding #[reflect(from_reflect = false)] to your Bar type
If I was guided towards this in the error msg that would have helped me right away, which would be very nice
Yeah ideally we would do this, but it's not possible to know whether or not a type implements Default
via the macro. We'd have to generate this error based on the lack of default
attributes when not opting out, which may be controversial compared to just returning None
.
from bevy.
This is actually expected behavior since FromReflect
(which is automatically derived alongside Reflect
) requires Default
for ignored fields.
There are two possible solutions besides implementing Default
for Foo
:
- Opt out of
FromReflect
by adding#[reflect(from_reflect = false)]
to yourBar
type - Add a custom default function for
Foo
like#[reflect(ignore, default = "create_foo")]
,#[reflect(ignore, default = "Foo::new")]
, etc.
Hopefully that helps!
from bevy.
As for how we can avoid this in the future, I think we could update the macro code to make FromReflect
opt-in. If any field is ignored, we can skip implementing FromReflect
unless a default
attribute is set for that field. I did something like this in #13432.
One possible issue is that this would mean that users won't be 100% sure their type implements FromReflect
unless they try to use it.
from bevy.
As for how we can avoid this in the future, I think we could update the macro code to make
FromReflect
opt-in. If any field is ignored, we can skip implementingFromReflect
unless adefault
attribute is set for that field. I did something like this in #13432.One possible issue is that this would mean that users won't be 100% sure their type implements
FromReflect
unless they try to use it.
If this is a longer term solution, is the near term is it possible in the derive macro to detect the lacking default impl and report on it?
Opt out of FromReflect by adding #[reflect(from_reflect = false)] to your Bar type
If I was guided towards this in the error msg that would have helped me right away, which would be very nice
from bevy.
Related Issues (20)
- `DirectNestedLoader::load` sometimes uses asset type's default loader instead of inspecting path
- simple_picking.rs example has an observer on a 3d mesh but no picking backend HOT 3
- TAA code contains an uncached query for 3D cameras
- Texture atlases should use atlas layouts, not atlas indices HOT 1
- Improve diagnostics for or interdict the panic "font size cannot be 0" HOT 1
- Allow plugins to define component requirements HOT 7
- Panic when lazily adding multiple observers HOT 2
- `run_system_cached` API will reject systems created by `pipe` and `map` HOT 1
- Implement KeyboardFocus resource and focus keyboard events
- Add CursorIcon::Hidden HOT 1
- Add docs to `RawHandleWrapper::_window` field HOT 1
- Framerate drop after turning on WinitSettings::desktop_app() HOT 3
- Logging for system parameter validation should be configurable HOT 2
- Animation's reflection trait bounds can be simplified
- `NonEmptyEventReader` system parameter
- Respect `SystemParam::validate_param` for observers and other non-executor system runners
- `missing-metadata` workflow fails and posts a misleading comment if `Cargo` itself breaks HOT 1
- Horizontal scroll does not work in `scroll` example HOT 2
- Colored glass should cast colored shadows HOT 4
- Transmission / opacity should affect shadow strength HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from bevy.