pub struct Identity(/* private fields */);Expand description
The extractor type to obtain your identity from a request.
use actix_web::*;
use actix_identity::Identity;
fn index(id: Identity) -> Result<String> {
// access request identity
if let Some(id) = id.identity() {
Ok(format!("Welcome! {}", id))
} else {
Ok("Welcome Anonymous!".to_owned())
}
}
fn login(id: Identity) -> HttpResponse {
id.remember("User1".to_owned()); // <- remember identity
HttpResponse::Ok().finish()
}
fn logout(id: Identity) -> HttpResponse {
id.forget(); // <- remove identity
HttpResponse::Ok().finish()
}Implementations§
Trait Implementations§
Source§impl FromRequest for Identity
Extractor implementation for Identity type.
impl FromRequest for Identity
Extractor implementation for Identity type.
use actix_identity::Identity;
fn index(id: Identity) -> String {
// access request identity
if let Some(id) = id.identity() {
format!("Welcome! {}", id)
} else {
"Welcome Anonymous!".to_owned()
}
}Source§fn from_request(
req: &HttpRequest,
_: &mut Payload,
) -> <Identity as FromRequest>::Future
fn from_request( req: &HttpRequest, _: &mut Payload, ) -> <Identity as FromRequest>::Future
Convert request to a Self
Auto Trait Implementations§
impl Freeze for Identity
impl !RefUnwindSafe for Identity
impl !Send for Identity
impl !Sync for Identity
impl Unpin for Identity
impl !UnwindSafe for Identity
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> 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