# Enum actix_session::SessionLength

source · [−]

    pub enum SessionLength {
        BrowserSession {
            state_ttl: Option<Duration>,
        },
        Predetermined {
            max_session_length: Option<Duration>,
        },
    }

Expand description

Describes how long a session should last.

Used by `SessionMiddlewareBuilder::session_length`.

## Variants

### `BrowserSession`

#### Fields

`state_ttl: Option<Duration>`

We must provide a time-to-live (TTL) when storing the session state in the storage backend—we do not want to store session states indefinitely, otherwise we will inevitably run out of storage by holding on to the state of countless abandoned or expired sessions!

We are dealing with the lifecycle of two uncorrelated object here: the session cookie and the session state. It is not a big issue if the session state outlives the cookie— we are wasting some space in the backend storage, but it will be cleaned up eventually. What happens, instead, if the cookie outlives the session state? A new session starts— e.g. if sessions are being used for authentication, the user is de-facto logged out.

It is not possible to predict with certainty how long a browser session is going to last—you need to provide a reasonable upper bound. You do so via `state_ttl`—it dictates what TTL should be used for session state when the lifecycle of the session cookie is tied to the browser session length. `SessionMiddleware` will default to 1 day if `state_ttl` is left unspecified.

The session cookie will expire when the current browser session ends.

When does a browser session end? It depends on the browser! Chrome, for example, will often continue running in the background when the browser is closed—session cookies are not deleted and they will still be available when the browser is opened again. Check the documentation of the browsers you are targeting for up-to-date information.

### `Predetermined`

#### Fields

`max_session_length: Option<Duration>`

Set `max_session_length` to specify how long the session cookie should live. `SessionMiddleware` will default to 1 day if `max_session_length` is set to `None`.

`max_session_length` is also used as the TTL for the session state in the storage backend.

The session cookie will be a persistent cookie.

Persistent cookies have a pre-determined lifetime, specified via the `Max-Age` or `Expires` attribute. They do not disappear when the current browser session ends.

## Trait Implementations

source

### impl Clone for SessionLength

source

#### fn clone(&self) -> SessionLength

Returns a copy of the value. Read more

1.0.0 · source

#### fn clone_from(&mut self, source: &Self)

Performs copy-assignment from `source`. Read more

source

### impl Debug for SessionLength

source

#### fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

## Auto Trait Implementations

### impl RefUnwindSafe for SessionLength

### impl Send for SessionLength

### impl Sync for SessionLength

### impl Unpin for SessionLength

### impl UnwindSafe for SessionLength

## Blanket Implementations

source

### impl<T> Any for T where
T: 'static + ?Sized,

source

#### fn type_id(&self) -> TypeId

Gets the `TypeId` of `self`. Read more

source

### impl<T> Borrow<T> for T where
T: ?Sized,

const: unstable · source

#### fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more

source

### impl<T> BorrowMut<T> for T where
T: ?Sized,

const: unstable · source

#### fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more

source

### impl<T> From<T> for T

const: unstable · source

#### fn from(t: T) -> T

Returns the argument unchanged.

source

### impl<T> Instrument for T

source

#### fn instrument(self, span: Span) -> Instrumented<Self>

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

source

#### fn in_current_span(self) -> Instrumented<Self>

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

source

### impl<T, U> Into<U> for T where
U: From<T>,

const: unstable · source

#### fn into(self) -> U

Calls `U::from(self)`.

That is, this conversion is whatever the implementation of `From<T> for U` chooses to do.

source

### impl<T> Same<T> for T

#### type Output = T

Should always be `Self`

source

### impl<T> ToOwned for T where
T: Clone,

#### type Owned = T

The resulting type after obtaining ownership.

source

#### fn to_owned(&self) -> T

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

source

#### fn clone_into(&self, target: &mut T)

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

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

source

### impl<T, U> TryFrom<U> for T where
U: Into<T>,

#### type Error = Infallible

The type returned in the event of a conversion error.

const: unstable · source

#### fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.

source

### impl<T, U> TryInto<U> for T where
U: TryFrom<T>,

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

The type returned in the event of a conversion error.

const: unstable · source

#### fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.

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

#### fn vzip(self) -> V

source

### impl<T> WithSubscriber for T

source

#### fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,

Attaches the provided `Subscriber` to this type, returning a `WithDispatch` wrapper. Read more

source

#### fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default `Subscriber` to this type, returning a `WithDispatch` wrapper. Read more