ruva_core/bus_components/handler/command/
mod.rs

1//! ### Example - simple command handler
2//! ```rust,no_run
3//! impl<C,R> TCommandService<(), ()> for CommandHandler<(C, R)>
4//! where
5//!     C: crate::prelude::TCommand + for<'a> TGetHandler<&'a mut R, Result<(), ()>>,
6//!     R: Send + Sync,
7//! {
8//!     async fn execute(mut self) -> Result<(), ()> {
9//!         let CommandHandler((cmd, mut dep)) = self;
10//!         let handler = C::get_handler();
11//!         handler(cmd, &mut dep).await
12//!     }
13//! }
14//! ```
15
16pub mod uow;
17use crate::{
18	message::TCommand,
19	prelude::{ApplicationError, ApplicationResponse, BaseError, TCommandService, TSetCurrentEvents, TUnitOfWork},
20};
21pub use uow::*;
22
23pub struct CommandHandler<T>(pub T);
24
25impl<T> CommandHandler<T> {
26	pub fn destruct(self) -> T {
27		self.0
28	}
29}
30
31pub trait AsyncFunc<C, R, ApplicationResult>: Fn(C, R) -> Self::Fut + Send + Sync {
32	type Fut: std::future::Future<Output = ApplicationResult> + Send;
33}
34
35impl<F, C, Fut, Respository, ApplicationResult> AsyncFunc<C, Respository, ApplicationResult> for F
36where
37	C: crate::prelude::TCommand,
38	F: Fn(C, Respository) -> Fut + Send + Sync,
39	Fut: std::future::Future<Output = ApplicationResult> + Send,
40{
41	type Fut = Fut;
42}
43
44pub trait TGetHandler<R, ApplicationResult>: Sized {
45	fn get_handler() -> impl AsyncFunc<Self, R, ApplicationResult>;
46}