Trait Task

Source
pub trait Task<D: Domain>:
    Debug
    + Downcast
    + Send
    + Sync {
    // Required methods
    fn duration(
        &self,
        _tick: u64,
        _state_diff: StateDiffRef<'_, D>,
        _agent: AgentId,
    ) -> TaskDuration;
    fn execute(
        &self,
        tick: u64,
        state_diff: StateDiffRefMut<'_, D>,
        agent: AgentId,
    ) -> Option<Box<dyn Task<D>>>;
    fn is_valid(
        &self,
        tick: u64,
        state_diff: StateDiffRef<'_, D>,
        agent: AgentId,
    ) -> bool;
    fn display_action(&self) -> D::DisplayAction;
    fn box_clone(&self) -> Box<dyn Task<D>>;
    fn box_hash(&self, state: &mut dyn Hasher);
    fn box_eq(&self, other: &Box<dyn Task<D>>) -> bool;

    // Provided method
    fn weight(
        &self,
        _tick: u64,
        _state_diff: StateDiffRef<'_, D>,
        _agent: AgentId,
    ) -> f32 { ... }
}
Expand description

A task that modifies the state.

It is illegal to have a task of both 0-duration and not modifying the state, as this would lead to self-looping nodes in the planner.

Required Methods§

Source

fn duration( &self, _tick: u64, _state_diff: StateDiffRef<'_, D>, _agent: AgentId, ) -> TaskDuration

Returns the duration of the task, for a given agent in a given tick and world state.

Source

fn execute( &self, tick: u64, state_diff: StateDiffRefMut<'_, D>, agent: AgentId, ) -> Option<Box<dyn Task<D>>>

Executes one step of the task for the given agent on the given tick and world state.

Source

fn is_valid( &self, tick: u64, state_diff: StateDiffRef<'_, D>, agent: AgentId, ) -> bool

Returns if the task is valid for the given agent in the given tick and world state.

Source

fn display_action(&self) -> D::DisplayAction

Returns the display actions corresponding to this task.

Source

fn box_clone(&self) -> Box<dyn Task<D>>

Utility method for cloning, since Self: Clone is not object-safe.

Use the macro impl_task_boxed_methods to automatically generate this method.

Source

fn box_hash(&self, state: &mut dyn Hasher)

Utility method for hashing, since Self: Hash is not object-safe.

Use the macro impl_task_boxed_methods to automatically generate this method.

Source

fn box_eq(&self, other: &Box<dyn Task<D>>) -> bool

Utility method for equality, since trait objects are not inherently Eq.

Should perform downcast to current type and then check equality.

Use the macro impl_task_boxed_methods to automatically generate this method.

Provided Methods§

Source

fn weight( &self, _tick: u64, _state_diff: StateDiffRef<'_, D>, _agent: AgentId, ) -> f32

Returns the relative weight of the task for the given agent in the given tick and world state, by default weight is 1.0.

Implementations§

Source§

impl<D> dyn Task<D>
where D: Any + 'static + Domain,

Source

pub fn is<__T: Task<D>>(&self) -> bool

Returns true if the trait object wraps an object of type __T.

Source

pub fn downcast<__T: Task<D>>(self: Box<Self>) -> Result<Box<__T>, Box<Self>>

Returns a boxed object from a boxed trait object if the underlying object is of type __T. Returns the original boxed trait if it isn’t.

Source

pub fn downcast_rc<__T: Task<D>>(self: Rc<Self>) -> Result<Rc<__T>, Rc<Self>>

Returns an Rc-ed object from an Rc-ed trait object if the underlying object is of type __T. Returns the original Rc-ed trait if it isn’t.

Source

pub fn downcast_ref<__T: Task<D>>(&self) -> Option<&__T>

Returns a reference to the object within the trait object if it is of type __T, or None if it isn’t.

Source

pub fn downcast_mut<__T: Task<D>>(&mut self) -> Option<&mut __T>

Returns a mutable reference to the object within the trait object if it is of type __T, or None if it isn’t.

Trait Implementations§

Source§

impl<D: Domain> Clone for Box<dyn Task<D>>

Source§

fn clone(&self) -> Self

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<D: Domain> Hash for Box<dyn Task<D>>

Source§

fn hash<H>(&self, state: &mut H)
where H: Hasher,

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl<D: Domain> PartialEq for Box<dyn Task<D>>

Source§

fn eq(&self, other: &Self) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<D: Domain> Eq for Box<dyn Task<D>>

Implementors§