Struct shipyard::WorkloadBuilder[][src]

pub struct WorkloadBuilder { /* fields omitted */ }

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

impl WorkloadBuilder[src]

pub fn new<N: Into<Cow<'static, str>>>(name: N) -> Self[src]

Creates a new empty WorkloadBuilder.

Example

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

fn add(mut usizes: ViewMut<usize>, u32s: View<u32>) {
    for (mut 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 mut world = World::new();

world.add_entity((0usize, 1u32));
world.add_entity((2usize, 3u32));
world.add_entity((4usize, 5u32));

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

world.run_default();

pub fn append(&mut self, other: &mut Self) -> &mut Self[src]

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

pub fn with_workload<W: Into<Cow<'static, str>> + 'static>(
    &mut self,
    workload: W
) -> &mut Self
[src]

Nests a workload by adding all its systems.
This other workload must be present in the World by the time add_to_world is called.

pub fn with_system<B, R, S: IntoWorkloadSystem<B, R>>(
    &mut self,
    system: S
) -> &mut Self
[src]

Adds a system to the workload being created.

Example:

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

fn add(mut usizes: ViewMut<usize>, u32s: View<u32>) {
    for (mut 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 mut world = World::new();

world.add_entity((0usize, 1u32));
world.add_entity((2usize, 3u32));
world.add_entity((4usize, 5u32));

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

world.run_default();

pub fn with_try_system<B, Ok, Err: 'static + Into<Box<dyn Error + Send + Sync>>, R: Into<Result<Ok, Err>>, S: IntoWorkloadSystem<B, R>>(
    &mut self,
    system: S
) -> &mut Self
[src]

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

Example:

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

fn add(mut usizes: ViewMut<usize>, u32s: View<u32>) {
    for (mut x, &y) in (&mut usizes, &u32s).iter() {
        *x += y 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((0usize, 1u32));
world.add_entity((2usize, 3u32));
world.add_entity((4usize, 5u32));

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

world.run_default();

pub fn add_to_world(
    &mut self,
    world: &World
) -> Result<WorkloadInfo, AddWorkload>
[src]

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.

Trait Implementations

impl Default for WorkloadBuilder[src]

impl Extend<WorkloadSystem> for WorkloadBuilder[src]

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> Pointable for T

type Init = T

The type for initializers.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.