Trait NeighborSensing
pub trait NeighborSensing<Pos, Acc, Inf = ()>: InteractionInformation<Inf> {
// Required methods
fn accumulate_information(
&self,
own_pos: &Pos,
ext_pos: &Pos,
ext_inf: &Inf,
accumulator: &mut Acc,
) -> Result<(), CalcError>;
fn react_to_neighbors(&mut self, accumulator: &Acc) -> Result<(), CalcError>;
fn clear_accumulator(accumulator: &mut Acc);
}Available on crate feature
cara only.Expand description
Allows reacting to multiple neighbors
Information of neighbors is first accumulated via the NeighborSensing::accumulate_information function and finally, the cell reacts to the gathered data via the NeighborSensing::react_to_neighbors function. Finally, the accumulator is cleared with NeighborSensing::clear_accumulator.
§Neighbor Counting
use cellular_raza_concepts::*;
struct Cell {/* .. */};
impl<Pos, Inf> NeighborSensing<Pos, usize, Inf> for Cell
where
Cell: InteractionInformation<Inf>,
{
fn accumulate_information(
&self,
_: &Pos,
_: &Pos,
_: &Inf,
neighbors: &mut usize
) -> Result<(), CalcError> {
Ok(*neighbors += 1)
}
fn react_to_neighbors(&mut self, neighbors: &usize) -> Result<(), CalcError> {
/* .. */
Ok(())
}
fn clear_accumulator(neighbors: &mut usize) {
*neighbors = 0;
}
}
Required Methods§
fn accumulate_information(
&self,
own_pos: &Pos,
ext_pos: &Pos,
ext_inf: &Inf,
accumulator: &mut Acc,
) -> Result<(), CalcError>
fn accumulate_information( &self, own_pos: &Pos, ext_pos: &Pos, ext_inf: &Inf, accumulator: &mut Acc, ) -> Result<(), CalcError>
Checks if the other cell represented by position and information is a neighbor to the current one or not.
fn react_to_neighbors(&mut self, accumulator: &Acc) -> Result<(), CalcError>
fn react_to_neighbors(&mut self, accumulator: &Acc) -> Result<(), CalcError>
Reacts to the results gathered by the [Interaction::is_neighbor] method and changes the state of the cell.
fn clear_accumulator(accumulator: &mut Acc)
fn clear_accumulator(accumulator: &mut Acc)
Clears the accumulator
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.