Struct veloren_client::DispatcherBuilder

pub struct DispatcherBuilder<'a, 'b> {
    current_id: usize,
    map: AHashMap<String, SystemId>,
    pub(crate) stages_builder: StagesBuilder<'a>,
    thread_local: SmallVec<[Box<dyn for<'b> RunNow<'b> + 'b>; 4]>,
    thread_pool: Arc<RwLock<Option<Arc<ThreadPool>>>>,
}
Expand description

Builder for the Dispatcher.

§Barriers

Barriers are a way of sequentializing parts of the system execution. See add_barrier()/with_barrier().

§Examples

This is how you create a dispatcher with a shared thread pool:

let dispatcher: Dispatcher = DispatcherBuilder::new()
    .with(system_a, "a", &[])
    .with(system_b, "b", &["a"]) // b depends on a
    .with(system_c, "c", &["a"]) // c also depends on a
    .with(system_d, "d", &[])
    .with(system_e, "e", &["c", "d"]) // e executes after c and d are finished
    .build();

Systems can be conditionally added by using the add_ functions:

let mut builder = DispatcherBuilder::new()
    .with(system_a, "a", &[]);

if b_enabled {
   builder.add(system_b, "b", &[]);
}

let dispatcher = builder.build();

Fields§

§current_id: usize§map: AHashMap<String, SystemId>§stages_builder: StagesBuilder<'a>§thread_local: SmallVec<[Box<dyn for<'b> RunNow<'b> + 'b>; 4]>§thread_pool: Arc<RwLock<Option<Arc<ThreadPool>>>>

Implementations§

§

impl<'a, 'b> DispatcherBuilder<'a, 'b>

pub fn new() -> DispatcherBuilder<'a, 'b>

Creates a new DispatcherBuilder by using the Default implementation.

The default behaviour is to create a thread pool on finish. If you already have a rayon ThreadPool, it’s highly recommended to configure this builder to use it with with_pool instead.

pub fn is_empty(&self) -> bool

Returns whether or not any system has been added to the builder

pub fn num_systems(&self) -> usize

Returns the number of systems added to the builder

pub fn has_system(&self, system: &str) -> bool

Returns whether or not a specific system has been added to the builder This is useful as add() will throw if a dependency does not exist So you can use this function to check if dependencies are satisfied

pub fn with<T>( self, system: T, name: &str, dep: &[&str], ) -> DispatcherBuilder<'a, 'b>
where T: for<'c> System<'c> + Send + 'a,

Adds a new system with a given name and a list of dependencies. Please note that the dependency should be added before you add the depending system.

If you want to register systems which can not be specified as dependencies, you can use "" as their name, which will not panic (using another name twice will).

Same as add(), but returns self to enable method chaining.

§Panics
  • if the specified dependency does not exist
  • if a system with the same name was already registered.

pub fn add<T>(&mut self, system: T, name: &str, dep: &[&str])
where T: for<'c> System<'c> + Send + 'a,

Adds a new system with a given name and a list of dependencies. Please note that the dependency should be added before you add the depending system.

If you want to register systems which can not be specified as dependencies, you can use "" as their name, which will not panic (using another name twice will).

§Panics
  • if the specified dependency does not exist
  • if a system with the same name was already registered.

pub fn contains(&self, name: &str) -> bool

Returns true if a system with the given name has been added to the BispatcherBuilder, otherwise, returns false.

pub fn with_batch<T>( self, controller: T, dispatcher_builder: DispatcherBuilder<'a, 'b>, name: &str, dep: &[&str], ) -> DispatcherBuilder<'a, 'b>
where 'b: 'a, T: for<'c> BatchController<'a, 'b, 'c> + Send + 'a,

The Batch is a System which contains a Dispatcher. By wrapping a Dispatcher inside a system, we can control the execution of a whole group of system, without sacrificing parallelism or conciseness.

This function accepts the DispatcherBuilder as parameter, and the type of the System that will drive the execution of the internal dispatcher.

Note that depending on the dependencies of the SubSystems the Batch can run in parallel with other Systems. In addition the Sub Systems can run in parallel within the Batch.

The Dispatcher created for this Batch is completelly separate, from the parent Dispatcher. This mean that the dependencies, the System names, etc.. specified on the Batch Dispatcher are not visible on the parent, and is not allowed to specify cross dependencies.

pub fn add_batch<T>( &mut self, controller: T, dispatcher_builder: DispatcherBuilder<'a, 'b>, name: &str, dep: &[&str], )
where 'b: 'a, T: for<'c> BatchController<'a, 'b, 'c> + Send + 'a,

The Batch is a System which contains a Dispatcher. By wrapping a Dispatcher inside a system, we can control the execution of a whole group of system, without sacrificing parallelism or conciseness.

