Struct shred::ParSeq

source ·
pub struct ParSeq<P, T> { /* private fields */ }
Expand description

A dispatcher intended to be used with Par and Seq structures.

This is more flexible and performant than Dispatcher, however, you have to check conflicts yourself. That means you cannot run two systems in parallel which write to the same resource; if you’d do that, one of the systems will panic while trying to fetch the SystemData.

Thread-local systems

This dispatcher also allows more freedom for thread-local systems; you can execute wherever you want, just not in parallel with other systems (putting one inside par! will give you a compile-time error saying the Send requirement is unmet).

Examples

#[macro_use(par, seq)]
extern crate shred;


let x = 5u8;

let mut dispatcher = ParSeq::new(
    seq![
        par![SysA, SysWithLifetime(&x), seq![SysC, SysD,],],
        SysB,
        SysLocal(&x as *const u8),
    ],
    &pool,
);

dispatcher.dispatch(&mut world);

Implementations§

source§

impl<P, T> ParSeq<P, T>
where P: Borrow<ThreadPool>, T: for<'a> RunWithPool<'a>,

source

pub fn new(run: T, pool: P) -> Self

Creates a new ParSeq dispatcher. run is usually created by using the par! / seq! macros.

source

pub fn setup(&mut self, world: &mut World)

Sets up world for dispatching. This will add default values for required resources by calling System::setup.

source

pub fn dispatch(&mut self, world: &World)

Dispatches the systems using world. This doesn’t call any virtual functions.

Please note that this method assumes that no resource is currently borrowed. If that’s the case, it panics.

Trait Implementations§

source§

impl<'a, P, T> RunNow<'a> for ParSeq<P, T>
where P: Borrow<ThreadPool>, T: for<'b> RunWithPool<'b>,

source§

fn run_now(&mut self, world: &World)

Runs the system now. Read more
source§

fn setup(&mut self, world: &mut World)

Sets up World for a later call to run_now.
source§

fn dispose(self: Box<Self>, world: &mut World)

Performs clean up that requires resources from the World. This commonly removes components from world which depend on external resources.

Auto Trait Implementations§

§

impl<P, T> RefUnwindSafe for ParSeq<P, T>

§

impl<P, T> Send for ParSeq<P, T>
where P: Send, T: Send,

§

impl<P, T> Sync for ParSeq<P, T>
where P: Sync, T: Sync,

§

impl<P, T> Unpin for ParSeq<P, T>
where P: Unpin, T: Unpin,

§

impl<P, T> UnwindSafe for ParSeq<P, T>
where P: UnwindSafe, T: UnwindSafe,

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

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

§

impl<T> Pointable for T

§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

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

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<T> Resource for T
where T: Any + Send + Sync,