Struct gotham::middleware::session::SessionData [] [src]

pub struct SessionData<T> where
    T: Default + Serialize + for<'de> Deserialize<'de> + 'static, 
{ /* fields omitted */ }

The wrapping type for application session data.

The application will receive a SessionData<T> via the State container, where T is the session type given to NewSessionMiddleware.

Examples

#[derive(Default, Serialize, Deserialize)]
struct MySessionType {
    items: Vec<String>,
}

fn my_handler(state: State) -> (State, Response) {
    // The `Router` has a `NewSessionMiddleware<_, MySessionType>` in a pipeline which is
    // active for this handler.
    let body = {
        let session = SessionData::<MySessionType>::borrow_from(&state);
        format!("{:?}", session.items).into_bytes()
    };

    let response = create_response(&state,
                                   StatusCode::Ok,
                                   Some((body, mime::TEXT_PLAIN)));

    (state, response)
}

Methods

impl<T> SessionData<T> where
    T: Default + Serialize + for<'de> Deserialize<'de> + 'static, 
[src]

[src]

Discards the session, invalidating it for future use and removing the data from the Backend.

Trait Implementations

impl<T> StateData for SessionData<T> where
    T: Default + Serialize + for<'de> Deserialize<'de> + 'static, 
[src]

impl<T> Deref for SessionData<T> where
    T: Default + Serialize + for<'de> Deserialize<'de> + 'static, 
[src]

The resulting type after dereferencing.

Important traits for &'a mut W
[src]

Dereferences the value.

impl<T> DerefMut for SessionData<T> where
    T: Default + Serialize + for<'de> Deserialize<'de> + 'static, 
[src]

Important traits for &'a mut W
[src]

Mutably dereferences the value.

Auto Trait Implementations

impl<T> !Send for SessionData<T>

impl<T> !Sync for SessionData<T>