soaprs_core/command.rs
1//! Named state-changing application operation contracts.
2
3use crate::MessageEnvelope;
4use crate::{BoxFuture, SoapResult};
5
6/// A named operation that may change application state.
7///
8/// Commands describe application intent and own their input. Infrastructure
9/// representations such as SQL statements or broker messages stay in adapters.
10pub trait Command: Send {
11 /// Successful output produced by the command.
12 type Output: Send;
13}
14
15/// Handles one concrete command type.
16///
17/// The method is named `command` to keep `execute` reserved for
18/// [`crate::UseCase`]. A command handler may itself contain application logic,
19/// delegate to a use case, or be implemented by a native adapter for a named
20/// infrastructure operation.
21pub trait CommandHandler<C>: Send + Sync
22where
23 C: Command,
24{
25 /// Handles the command.
26 fn command(&self, command: C) -> BoxFuture<'_, SoapResult<C::Output>>;
27}
28
29impl<C> Command for MessageEnvelope<C>
30where
31 C: Command,
32{
33 type Output = C::Output;
34}