soaprs-core 0.2.0

Core contracts for soaprs
Documentation
//! Named application query contracts.

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

/// A named read operation with an output type fixed by the query itself.
///
/// Query values should own their input so they can cross asynchronous and
/// adapter boundaries without borrowing transport-specific data.
pub trait Query: Send {
    /// Successful output produced by this query.
    type Output: Send;
}

/// Handles one concrete query type.
///
/// The method is named `query` to keep `execute` reserved for [`crate::UseCase`].
/// A use case depends on `QueryHandler<MyQuery>` and remains unaware of whether
/// the handler uses portable repository parameters or a native adapter query.
pub trait QueryHandler<Q>: Send + Sync
where
    Q: Query,
{
    /// Resolves the named query.
    fn query(&self, query: Q) -> BoxFuture<'_, SoapResult<Q::Output>>;
}

impl<Q> Query for MessageEnvelope<Q>
where
    Q: Query,
{
    type Output = Q::Output;
}