Parallelizer

Struct Parallelizer 

Source
pub struct Parallelizer<M = ()> { /* private fields */ }
Expand description

Parallelizer runs all its states at the same time.

Note that at any time you ask it to make a decision it goes through non-active states and tries to run them so instead of starting all possible states at once, it will ensure that at any time of decision making all possible states will run.

§Example

use emergent::prelude::*;

struct Memory {
    a: bool,
    b: bool,
}

let mut parallelizer = Parallelizer::new(vec![
    ParallelizerState::new(true, ClosureTask::default().enter(|m: &mut Memory| m.a = true)),
    ParallelizerState::new(true, ClosureTask::default().enter(|m: &mut Memory| m.b = true)),
]);

let mut memory = Memory { a: false, b: false };
assert!(parallelizer.process(&mut memory));
assert_eq!(memory.a, true);
assert_eq!(memory.b, true);

Implementations§

Source§

impl<M> Parallelizer<M>

Source

pub fn new(states: Vec<ParallelizerState<M>>) -> Self

Constructs new parallelizer with states.

Source

pub fn is_active(&self) -> bool

Tells if any of states is active/running.

Source

pub fn reset(&mut self, memory: &mut M, forced: bool) -> bool

Stops all active/running states.

By default states that are locked won’t stop, but we can force stop them.

Source

pub fn process(&mut self, memory: &mut M) -> bool

Perform decision making.

Source

pub fn update(&mut self, memory: &mut M)

Update active/running states.

Trait Implementations§

Source§

impl<M> Debug for Parallelizer<M>

Source§

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

Formats the value using the given formatter. Read more
Source§

impl<M, K> DecisionMaker<M, K> for Parallelizer<M>
where K: Default,

Source§

fn decide(&mut self, memory: &mut M) -> Option<K>

Performs decision making and returns the key of the state it switched into.
Source§

fn change_mind(&mut self, _: Option<K>, memory: &mut M) -> bool

Force switch into state (Some activates new state, None deactivates current state). Read more
Source§

impl<M> Task<M> for Parallelizer<M>

Source§

fn is_locked(&self, memory: &M) -> bool

Tells if task is locked (it’s still running). Used by decision makers to tell if one can change its state (when current task is not locked).
Source§

fn on_enter(&mut self, memory: &mut M)

Action performed when task starts its work.
Source§

fn on_exit(&mut self, memory: &mut M)

Action performed when task stops its work.
Source§

fn on_update(&mut self, memory: &mut M)

Action performed when task is active and gets updated.
Source§

fn on_process(&mut self, memory: &mut M) -> bool

Action performed when task is active but decision maker did not changed its state. This one is applicable for making hierarchical decision makers (telling children decision makers to decide on new state, because some if not all decision makers are tasks). Read more

Auto Trait Implementations§

§

impl<M> Freeze for Parallelizer<M>

§

impl<M = ()> !RefUnwindSafe for Parallelizer<M>

§

impl<M> Send for Parallelizer<M>

§

impl<M> Sync for Parallelizer<M>

§

impl<M> Unpin for Parallelizer<M>

§

impl<M = ()> !UnwindSafe for Parallelizer<M>

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.

Source§

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

Source§

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>,

Source§

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, M, K> DecisionMakingTask<M, K> for T
where T: DecisionMaker<M, K> + Task<M>,