RunSystemLoop

Trait RunSystemLoop 

Source
pub trait RunSystemLoop: Sized {
    // Required method
    fn run_system_loop_with<InputSource, T, I, Out, Marker>(
        self,
        n: usize,
        input: InputSource,
        system: T,
    ) -> Vec<Result<Out, RunSystemError>>
       where T: IntoSystem<I, Out, Marker>,
             I: SystemInput,
             InputSource: FnMut() -> <I as SystemInput>::Inner<'static>;

    // Provided method
    fn run_system_loop<T, Out, Marker>(
        self,
        n: usize,
        system: T,
    ) -> Vec<Result<Out, RunSystemError>>
       where T: IntoSystem<(), Out, Marker> { ... }
}
Expand description

A trait similar to bevy_ecs::system::RunSystemOnce, but it runs a system multiple times.

This is useful for testing multiple iterations of a system.

Required Methods§

Source

fn run_system_loop_with<InputSource, T, I, Out, Marker>( self, n: usize, input: InputSource, system: T, ) -> Vec<Result<Out, RunSystemError>>
where T: IntoSystem<I, Out, Marker>, I: SystemInput, InputSource: FnMut() -> <I as SystemInput>::Inner<'static>,

Runs a system n times with the given input source, returning a Vec of the outputs.

§Example
use bevy::prelude::*;
use moonshine_util::diagnostics::RunSystemLoop;

let mut world = World::new();
let mut names = vec!["Alice", "Bob", "Charlie"];
let entities = world.run_system_loop_with(
    3,
    || names.pop().unwrap().to_owned(),
    |In(name): In<String>, mut commands: Commands| {
        commands.spawn(Name::new(name));
    });

assert_eq!(entities.len(), 3);
assert_eq!(world.query::<&Name>().iter(&mut world).count(), 3);

Provided Methods§

Source

fn run_system_loop<T, Out, Marker>( self, n: usize, system: T, ) -> Vec<Result<Out, RunSystemError>>
where T: IntoSystem<(), Out, Marker>,

Runs a system n times, returning a Vec of the outputs.

§Example
use bevy::prelude::*;
use moonshine_util::diagnostics::RunSystemLoop;

let mut world = World::new();
let entities = world.run_system_loop(3, |mut commands: Commands| {
    commands.spawn_empty().id()
});

assert_eq!(entities.len(), 3);

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl RunSystemLoop for &mut World

Source§

fn run_system_loop_with<InputSource, T, I, Out, Marker>( self, n: usize, input: InputSource, system: T, ) -> Vec<Result<Out, RunSystemError>>
where T: IntoSystem<I, Out, Marker>, I: SystemInput, InputSource: FnMut() -> <I as SystemInput>::Inner<'static>,

Implementors§