soaprs-core 0.2.0

Core contracts for soaprs
Documentation
//! Named state-changing application operation contracts.

use crate::MessageEnvelope;
use crate::{BoxFuture, SoapResult};

/// A named operation that may change application state.
///
/// Commands describe application intent and own their input. Infrastructure
/// representations such as SQL statements or broker messages stay in adapters.
pub trait Command: Send {
    /// Successful output produced by the command.
    type Output: Send;
}

/// Handles one concrete command type.
///
/// The method is named `command` to keep `execute` reserved for
/// [`crate::UseCase`]. A command handler may itself contain application logic,
/// delegate to a use case, or be implemented by a native adapter for a named
/// infrastructure operation.
pub trait CommandHandler<C>: Send + Sync
where
    C: Command,
{
    /// Handles the command.
    fn command(&self, command: C) -> BoxFuture<'_, SoapResult<C::Output>>;
}

impl<C> Command for MessageEnvelope<C>
where
    C: Command,
{
    type Output = C::Output;
}