soaprs_core/query.rs
1//! Named application query contracts.
2
3use crate::{BoxFuture, MessageEnvelope, SoapResult};
4
5/// A named read operation with an output type fixed by the query itself.
6///
7/// Query values should own their input so they can cross asynchronous and
8/// adapter boundaries without borrowing transport-specific data.
9pub trait Query: Send {
10 /// Successful output produced by this query.
11 type Output: Send;
12}
13
14/// Handles one concrete query type.
15///
16/// The method is named `query` to keep `execute` reserved for [`crate::UseCase`].
17/// A use case depends on `QueryHandler<MyQuery>` and remains unaware of whether
18/// the handler uses portable repository parameters or a native adapter query.
19pub trait QueryHandler<Q>: Send + Sync
20where
21 Q: Query,
22{
23 /// Resolves the named query.
24 fn query(&self, query: Q) -> BoxFuture<'_, SoapResult<Q::Output>>;
25}
26
27impl<Q> Query for MessageEnvelope<Q>
28where
29 Q: Query,
30{
31 type Output = Q::Output;
32}