Function moonshine_check::panic
source · pub fn panic() -> PolicyExpand description
Returns a Policy which despawns matching instances and all of their children.
§Usage
Use this policy if you want to panic! on invalid entities.
In general, you should avoid using this policy as it can make your application unstable.
It is recommended to use invalid or purge instead, especially in a production environment.
§Example
ⓘ
use bevy::prelude::*;
use moonshine_check::prelude::*;
#[derive(Bundle, Default)]
struct AB {
a: A,
b: B,
}
#[derive(Component, Default)]
struct A;
#[derive(Component, Default)]
struct B;
let mut app = App::new();
app.add_plugins(MinimalPlugins)
.check::<A, Without<B>>(panic())
.add_systems(Update, update);
app.world_mut().spawn(AB::default()); // OK!
app.world_mut().spawn(A); // Bug! `B` is missing!
app.update();
fn update(items: Query<Entity, With<A>>, query: Query<&B>) {
// Guaranteed:
unreachable!();
}