modo/rbac/traits.rs
1use std::future::Future;
2
3use crate::Result;
4
5/// Resolves the authenticated user's role from an incoming HTTP request.
6///
7/// Implement this trait on a concrete type and pass it to [`super::middleware()`].
8/// The method receives mutable access to request parts so it can call axum
9/// extractors such as `Session` internally.
10///
11/// This trait uses RPITIT and is **not** object-safe. Use it as a concrete type
12/// parameter, never as `dyn RoleExtractor`.
13pub trait RoleExtractor: Send + Sync + 'static {
14 /// Extracts the role string for the current request.
15 ///
16 /// Return an [`Error`](crate::Error) (e.g., `Error::unauthorized`) to short-circuit
17 /// the request. The middleware converts the error into an HTTP response immediately
18 /// without forwarding to the inner service.
19 fn extract(
20 &self,
21 parts: &mut http::request::Parts,
22 ) -> impl Future<Output = Result<String>> + Send;
23}