Struct shipyard::WorkloadBuilder[][src]

pub struct WorkloadBuilder<'a> { /* fields omitted */ }
Expand description

Keeps information to create a workload.

Implementations

Adds a system to the workload been created.
It is strongly recommanded to use the system and try_system macros.
If the two functions in the tuple don’t match, the workload could fail to run every time.

Example:

use shipyard::{system, EntitiesViewMut, IntoIter, Shiperator, View, ViewMut, World};

fn add(mut usizes: ViewMut<usize>, u32s: View<u32>) {
    for (x, &y) in (&mut usizes, &u32s).iter() {
        *x += y as usize;
    }
}

fn check(usizes: View<usize>) {
    let mut iter = usizes.iter();
    assert_eq!(iter.next(), Some(&1));
    assert_eq!(iter.next(), Some(&5));
    assert_eq!(iter.next(), Some(&9));
}

let world = World::new();

world.run(
    |mut entities: EntitiesViewMut, mut usizes: ViewMut<usize>, mut u32s: ViewMut<u32>| {
        entities.add_entity((&mut usizes, &mut u32s), (0, 1));
        entities.add_entity((&mut usizes, &mut u32s), (2, 3));
        entities.add_entity((&mut usizes, &mut u32s), (4, 5));
    },
);

world
    .add_workload("Add & Check")
    .with_system((|world: &World| world.try_run(add), add))
    .with_system(system!(check))
    .build();

world.run_default();

Finishes the workload creation and store it in the World.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The alignment of pointer.

The type for initializers.

Initializes a with the given initializer. Read more

Dereferences the given pointer. Read more

Mutably dereferences the given pointer. Read more

Drops the object pointed to by the given pointer. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.