pub struct AuthUser<U: BaseUser>(pub U);Expand description
Authenticated user extractor that loads the full user model from database.
Wraps the user model U as a tuple struct for destructuring, consistent
with Path<T>, Json<T>, and other Reinhardt extractors.
Requires feature = "params" to access request data from InjectionContext.
§Usage
ⓘ
use reinhardt_auth::AuthUser;
use reinhardt_auth::DefaultUser;
#[get("/profile/")]
pub async fn profile(
#[inject] AuthUser(user): AuthUser<DefaultUser>,
) -> ViewResult<Response> {
let username = user.get_username();
// ...
}§Failure
Returns an injection error when:
- No
AuthStatein request extensions (HTTP 401) user_idparse failure (HTTP 401, not nil UUID fallback)DatabaseConnectionnot registered in DI (HTTP 503)- Database query failure (HTTP 500)
Tuple Fields§
§0: UTrait Implementations§
Source§impl<U> Injectable for AuthUser<U>
impl<U> Injectable for AuthUser<U>
Auto Trait Implementations§
impl<U> Freeze for AuthUser<U>where
U: Freeze,
impl<U> RefUnwindSafe for AuthUser<U>where
U: RefUnwindSafe,
impl<U> Send for AuthUser<U>
impl<U> Sync for AuthUser<U>
impl<U> Unpin for AuthUser<U>where
U: Unpin,
impl<U> UnsafeUnpin for AuthUser<U>where
U: UnsafeUnpin,
impl<U> UnwindSafe for AuthUser<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,
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>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more