Struct actix_identity::Identity[][src]

pub struct Identity(_);

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

impl Identity[src]

pub fn identity(&self) -> Option<String>[src]

Return the claimed identity of the user associated request or None if no identity can be found associated with the request.

pub fn remember(&self, identity: String)[src]

Remember identity.

pub fn forget(&self)[src]

This method is used to ‘forget’ the current identity on subsequent requests.

Trait Implementations

impl Clone for Identity[src]

impl FromRequest for Identity[src]

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()
    }
}

type Config = ()

Configuration for this extractor.

type Error = Error

The associated error which can be returned.

type Future = Ready<Result<Identity, Error>>

Future that resolves to a Self.

Auto Trait Implementations

impl !RefUnwindSafe for Identity

impl !Send for Identity

impl !Sync for Identity

impl Unpin for Identity

impl !UnwindSafe for Identity

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T> Instrument for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> Same<T> for T

type Output = T

Should always be Self

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,