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]
T: Default + Serialize + for<'de> Deserialize<'de> + 'static,
pub fn discard(self, state: &mut State) -> Result<(), SessionError>
[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]
T: Default + Serialize + for<'de> Deserialize<'de> + 'static,
impl<T> Deref for SessionData<T> where
T: Default + Serialize + for<'de> Deserialize<'de> + 'static,
[src]
T: Default + Serialize + for<'de> Deserialize<'de> + 'static,
type Target = T
The resulting type after dereferencing.
ⓘImportant traits for &'a mut Wfn deref(&self) -> &T
[src]
ⓘImportant traits for &'a mut W
Dereferences the value.
impl<T> DerefMut for SessionData<T> where
T: Default + Serialize + for<'de> Deserialize<'de> + 'static,
[src]
T: Default + Serialize + for<'de> Deserialize<'de> + 'static,