Crates.io | bevy_trait |
lib.rs | bevy_trait |
version | |
source | src |
created_at | 2023-03-01 22:38:50.072074+00 |
updated_at | 2025-03-31 01:03:23.319615+00 |
description | Macros for creating Traits in Bevy |
homepage | |
repository | https://github.com/hankjordan/bevy_trait |
max_upload_size | |
id | 798391 |
Cargo.toml error: | TOML parse error at line 17, column 1 | 17 | autolib = false | ^^^^^^^ unknown field `autolib`, expected one of `name`, `version`, `edition`, `authors`, `description`, `readme`, `license`, `repository`, `homepage`, `documentation`, `build`, `resolver`, `links`, `default-run`, `default_dash_run`, `rust-version`, `rust_dash_version`, `rust_version`, `license-file`, `license_dash_file`, `license_file`, `licenseFile`, `license_capital_file`, `forced-target`, `forced_dash_target`, `autobins`, `autotests`, `autoexamples`, `autobenches`, `publish`, `metadata`, `keywords`, `categories`, `exclude`, `include` |
size | 0 |
Macros for creating Traits in Bevy.
Turn a trait fn into a Bevy system
trait Interactive {
#[system]
fn update(damage: f32);
}
/*
// Desugars to
trait Interactive {
fn update(damage: f32) -> impl System;
}
*/
#[derive(Component)]
struct Health(f32);
#[derive(Component, Copy, Clone)]
struct Cactus;
impl Interactive for Cactus {
#[system(damage: f32)]
fn update(
cacti: Query<&GlobalTransform, With<Cactus>>,
creatures: Query<(&GlobalTransform, &mut Health), Without<Cactus>>,
) {
// This is a normal Bevy system and accepts SystemParams as such.
for cactus_gtf in &cacti {
info!("Damage {:?}", damage); // You can also use params passed into the System builder.
// ...
}
}
}
fn run() {
let system = Cactus::update(42); // This is a System ...
App::new()
.add_plugins(DefaultPlugins)
.add_systems(Update, system) // ... that you can add to an App
.run();
}
Since bevy_trait
does not rely on bevy
directly, it is typically compatible across many different versions.
Bevy Version | Crate Version |
---|---|
0.15 |
0.3 |
0.10 , 0.11 , 0.12 , 0.13 , 0.14 |
0.1 , 0.2 |
bevy_trait
is dual-licensed under MIT and Apache-2.0.