A way to get resources that implements a specific trait.
This crate is highly experimental.
The code is derived and heavily relies on previous work done in bevy-trait-query.
```rust use bevy::prelude::*; use bevytraitresource::{trait_resource, TraitResourceExt};
pub trait IncrementTrait { fn value(&self) -> i32; fn increment(&mut self); }
struct NumberValueResource { value: i32, }
impl IncrementTrait for NumberValueResource { // Trait implementation... }
pub fn incrementvaluesystem(world: &mut World) {
for resopt in world.getresourcestraitmut::
struct SomePlugin;
impl Plugin for SomePlugin {
fn build(&self, app: &mut App) {
app.initresourceas::
You can also register a resource to multiple traits.
rust
impl Plugin for SomePlugin {
fn build(&self, app: &mut App) {
app.init_resource::
app.register_resource_as::<dyn IncrementTrait, NumberValueResource>()
.register_resource_as::<dyn SomeOtherTrait, NumberValueResource>();
}
}
Unregistering.
rust
app.unregisterresourcefrom_trait::