Skip to main content

hello_world/
hello_world.rs

1use agent_line::{Agent, Ctx, Outcome, StepResult};
2
3#[derive(Clone)]
4struct State {
5    n: i32,
6}
7
8struct AddOne;
9
10impl Agent<State> for AddOne {
11    fn name(&self) -> &'static str {
12        "add_one"
13    }
14
15    fn run(&mut self, state: State, _ctx: &mut Ctx) -> StepResult<State> {
16        let next = State { n: state.n + 1 };
17        Ok((next, Outcome::Done))
18    }
19}
20
21fn main() {
22    let mut ctx = Ctx::new();
23    let mut agent = AddOne;
24    let (state, out) = agent.run(State { n: 1 }, &mut ctx).unwrap();
25    println!("state.n={} outcome={out:?}", state.n);
26}