Skip to main content

card_stack/
actions.rs

1use state_validation::StateFilter;
2
3use crate::{
4    priority::{Priority, PriorityMut, PriorityStack},
5    requirements::ActionRequirement,
6};
7
8pub trait ActionSource: Sized {
9    /// Where this action originates from.
10    type Source: Send + Sync;
11    /// Where this action originates from.
12    fn source(&self) -> &Self::Source;
13}
14/// An action that must be put on an empty stack.
15///
16/// **NOTE:** if it implements `StackAction` in addition to this trait,
17/// it can be put both on an empty stack and stacked stack.
18pub trait IncitingAction<State, Input>: IncitingActionInfo<State> {
19    /// Requirement must be satisfied before this action can be resolved.
20    type Requirement: ActionRequirement<Priority<State>, Input>;
21
22    fn resolve(
23        self,
24        priority: PriorityMut<Priority<State>>,
25        input: <<Self::Requirement as ActionRequirement<
26            Priority<State>,
27            Input,
28        >>::Filter as StateFilter<Priority<State>, Input>>::ValidOutput,
29    ) -> Self::Resolved;
30}
31pub trait IncitingActionInfo<State> {
32    /// The resolution of this inciting action.
33    type Resolved;
34    /// Can be stacked upon this inciting action.
35    type Stackable;
36}
37
38/// An action that must be put on a stacked stack,
39///
40/// **NOTE:** if it implements `IncitingAction` in addition to this trait,
41/// it can be put both on an empty stack and stacked stack.
42pub trait StackAction<State, Input, IncitingAction: crate::actions::IncitingActionInfo<State>> {
43    /// Requirement must be satisfied before this action can be resolved.
44    type Requirement: ActionRequirement<PriorityStack<State, IncitingAction>, Input>;
45
46    /// The resolution of this action.
47    type Resolved;
48    fn resolve(
49        self,
50        priority: PriorityMut<PriorityStack<State, IncitingAction>>,
51        input: <<Self::Requirement as ActionRequirement<
52            PriorityStack<State, IncitingAction>,
53            Input,
54        >>::Filter as StateFilter<PriorityStack<State, IncitingAction>, Input>>::ValidOutput,
55    ) -> Self::Resolved;
56}