Commit c036682
Merge amethyst#1883
1883: Improvement/system desc ergonomics r=jojolepro a=azriel91
## Description
Extend `SystemDesc` derive to generate implementation for system with event channel reader fields. Essentially:
```patch
-#[derive(Debug)]
+#[derive(Debug, SystemDesc)]
+#[system_desc(name(SystemWithEventChannelDesc))]
struct SystemWithEventChannel {
+ #[system_desc(event_channel_reader)]
u32_reader: ReaderId<u32>,
}
-use amethyst_core::SystemDesc;
-
-/// Builds a `SystemWithEventChannel`.
-#[derive(Default, Debug)]
-pub struct SystemWithEventChannelDesc;
-
-impl<'a, 'b> SystemDesc<'a, 'b, SystemWithEventChannel> for SystemWithEventChannelDesc {
- fn build(self, world: &mut World) -> SystemWithEventChannel {
- <SystemWithEventChannel as System<'_>>::SystemData::setup(world);
-
- let u32_reader = world.fetch_mut::<EventChannel<u32>>().register_reader();
-
- SystemWithEventChannel::new()
- }
-}
```
**Note:** built on top of amethyst#1882, so build is green. See commit 932a58d onwards
## Modifications
* `SystemDesc` proc macro supports `#[system_desc(event_reader_id)]` to register event reader.
## PR Checklist
By placing an x in the boxes I certify that I have:
- [x] Updated the content of the book if this PR would make the book outdated.
- [x] Added a changelog entry if this will impact users, or modified more than 5 lines of Rust that wasn't a doc comment.
- [x] Added unit tests for new code added in this PR.
- [x] Acknowledged that by making this pull request I release this code under an MIT/Apache 2.0 dual licensing scheme.
If this modified or created any rs files:
- [x] Ran `cargo +stable fmt --all`
- [x] Ran `cargo clippy --all --features "empty"`
- [x] Ran `cargo test --all --features "empty"`
Co-authored-by: Azriel Hoh <[email protected]>File tree
4 files changed
+719
-83
lines changed- amethyst_derive
- src
- tests
- amethyst_ui/src
- docs
4 files changed
+719
-83
lines changed
0 commit comments