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§
Source§impl Workload
impl Workload
Sourcepub fn new<T>(label: impl AsLabel<T>) -> Self
pub fn new<T>(label: impl AsLabel<T>) -> Self
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_workload();
Sourcepub fn append(self, other: &mut Self) -> Self
pub fn append(self, other: &mut Self) -> Self
Moves all systems of other
into Self
, leaving other
empty.
This allows us to collect systems in different builders before joining them together.
Sourcepub fn merge(self, other: Workload) -> Workload
pub fn merge(self, other: Workload) -> Workload
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.
Sourcepub fn with_workload(self, other: Workload) -> Workload
pub fn with_workload(self, other: Workload) -> Workload
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.
Sourcepub fn with_system<B, R, S: IntoWorkloadSystem<B, R>>(
self,
system: S,
) -> Workload
pub fn with_system<B, R, S: IntoWorkloadSystem<B, R>>( self, system: S, ) -> Workload
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_workload();
Sourcepub fn with_try_system<B, Ok, Err: 'static + Into<Box<dyn Error + Send + Sync>>, R: Into<Result<Ok, Err>>, S: IntoWorkloadTrySystem<B, R>>(
self,
system: S,
) -> Self
pub fn with_try_system<B, Ok, Err: 'static + Into<Box<dyn Error + Send + Sync>>, R: Into<Result<Ok, Err>>, S: IntoWorkloadTrySystem<B, R>>( self, system: S, ) -> Self
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, 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_workload();
Sourcepub fn add_to_world(self, world: &World) -> Result<(), AddWorkload>
pub fn add_to_world(self, world: &World) -> Result<(), AddWorkload>
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)
AllStorages
(shared)- Systems’ storage (exclusive) to enable tracking
§Errors
- Scheduler borrow failed.
- Workload with an identical name already present.
- Nested workload is not present in
world
. AllStorages
borrow failed.- Storage borrow failed.
Sourcepub fn are_all_uniques_present_in_world(
&self,
world: &World,
) -> Result<(), UniquePresence>
pub fn are_all_uniques_present_in_world( &self, world: &World, ) -> Result<(), UniquePresence>
Sourcepub fn build(self) -> Result<(ScheduledWorkload, WorkloadInfo), AddWorkload>
pub fn build(self) -> Result<(ScheduledWorkload, WorkloadInfo), AddWorkload>
Sourcepub fn with_barrier(self) -> Self
pub fn with_barrier(self) -> Self
Stop parallelism between systems before and after the barrier.
Trait Implementations§
Source§impl Extend<WorkloadSystem> for Workload
impl Extend<WorkloadSystem> for Workload
Source§fn extend<T: IntoIterator<Item = WorkloadSystem>>(&mut self, iter: T)
fn extend<T: IntoIterator<Item = WorkloadSystem>>(&mut self, iter: T)
Source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one
)Source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one
)Source§impl IntoWorkload<Workload, Workload> for Workload
impl IntoWorkload<Workload, Workload> for Workload
Source§fn into_workload(self) -> Workload
fn into_workload(self) -> Workload
Source§impl WorkloadModificator for Workload
impl WorkloadModificator for Workload
Source§fn run_if<RunB, Run: IntoWorkloadRunIf<RunB>>(self, run_if: Run) -> Workload
fn run_if<RunB, Run: IntoWorkloadRunIf<RunB>>(self, run_if: Run) -> Workload
true
.Source§fn run_if_storage_empty<T: Component>(self) -> Workload
fn run_if_storage_empty<T: Component>(self) -> Workload
T
storage is empty. Read moreSource§fn run_if_missing_unique<T: Unique>(self) -> Workload
fn run_if_missing_unique<T: Unique>(self) -> Workload
T
unique storage is not present in the World
.Source§fn run_if_storage_empty_by_id(self, storage_id: StorageId) -> Workload
fn run_if_storage_empty_by_id(self, storage_id: StorageId) -> Workload
Source§fn skip_if<RunB, Run: IntoWorkloadRunIf<RunB>>(self, should_skip: Run) -> Self
fn skip_if<RunB, Run: IntoWorkloadRunIf<RunB>>(self, should_skip: Run) -> Self
true
.Source§fn skip_if_storage_empty<T: Component>(self) -> Self
fn skip_if_storage_empty<T: Component>(self) -> Self
T
storage is empty. Read moreSource§fn skip_if_missing_unique<T: Unique>(self) -> Self
fn skip_if_missing_unique<T: Unique>(self) -> Self
T
unique storage is not present in the World
.Source§fn skip_if_storage_empty_by_id(self, storage_id: StorageId) -> Self
fn skip_if_storage_empty_by_id(self, storage_id: StorageId) -> Self
Source§fn before_all<T>(self, other: impl AsLabel<T>) -> Workload
fn before_all<T>(self, other: impl AsLabel<T>) -> Workload
Auto Trait Implementations§
impl Freeze for Workload
impl !RefUnwindSafe for Workload
impl Send for Workload
impl Sync for Workload
impl Unpin for Workload
impl !UnwindSafe for Workload
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more