#[derive(ParticleType)]Expand description
Derive macro for particle type enums.
Creates type-safe particle categories that convert to/from u32 for GPU usage.
Variants are assigned sequential IDs starting from 0.
§Generated Items
For an enum Species:
impl From<Species> for u32- Convert variant to integerimpl From<u32> for Species- Convert integer to variant (invalid values default to first variant)Species::count() -> u32- Returns number of variants
§Requirements
- Must be an enum (not a struct)
- All variants must be unit variants (no fields)
- Enum should also derive
Clone,Copy,PartialEqfor typical usage
§Example
ⓘ
#[derive(ParticleType, Clone, Copy, PartialEq)]
enum Species {
Prey, // = 0
Predator, // = 1
Plant, // = 2
}
// Convert to u32 for rules
let prey_id: u32 = Species::Prey.into(); // 0
// Use with typed rules
Rule::Chase {
self_type: Species::Predator.into(),
target_type: Species::Prey.into(),
radius: 0.3,
strength: 2.0,
}
// Use in spawner
Creature {
position: pos,
velocity: Vec3::ZERO,
particle_type: Species::Prey.into(),
}
// Get variant count
let num_species = Species::count(); // 3§Panics
The macro panics at compile time if:
- Applied to a struct instead of an enum
- Any variant has fields (tuple or struct variants)
- Enum has zero variants