1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
pub use actionable_macros::{AsyncDispatcher, Dispatcher};
use async_trait::async_trait;

use crate::Permissions;

/// Dispatches `T` to an appropriate handler. This trait is derivable.
pub trait Dispatcher<T>: Send + Sync {
    /// The type of the result.
    type Result: Send + Sync;

    /// Dispatches `request` to the appropriate handler while also ensuring
    /// `permissions` allows the request.
    fn dispatch(&self, permissions: &Permissions, request: T) -> Self::Result;
}

/// Dispatches `T` to an appropriate handler. This trait is derivable.
#[async_trait]
pub trait AsyncDispatcher<T>: Send + Sync {
    /// The type of the result.
    type Result: Send + Sync;

    /// Dispatches `request` to the appropriate handler while also ensuring
    /// `permissions` allows the request.
    async fn dispatch(&self, permissions: &Permissions, request: T) -> Self::Result;
}