Skip to main content

rustsim_spaces/
nothing.rs

1//! No-op space for non-spatial models.
2//!
3//! [`NothingSpace`] is the simplest space - agents have no position and all
4//! spatial operations are no-ops. Use this when your simulation has no
5//! spatial structure (e.g. well-mixed population models).
6//!
7//! Mirrors Julia Agents.jl `nothing` space.
8
9use rustsim_core::interaction::{PositionedAgent, SpaceInteraction};
10use rustsim_core::space::Space;
11
12/// A no-op space for non-spatial models.
13///
14/// Agents using `NothingSpace` must have `Position = ()`. All spatial methods
15/// (add, remove, nearby) are trivial no-ops that return empty results.
16#[derive(Debug, Default, Clone, Copy)]
17pub struct NothingSpace;
18
19impl Space for NothingSpace {}
20
21impl<A> SpaceInteraction<A> for NothingSpace
22where
23    A: PositionedAgent<Position = ()>,
24{
25    type Error = std::convert::Infallible;
26
27    fn random_position<R: rand::RngCore>(&self, _rng: &mut R) -> A::Position {}
28
29    fn add_agent(&mut self, _agent: &A) -> Result<(), Self::Error> {
30        Ok(())
31    }
32
33    fn remove_agent(&mut self, _agent: &A) -> Result<(), Self::Error> {
34        Ok(())
35    }
36
37    fn nearby_ids(
38        &self,
39        _position: &A::Position,
40        _radius: usize,
41    ) -> Vec<rustsim_core::types::AgentId> {
42        Vec::new()
43    }
44}