This function accepts the DispatcherBuilder as parameter, and the type of the System that will drive the execution of the internal dispatcher.

Note that depending on the dependencies of the SubSystems the Batch can run in parallel with other Systems. In addition the Sub Systems can run in parallel within the Batch.

The Dispatcher created for this Batch is completelly separate, from the parent Dispatcher. This mean that the dependencies, the System names, etc.. specified on the Batch Dispatcher are not visible on the parent, and is not allowed to specify cross dependencies.

pub fn with_thread_local<T>(self, system: T) -> DispatcherBuilder<'a, 'b>
where T: for<'c> RunNow<'c> + 'b,

Adds a new thread local system.

Please only use this if your struct is not Send and Sync.

Thread-local systems are dispatched in-order.

Same as DispatcherBuilder::add_thread_local, but returns self to enable method chaining.

pub fn add_thread_local<T>(&mut self, system: T)
where T: for<'c> RunNow<'c> + 'b,

Adds a new thread local system.

Please only use this if your struct is not Send and Sync.

Thread-local systems are dispatched in-order.

pub fn with_barrier(self) -> DispatcherBuilder<'a, 'b>

Inserts a barrier which assures that all systems added before the barrier are executed before the ones after this barrier.

Does nothing if there were no systems added since the last call to add_barrier()/with_barrier().

Thread-local systems are not affected by barriers; they’re always executed at the end.

Same as DispatcherBuilder::add_barrier, but returns self to enable method chaining.

pub fn add_barrier(&mut self)

Inserts a barrier which assures that all systems added before the barrier are executed before the ones after this barrier.

Does nothing if there were no systems added since the last call to add_barrier()/with_barrier().

Thread-local systems are not affected by barriers; they’re always executed at the end.

pub fn with_pool(self, pool: Arc<ThreadPool>) -> DispatcherBuilder<'a, 'b>

Attach a rayon thread pool to the builder and use that instead of creating one.

Same as add_pool(), but returns self to enable method chaining.

pub fn add_pool(&mut self, pool: Arc<ThreadPool>)

Attach a rayon thread pool to the builder and use that instead of creating one.

pub fn print_par_seq(&self)

Prints the equivalent system graph that can be easily used to get the graph using the seq! and par! macros. This is only recommended for advanced users.

pub fn build(self) -> Dispatcher<'a, 'b>

Builds the Dispatcher.

In the future, this method will precompute useful information in order to speed up dispatching.

§

impl<'b> DispatcherBuilder<'static, 'b>

pub fn build_async<R>(self, world: R) -> AsyncDispatcher<'b, R>

Builds an async dispatcher.

It does not allow non-static types and accepts a World struct or a value that can be borrowed as World.

Trait Implementations§

§

impl<'a, 'b> Debug for DispatcherBuilder<'a, 'b>

§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
§

impl<'a, 'b> Default for DispatcherBuilder<'a, 'b>

§

fn default() -> DispatcherBuilder<'a, 'b>

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<'a, 'b> Freeze for DispatcherBuilder<'a, 'b>

§

impl<'a, 'b> !RefUnwindSafe for DispatcherBuilder<'a, 'b>

§

impl<'a, 'b> !Send for DispatcherBuilder<'a, 'b>

§

impl<'a, 'b> !Sync for DispatcherBuilder<'a, 'b>

§

impl<'a, 'b> Unpin for DispatcherBuilder<'a, 'b>

§

impl<'a, 'b> !UnwindSafe for DispatcherBuilder<'a, 'b>

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.

§

impl<T> GetSetFdFlags for T

§

fn get_fd_flags(&self) -> Result<FdFlags, Error>
where T: AsFilelike,

Query the “status” flags for the self file descriptor.
§

fn new_set_fd_flags(&self, fd_flags: FdFlags) -> Result<SetFdFlags<T>, Error>
where T: AsFilelike,

Create a new SetFdFlags value for use with set_fd_flags. Read more
§

fn set_fd_flags(&mut self, set_fd_flags: SetFdFlags<T>) -> Result<(), Error>
where T: AsFilelike,

Set the “status” flags for the self file descriptor. Read more
§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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.

source§

impl<T> IntoEither for T

source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
§

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
§

impl<T> Pointee for T

§

type Pointer = u32

§

fn debug( pointer: <T as Pointee>::Pointer, f: &mut Formatter<'_>, ) -> Result<(), Error>

source§

impl<T> Same for T

§

type Output = T

Should always be Self
§

impl<Context> SubContext<Context> for Context

§

fn sub_context(self) -> Context

§

impl<T> TryDefault for T
where T: Default,

§

fn try_default() -> Result<T, String>

Tries to create the default.
§

fn unwrap_default() -> Self

Calls try_default and panics on an error case.
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.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

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
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

impl<A, B, T> HttpServerConnExec<A, B> for T
where B: Body,