Expand description
Probar Derive Macros: Type-Safe ECS Selectors (Poka-Yoke)
Per spec Section 4: This crate provides derive macros that eliminate “stringly-typed” selectors, making it impossible to write invalid entity or component queries at compile time.
§Toyota Way: Poka-Yoke (Mistake-Proofing)
Instead of runtime errors from typos:
ⓘ
// BAD: Stringly-typed, prone to typos (runtime error)
let player = game.entity("playr"); // Typo! Runtime panicUse compile-time checked selectors:
ⓘ
// GOOD: Type-safe, compile-time checked (Poka-Yoke)
#[derive(ProbarEntity)]
struct Player;
let player = game.entity::<Player>(); // Compile error if wrong§Available Macros
ProbarEntity- Derive for entity type markersProbarComponent- Derive for component type inspectionProbarSelector- Generate type-safe selector enums
§Example
ⓘ
use probar_derive::{ProbarEntity, ProbarComponent, ProbarSelector};
// Define entity markers
#[derive(ProbarEntity)]
#[probar(name = "player")]
struct Player;
#[derive(ProbarEntity)]
#[probar(name = "enemy")]
struct Enemy;
// Define components
#[derive(ProbarComponent)]
struct Position {
x: f32,
y: f32,
}
#[derive(ProbarComponent)]
struct Health {
current: u32,
max: u32,
}
// Generate selector enum
#[derive(ProbarSelector)]
#[probar(entities = [Player, Enemy])]
#[probar(components = [Position, Health])]
struct GameSelectors;
// Usage in tests (compile-time safe!)
async fn test_player_movement() {
let game = StateBridge::new();
// Type-safe entity access
let player = game.entity::<Player>().await?;
// Type-safe component access
let pos: Position = game.component::<Position>(player)?;
assert!(pos.x > 0.0);
}Attribute Macros§
- probar_
test - Attribute macro for marking test functions with Probar metadata.
Derive Macros§
- Probar
Component - Derive macro for type-safe component inspection.
- Probar
Entity - Derive macro for type-safe entity markers.
- Probar
Selector - Derive macro for generating type-safe selector enums.