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§
Sourcefn duration(
&self,
_tick: u64,
_state_diff: StateDiffRef<'_, D>,
_agent: AgentId,
) -> TaskDuration
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.
Sourcefn execute(
&self,
tick: u64,
state_diff: StateDiffRefMut<'_, D>,
agent: AgentId,
) -> Option<Box<dyn Task<D>>>
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.
Sourcefn is_valid(
&self,
tick: u64,
state_diff: StateDiffRef<'_, D>,
agent: AgentId,
) -> bool
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.
Sourcefn display_action(&self) -> D::DisplayAction
fn display_action(&self) -> D::DisplayAction
Returns the display actions corresponding to this task.
Sourcefn box_clone(&self) -> Box<dyn Task<D>>
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.
Sourcefn box_hash(&self, state: &mut dyn Hasher)
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.
Provided Methods§
Implementations§
Source§impl<D> dyn Task<D>
impl<D> dyn Task<D>
Sourcepub fn is<__T: Task<D>>(&self) -> bool
pub fn is<__T: Task<D>>(&self) -> bool
Returns true if the trait object wraps an object of type __T
.
Sourcepub fn downcast<__T: Task<D>>(self: Box<Self>) -> Result<Box<__T>, Box<Self>>
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.
Sourcepub fn downcast_rc<__T: Task<D>>(self: Rc<Self>) -> Result<Rc<__T>, Rc<Self>>
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.
Sourcepub fn downcast_ref<__T: Task<D>>(&self) -> Option<&__T>
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.
Sourcepub fn downcast_mut<__T: Task<D>>(&mut self) -> Option<&mut __T>
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.