pub struct Workload { /* private fields */ }
Expand description

Keeps information to create a workload.

A workload is a collection of systems. They will execute as much in parallel as possible.
They are evaluated first to last when they can’t be parallelized.
The default workload will automatically be set to the first workload added.

Implementations

Creates a new empty Workload.

Example
use shipyard::{Component, IntoIter, View, ViewMut, Workload, World};

#[derive(Component, Clone, Copy)]
struct U32(u32);

#[derive(Component, Debug, PartialEq, Eq)]
struct USIZE(usize);

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

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

let mut world = World::new();

world.add_entity((USIZE(0), U32(1)));
world.add_entity((USIZE(2), U32(3)));
world.add_entity((USIZE(4), U32(5)));

Workload::new("Add & Check")
    .with_system(add)
    .with_system(check)
    .add_to_world(&world)
    .unwrap();

world.run_default();

Moves all systems of other into Self, leaving other empty.
This allows us to collect systems in different builders before joining them together.

Propagates all information from self and other into their respective systems before merging their systems.
This includes run_if/skip_if, tags, before/after requirements.

Adds a system to the workload being created.

Example:
use shipyard::{Component, EntitiesViewMut, IntoIter, View, ViewMut, Workload, World};

#[derive(Component, Clone, Copy)]
struct U32(u32);

#[derive(Component, Debug, PartialEq, Eq)]
struct USIZE(usize);

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

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

let mut world = World::new();

world.add_entity((USIZE(0), U32(1)));
world.add_entity((USIZE(2), U32(3)));
world.add_entity((USIZE(4), U32(5)));

Workload::new("Add & Check")
    .with_system(add)
    .with_system(check)
    .add_to_world(&world)
    .unwrap();

world.run_default();

Adds a fallible system to the workload being created.
The workload’s execution will stop if any error is encountered.

Example:
use shipyard::{Component, EntitiesViewMut, Get, IntoIter, IntoWithId, View, ViewMut, Workload, World};
use shipyard::error::MissingComponent;

#[derive(Component, Clone, Copy)]
struct U32(u32);

#[derive(Component, Debug, PartialEq, Eq)]
struct USIZE(usize);

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

fn check(usizes: View<USIZE>) -> Result<(), MissingComponent> {
    for (id, i) in usizes.iter().with_id() {
        assert!(usizes.get(id)? == i);
    }

    Ok(())
}

let mut world = World::new();

world.add_entity((USIZE(0), U32(1)));
world.add_entity((USIZE(2), U32(3)));
world.add_entity((USIZE(4), U32(5)));

Workload::new("Add & Check")
    .with_system(add)
    .with_try_system(check)
    .add_to_world(&world)
    .unwrap();

world.run_default();

Finishes the workload creation and stores it in the World.
Returns a struct with describing how the workload has been split in batches.

Borrows
  • Scheduler (exclusive)
Errors
  • Scheduler borrow failed.
  • Workload with an identical name already present.
  • Nested workload is not present in world.

Returns the first Unique storage borrowed by this workload that is not present in world.
If the workload contains nested workloads they have to be present in the World.

Borrows
  • AllStorages (shared)

Build the Workload from the Workload.

Trait Implementations

Extends a collection with the contents of an iterator. Read more

🔬 This is a nightly-only experimental API. (extend_one)

Extends a collection with exactly one element.

🔬 This is a nightly-only experimental API. (extend_one)

Reserves capacity in a collection for the given number of additional elements. Read more

Converts to a collection of systems. Read more

Converts to a collection of systems.
All systems will run one after the other. Does not propagate into nested Workload but they will run sequentially between them. Read more

Only run the workload if the function evaluates to true.

Only run the workload if the T storage is empty. Read more

Only run the workload if the T unique storage is not present in the World.

Only run the workload if the storage is empty. Read more

Do not run the workload if the function evaluates to true.

Do not run the workload if the T storage is empty. Read more

Do not run the workload if the T unique storage is not present in the World.

Do not run the workload if the storage is empty. Read more

When building a workload, all systems within this workload will be placed before all invocation of the other system or workload.

When building a workload, all systems within this workload will be placed after all invocation of the other system or workload.

Changes the name of this workload.

Adds a tag to this workload. Tags can be used to control system ordering when running workloads.

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

Returns the argument unchanged.

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more

Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

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.

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more