# Trait actix_web::middleware::identity::RequestIdentity[−][src]

    pub trait RequestIdentity {
        fn identity(&self) -> Option<String>;
        fn remember(&self, identity: String);
        fn forget(&self);
    }

The helper trait to obtain your identity from a request.

    use actix_web::middleware::identity::RequestIdentity;
    use actix_web::*;

    fn index(req: HttpRequest) -> Result<String> {
        // access request identity
        if let Some(id) = req.identity() {
            Ok(format!("Welcome! {}", id))
        } else {
            Ok("Welcome Anonymous!".to_owned())
        }
    }

    fn login(mut req: HttpRequest) -> HttpResponse {
        req.remember("User1".to_owned()); // <- remember identity
        HttpResponse::Ok().finish()
    }

    fn logout(mut req: HttpRequest) -> HttpResponse {
        req.forget(); // <- remove identity
        HttpResponse::Ok().finish()
    }

## Required Methods

### `fn identity(&self) -> Option<String>`

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

### `fn remember(&self, identity: String)`

Remember identity.

### `fn forget(&self)`

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

## Implementors

- `impl<S> RequestIdentity for HttpRequest<S>` | [src]

# Help

## Keyboard Shortcuts

`?`
  Show this help dialog
`S`
  Focus the search field
`↑`
  Move up in search results
`↓`
  Move down in search results
`↹`
  Switch tab
`⏎`
  Go to active search result
`+`
  Expand all sections
`-`
  Collapse all sections

## Search Tricks

Prefix searches with a type followed by a colon (e.g. `fn:`) to restrict the search to a given type.

Accepted types are: `fn`, `mod`, `struct`, `enum`, `trait`, `type`, `macro`, and `const`.

Search functions by type signature (e.g. `vec -> usize` or `* -> vec`)

Search multiple things at once by splitting your query with comma (e.g. `str,u8` or `String,struct:Vec,test`)