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
use crate::Router;

/// An action context, describing any additional context that the action may carry.
/// This is used to distribute system setup information when invoking them as actions,
/// for example, when systems have defined action routes.
#[derive(Clone, Debug, Default)]
pub enum ActionContext<State> {
    /// The action is being invoked as a single unit.
    #[default]
    Unit,
    /// The action is a collection of actions.
    System(SystemContext<State>),
}

impl<State> From<SystemContext<State>> for ActionContext<State> {
    fn from(context: SystemContext<State>) -> Self {
        Self::System(context)
    }
}

/// A router for actions that can be invoked as services.
#[derive(Clone, Debug, Default)]
pub struct SystemContext<State> {
    /// Any routes that have been mounted on a routed system.
    pub router: Router<State>,
}

impl<State> From<Router<State>> for SystemContext<State> {
    fn from(router: Router<State>) -> Self {
        Self { router }
    }
}