blob: 79ebee017cfc7528517569c239452a0c4a25805b (
plain) (
blame)
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
use crate::ChainProcess;
/// The entry logic of the Mingling program
///
/// Dispatcher is the first stop for args after they enter the program:
/// it is used to wrap the user's raw args into an initial [`ChainProcess`] and feed them into the program loop
///
/// # Manual impl
///
/// ```
/// # use mingling_core::ChainProcess;
/// # use mingling_core::Dispatcher;
/// # use mingling_core::Grouped;
/// # use mingling_core::Routable;
/// # use mingling_core::MockProgramCollect as ThisProgram;
/// # unsafe impl Grouped<ThisProgram> for Foo {
/// # fn member_id() -> ThisProgram { ThisProgram::Foo }
/// # }
/// struct CMDGreet;
/// struct Foo {
/// args: Vec<String>
/// }
///
/// impl Dispatcher<ThisProgram> for CMDGreet {
/// fn begin(&self, args: Vec<String>) -> ChainProcess<ThisProgram> {
/// Routable::to_chain(Foo { args })
/// }
/// }
/// ```
pub trait Dispatcher<C> {
/// Begin logic, receives the remaining arguments after the command prefix
/// has been stripped
///
/// Example:
///
/// ```
/// # use mingling_core::ChainProcess;
/// # use mingling_core::Dispatcher;
/// # use mingling_core::Grouped;
/// # use mingling_core::Routable;
/// # use mingling_core::MockProgramCollect as ThisProgram;
/// # unsafe impl Grouped<ThisProgram> for Foo {
/// # fn member_id() -> ThisProgram { ThisProgram::Foo }
/// # }
/// # struct CMDGreet;
/// # struct Foo {
/// # args: Vec<String>
/// # }
/// # impl Dispatcher<ThisProgram> for CMDGreet {
/// fn begin(&self, args: Vec<String>) -> ChainProcess<ThisProgram> {
/// // Create Foo from args and route it to the next chain
/// Routable::to_chain(Foo { args })
/// }
/// # }
/// ```
fn begin(&self, args: Vec<String>) -> ChainProcess<C>;
}
|