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
use crateMessageBusDriver;
use Result;
/// Represents the response type of a command.
///
/// This trait should be implemented by all types used as commands within the
/// message bus system. Each command defines a corresponding `Response` type,
/// which will be returned when the command is successfully handled.
///
/// [`Command`] allows the system to reason about command handling in a
/// generic way without requiring dynamic dispatch or concrete knowledge of
/// the return type.
/// A handler responsible for executing commands.
///
/// Implementors of this trait define the logic for processing a specific
/// `Command` within the context of a `UnitOfWork`. The `handle` method is
/// provided a mutable reference to the `UnitOfWork`, allowing full access
/// to domain state and repositories for the duration of the command lifecycle.
///
/// This method must return a future that resolves to either a successful
/// result of type `C::Response` or a failure, which will cause the unit of
/// work to be rolled back.
///
/// Command handlers are only invoked during the command execution phase
/// of the message bus.