Struct shipyard::WorkloadBuilder [−][src]
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]
&mut self,
workload: W
) -> &mut Self
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]
&mut self,
system: S
) -> &mut Self
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]
&mut self,
system: S
) -> &mut Self
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]
&mut self,
world: &World
) -> Result<WorkloadInfo, AddWorkload>
Trait Implementations
impl Default for WorkloadBuilder
[src]
fn default() -> WorkloadBuilder
[src]
impl Extend<WorkloadSystem> for WorkloadBuilder
[src]
fn extend<T: IntoIterator<Item = WorkloadSystem>>(&mut self, iter: T)
[src]
pub fn extend_one(&mut self, item: A)
[src]
pub fn extend_reserve(&mut self, additional: usize)
[src]
Auto Trait Implementations
impl !RefUnwindSafe for WorkloadBuilder
impl Send for WorkloadBuilder
impl Sync for WorkloadBuilder
impl Unpin for WorkloadBuilder
impl !UnwindSafe for WorkloadBuilder
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> Pointable for T
pub const ALIGN: usize
type Init = T
The type for initializers.
pub unsafe fn init(init: <T as Pointable>::Init) -> usize
pub unsafe fn deref<'a>(ptr: usize) -> &'a T
pub unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T
pub unsafe fn drop(ptr: usize)
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,