Trait TokenValidator
pub trait TokenValidator:
Send
+ Sync
+ 'static {
// Required method
fn validate<C>(&self, token: &str) -> Result<C, TokenError>
where C: Claims;
}Expand description
Validates a raw JWT string and returns decoded claims.
KeyValidator implements this trait. Use it as a bound in middleware or
handlers so the concrete validator can be injected without coupling call-site
code to a specific type.
§Bounds
Send + Sync + 'static are required so that validators can be held in
long-lived contexts (e.g. Axum state) and passed across async task boundaries.
Clone is not required by the trait — KeyValidator implements it
independently (it wraps an Arc internally, so cloning is cheap and all
clones share the same key store).
Required Methods§
fn validate<C>(&self, token: &str) -> Result<C, TokenError>where
C: Claims,
fn validate<C>(&self, token: &str) -> Result<C, TokenError>where
C: Claims,
Validate a raw JWT string. Returns the decoded claims on success.
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.