crb_superagent/mission/
mod.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
pub mod async_fn;
pub mod reporting;
pub mod runtime;
pub mod sync_fn;

pub use runtime::RunMission;

use anyhow::Result;
use async_trait::async_trait;
use crb_agent::{Agent, Context};

pub trait Goal: Send + 'static {}

impl<T> Goal for T where Self: Send + 'static {}

#[async_trait]
pub trait Mission: Agent {
    type Goal: Goal;

    async fn deliver(self, ctx: &mut Context<Self>) -> Option<Self::Goal>;
}

pub trait Observer<M: Mission>: Send {
    fn check(&mut self, goal: &M::Goal) -> Result<()>;
}

pub trait Runnable: Mission {
    fn run(self) -> RunMission<Self>;
}

impl<M: Mission> Runnable for M
where
    Self::Context: Default,
{
    fn run(self) -> RunMission<Self> {
        RunMission::new(self)
    }
}