Skip to main content

Subject

Trait Subject 

Source
pub trait Subject:
    Serialize
    + DeserializeOwned
    + Eq
    + Clone
    + Send
    + Sync
    + 'static { }
Expand description

Who a session belongs to: a user id, an account/tenant pair, an API client, anything.

The guard never interprets the subject. It serializes it to JSON for the store and deserializes it back when a session is authenticated. Blanket-implemented for every type with the right bounds, e.g. uuid::Uuid, i64, String or your own #[derive(Serialize, Deserialize, PartialEq, Eq, Clone)] struct.

The serialized form must be deterministic, because stores find a subject’s sessions by comparing it: equal values must produce equal JSON. Avoid HashMap fields inside subjects (use BTreeMap), and keep the representation stable across releases of your app.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

Source§

impl<T> Subject for T
where T: Serialize + DeserializeOwned + Eq + Clone + Send + Sync + 'static,