Skip to main content

RoleExtractor

Trait RoleExtractor 

Source
pub trait RoleExtractor:
    Send
    + Sync
    + 'static {
    // Required method
    fn extract(
        &self,
        parts: &mut Parts,
    ) -> impl Future<Output = Result<String>> + Send;
}
Expand description

Resolves the caller’s role for the current HTTP request.

Implement this trait on a concrete type (for example a struct that wraps a Database handle or session helper) and pass an instance to super::middleware(). The parts argument is mutable so implementations can call axum extractors such as Session::from_request_parts or Bearer internally.

This trait uses return-position impl Trait in traits (RPITIT) and is not object-safe. Always use it as a generic parameter bound, never as dyn RoleExtractor or behind Box<dyn ...>.

Required Methods§

Source

fn extract( &self, parts: &mut Parts, ) -> impl Future<Output = Result<String>> + Send

Extracts the role string for the current request.

Return an Error (for example Error::unauthorized or Error::forbidden) to short-circuit the request. The middleware converts the error into an HTTP response immediately and does not call the inner service.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§