beetry_core/leaf/
builder.rs1use std::{marker::PhantomData, sync::Arc, time::Duration};
2
3use crate::{
4 Action, ActionBehavior, BoxNode, Condition, ConditionBehavior, RegisterTask, TaskHandle,
5};
6
7#[derive(Clone)]
8pub struct Builder<R, T> {
9 registry: Arc<R>,
10 abort_poll_interval: Duration,
11 _phantom: PhantomData<T>,
12}
13
14impl<R, T> Builder<R, T>
15where
16 R: RegisterTask<T> + 'static,
17 T: TaskHandle + 'static,
18{
19 pub fn new(registry: R, abort_poll_interval: Duration) -> Self {
20 Self {
21 registry: Arc::new(registry),
22 abort_poll_interval,
23 _phantom: PhantomData,
24 }
25 }
26
27 pub fn action<B>(&self, behavior: B) -> Action<R, T, B>
28 where
29 B: ActionBehavior + 'static,
30 {
31 Action::new(
32 behavior,
33 Arc::clone(&self.registry),
34 self.abort_poll_interval,
35 )
36 }
37
38 pub fn action_box(&self, behavior: impl ActionBehavior + 'static) -> BoxNode {
39 Box::new(Action::new(
40 behavior,
41 Arc::clone(&self.registry),
42 self.abort_poll_interval,
43 ))
44 }
45
46 pub fn condition_box(&self, behavior: impl ConditionBehavior + 'static) -> BoxNode {
47 Box::new(Condition::new(behavior))
48 }
49}