1use crate::{Action, Execution, Signal, World, error::SensorError};
2use async_trait::async_trait;
3use serde::{Deserialize, Serialize};
4use std::sync::Arc;
5
6#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
8#[serde(rename_all = "kebab-case")]
9#[non_exhaustive]
10pub enum Stage {
11 PreAction,
13 SelfCorrect,
15 PreCommit,
17 PostIntegrate,
19 Continuous,
21}
22
23pub type SensorId = String;
24
25#[async_trait]
26pub trait Sensor: Send + Sync + 'static {
27 fn id(&self) -> &SensorId;
28 fn kind(&self) -> Execution;
29 fn stage(&self) -> Stage;
30 async fn observe(&self, action: &Action, world: &World) -> Result<Vec<Signal>, SensorError>;
31}
32
33pub struct SensorEntry {
34 pub factory: fn() -> Arc<dyn Sensor>,
35}
36
37inventory::collect!(SensorEntry);
38
39pub fn iter_macro_sensors() -> impl Iterator<Item = Arc<dyn Sensor>> {
40 inventory::iter::<SensorEntry>().map(|e| (e.factory)())
41}