use crate::{Action, Execution, Signal, World, error::SensorError};
use async_trait::async_trait;
use serde::{Deserialize, Serialize};
use std::sync::Arc;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
#[serde(rename_all = "kebab-case")]
#[non_exhaustive]
pub enum Stage {
PreAction,
SelfCorrect,
PreCommit,
PostIntegrate,
Continuous,
}
pub type SensorId = String;
#[async_trait]
pub trait Sensor: Send + Sync + 'static {
fn id(&self) -> &SensorId;
fn kind(&self) -> Execution;
fn stage(&self) -> Stage;
async fn observe(&self, action: &Action, world: &World) -> Result<Vec<Signal>, SensorError>;
}
pub struct SensorEntry {
pub factory: fn() -> Arc<dyn Sensor>,
}
inventory::collect!(SensorEntry);
pub fn iter_macro_sensors() -> impl Iterator<Item = Arc<dyn Sensor>> {
inventory::iter::<SensorEntry>().map(|e| (e.factory)())
}