pub enum Session<U> {
Jwt(Jwt<U>),
Cookie(CookieSession<U>),
}Expand description
A session extracted from request extensions, wrapping the authenticated user.
Variants are gated behind their respective features (jwt, cookie, basic-auth).
Implements Deref<Target = U> for direct access to the inner user type.
Returns 401 Unauthorized when used as a handler extractor if no session is present.
Variants§
Jwt(Jwt<U>)
Cookie(CookieSession<U>)
Implementations§
Source§impl<U: Clone + Send + Sync + 'static> Session<U>
impl<U: Clone + Send + Sync + 'static> Session<U>
Sourcepub fn from_extensions(extensions: &mut Extensions) -> Option<Session<U>>
pub fn from_extensions(extensions: &mut Extensions) -> Option<Session<U>>
Extract a session from request extensions, trying each enabled auth method.
Sourcepub fn insert_into(self, extensions: &mut Extensions)
pub fn insert_into(self, extensions: &mut Extensions)
Re-insert this session into request extensions (restores the original variant).
Trait Implementations§
Source§impl<S: Sync, U: Clone + Send + Sync + 'static> FromRequestParts<S> for Session<U>
impl<S: Sync, U: Clone + Send + Sync + 'static> FromRequestParts<S> for Session<U>
Source§type Rejection = StatusCode
type Rejection = StatusCode
If the extractor fails it’ll use this “rejection” type. A rejection is
a kind of error that can be converted into a response.
Source§async fn from_request_parts(
parts: &mut Parts,
_: &S,
) -> Result<Self, StatusCode>
async fn from_request_parts( parts: &mut Parts, _: &S, ) -> Result<Self, StatusCode>
Perform the extraction.
Auto Trait Implementations§
impl<U> Freeze for Session<U>where
U: Freeze,
impl<U> RefUnwindSafe for Session<U>where
U: RefUnwindSafe,
impl<U> Send for Session<U>where
U: Send,
impl<U> Sync for Session<U>where
U: Sync,
impl<U> Unpin for Session<U>where
U: Unpin,
impl<U> UnsafeUnpin for Session<U>where
U: UnsafeUnpin,
impl<U> UnwindSafe for Session<U>where
U: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<R> CryptoRng for R
impl<T> Formattable for T
Source§impl<S, T> FromRequest<S, ViaParts> for T
impl<S, T> FromRequest<S, ViaParts> for T
Source§type Rejection = <T as FromRequestParts<S>>::Rejection
type Rejection = <T as FromRequestParts<S>>::Rejection
If the extractor fails it’ll use this “rejection” type. A rejection is
a kind of error that can be converted into a response.
Source§fn from_request(
req: Request<Body>,
state: &S,
) -> impl Future<Output = Result<T, <T as FromRequest<S, ViaParts>>::Rejection>>
fn from_request( req: Request<Body>, state: &S, ) -> impl Future<Output = Result<T, <T as FromRequest<S, ViaParts>>::Rejection>>
Perform the extraction.
impl<A, B, T> HttpServerConnExec<A, B> for Twhere
B: Body,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
impl<T> Parsable for T
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
impl<R> RngCore for Rwhere
R: Rng,
Source§impl<R> RngExt for R
impl<R> RngExt for R
Source§fn random<T>(&mut self) -> Twhere
StandardUniform: Distribution<T>,
fn random<T>(&mut self) -> Twhere
StandardUniform: Distribution<T>,
Return a random value via the
StandardUniform distribution. Read moreSource§fn random_iter<T>(self) -> Iter<StandardUniform, Self, T>
fn random_iter<T>(self) -> Iter<StandardUniform, Self, T>
Source§fn random_range<T, R>(&mut self, range: R) -> Twhere
T: SampleUniform,
R: SampleRange<T>,
fn random_range<T, R>(&mut self, range: R) -> Twhere
T: SampleUniform,
R: SampleRange<T>,
Generate a random value in the given range. Read more
Source§fn random_bool(&mut self, p: f64) -> bool
fn random_bool(&mut self, p: f64) -> bool
Return a bool with a probability
p of being true. Read moreSource§fn random_ratio(&mut self, numerator: u32, denominator: u32) -> bool
fn random_ratio(&mut self, numerator: u32, denominator: u32) -> bool
Return a bool with a probability of
numerator/denominator of being
true. Read moreSource§fn sample<T, D>(&mut self, distr: D) -> Twhere
D: Distribution<T>,
fn sample<T, D>(&mut self, distr: D) -> Twhere
D: Distribution<T>,
Sample a new value, using the given distribution. Read more
Source§fn sample_iter<T, D>(self, distr: D) -> Iter<D, Self, T>where
D: Distribution<T>,
Self: Sized,
fn sample_iter<T, D>(self, distr: D) -> Iter<D, Self, T>where
D: Distribution<T>,
Self: Sized,
Create an iterator that generates values using the given distribution. Read more