Struct actix_identity::Identity[][src]

pub struct Identity(_);
Expand description

The extractor type to obtain your identity from a request.

use actix_web::*;
use actix_identity::Identity;

#[get("/")]
async fn index(id: Identity) -> impl Responder {
    // access request identity
    if let Some(id) = id.identity() {
        format!("Welcome! {}", id)
    } else {
        "Welcome Anonymous!".to_owned()
    }
}

#[post("/login")]
async fn login(id: Identity) -> impl Responder {
    // remember identity
    id.remember("User1".to_owned());

    HttpResponse::Ok()
}

#[post("/logout")]
async fn logout(id: Identity) -> impl Responder {
    // remove identity
    id.forget();

    HttpResponse::Ok()
}

Implementations

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

Remember identity.

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

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Extractor implementation for Identity type.

use actix_identity::Identity;

#[get("/")]
async fn index(id: Identity) -> impl Responder {
    // access request identity
    if let Some(id) = id.identity() {
        format!("Welcome! {}", id)
    } else {
        "Welcome Anonymous!".to_owned()
    }
}

Configuration for this extractor.

The associated error which can be returned.

Future that resolves to a Self.

Create a Self from request parts asynchronously.

Create a Self from request head asynchronously. Read more

Create and configure config instance.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more

Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Performs the conversion.

Should always be Self

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.