Struct rouille::SessionsManager [] [src]

pub struct SessionsManager<T> where T: Clone {
    // some fields omitted
}

Manages all active user sessions in memory.

Example

#[derive(Debug, Clone)]
struct SessionData {
    user_id: i32
}

let sessions = rouille::SessionsManager::<SessionData>::new("SID", 3600);
 
rouille::start_server("localhost:80", move |request| {
    let session = sessions.start(&request);
    // rest of the handler
    session.apply(response)
})

Methods

impl<T> SessionsManager<T> where T: Clone

fn new<S>(cookie_name: S, timeout_s: u64) -> SessionsManager<T> where S: Into<String>

Initializes the sessions manager.

Parameters

  • cookie_name: The name of the cookie to use. Usually SID.
  • timeout_s: The duration of the session, in seconds. Usually 3600.

fn start(&self, request: &Request) -> Session<T>

Tries to load an existing session from the request, or creates one if there is no session yet.