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
sourceimpl 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();
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: &mut Workload) -> Workload
pub fn merge(self, other: &mut 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, S: IntoWorkloadSystem<B, ()>>(self, system: S) -> Workload
pub fn with_system<B, S: IntoWorkloadSystem<B, ()>>(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();
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, 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();
sourcepub fn add_to_world(self, world: &World) -> Result<WorkloadInfo, AddWorkload>
pub fn add_to_world(self, world: &World) -> Result<WorkloadInfo, AddWorkload>
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>
Trait Implementations
sourceimpl Extend<WorkloadSystem> for Workload
impl Extend<WorkloadSystem> for Workload
sourcefn extend<T: IntoIterator<Item = WorkloadSystem>>(&mut self, iter: T)
fn extend<T: IntoIterator<Item = WorkloadSystem>>(&mut self, iter: T)
Extends a collection with the contents of an iterator. Read more
sourcefn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one
)Extends a collection with exactly one element.
sourcefn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one
)Reserves capacity in a collection for the given number of additional elements. Read more
sourceimpl IntoWorkload<Workload, Workload> for Workload
impl IntoWorkload<Workload, Workload> for Workload
sourcefn into_workload(self) -> Workload
fn into_workload(self) -> Workload
Converts to a collection of systems. Read more
sourcefn into_sequential_workload(self) -> Workload
fn into_sequential_workload(self) -> Workload
sourceimpl WorkloadModificator for Workload
impl WorkloadModificator for Workload
sourcefn run_if<RunB, Run: IntoWorkloadRunIf<RunB>>(self, run_if: Run) -> Workload
fn run_if<RunB, Run: IntoWorkloadRunIf<RunB>>(self, run_if: Run) -> Workload
Only run the workload if the function evaluates to true
.
sourcefn run_if_storage_empty<T: Component>(self) -> Workload
fn run_if_storage_empty<T: Component>(self) -> Workload
Only run the workload if the T
storage is empty. Read more
sourcefn run_if_missing_unique<T: Unique>(self) -> Workload
fn run_if_missing_unique<T: Unique>(self) -> Workload
Only run the workload if the T
unique storage is not present in the World
.
sourcefn run_if_storage_empty_by_id(self, storage_id: StorageId) -> Workload
fn run_if_storage_empty_by_id(self, storage_id: StorageId) -> Workload
Only run the workload if the storage is empty. Read more
sourcefn skip_if<RunB, Run: IntoWorkloadRunIf<RunB>>(self, should_skip: Run) -> Self
fn skip_if<RunB, Run: IntoWorkloadRunIf<RunB>>(self, should_skip: Run) -> Self
Do not run the workload if the function evaluates to true
.
sourcefn skip_if_storage_empty<T: Component>(self) -> Self
fn skip_if_storage_empty<T: Component>(self) -> Self
Do not run the workload if the T
storage is empty. Read more
sourcefn skip_if_missing_unique<T: Unique>(self) -> Self
fn skip_if_missing_unique<T: Unique>(self) -> Self
Do not run the workload if the T
unique storage is not present in the World
.
sourcefn skip_if_storage_empty_by_id(self, storage_id: StorageId) -> Self
fn skip_if_storage_empty_by_id(self, storage_id: StorageId) -> Self
Do not run the workload if the storage is empty. Read more
sourcefn before_all<T>(self, other: impl AsLabel<T>) -> Workload
fn before_all<T>(self, other: impl AsLabel<T>) -> Workload
When building a workload, all systems within this workload will be placed before all invocation of the other system or workload.
Auto Trait Implementations
impl !RefUnwindSafe for Workload
impl Send for Workload
impl Sync for Workload
impl Unpin for Workload
impl !UnwindSafe for Workload
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> Instrument for T
impl<T> Instrument for T
sourcefn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
sourcefn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
impl<T> Pointable for T
impl<T> Pointable for T
sourceimpl<T> WithSubscriber for T
impl<T> WithSubscriber for T
sourcefn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
Attaches the provided Subscriber
to this type, returning a
WithDispatch
wrapper. Read more
sourcefn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
Attaches the current default Subscriber
to this type, returning a
WithDispatch
wrapper. Read more