hexeract_core/command.rs
1/// A message expressing the intent to mutate state.
2///
3/// Each command has exactly one [`CommandHandler`](crate::handler::CommandHandler)
4/// registered with the [`Mediator`](https://docs.rs/hexeract). The handler
5/// returns the associated [`Command::Output`] type.
6///
7/// Implementors should be cheap to clone or move, since the framework owns
8/// the command after dispatch.
9///
10/// # Example
11///
12/// ```
13/// use hexeract_core::Command;
14/// use uuid::Uuid;
15///
16/// struct RegisterUser {
17/// pub email: String,
18/// }
19///
20/// impl Command for RegisterUser {
21/// type Output = Uuid;
22/// }
23/// ```
24pub trait Command: Send + Sync + 'static {
25 /// The result type returned by the handler upon successful execution.
26 type Output: Send + Sync + 'static;
27}
28
29#[cfg(test)]
30mod tests {
31 use super::*;
32
33 struct DummyCommand;
34 impl Command for DummyCommand {
35 type Output = u64;
36 }
37
38 fn assert_command<C: Command>() {}
39
40 #[test]
41 fn dummy_command_implements_trait() {
42 assert_command::<DummyCommand>();
43 }
44}