Add minimal example, some formatting, bump parking_lot version
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
#[macro_use]
|
||||
extern crate rocket;
|
||||
|
||||
use std::time::Duration;
|
||||
|
||||
type Session<'a> = rocket_session::Session<'a, u64>;
|
||||
|
||||
#[launch]
|
||||
fn rocket() -> _ {
|
||||
// This session expires in 15 seconds as a demonstration of session configuration
|
||||
rocket::build()
|
||||
.attach(Session::fairing().with_lifetime(Duration::from_secs(15)))
|
||||
.mount("/", routes![index])
|
||||
}
|
||||
|
||||
#[get("/")]
|
||||
fn index(session: Session) -> String {
|
||||
let count = session.tap(|n| {
|
||||
// Change the stored value (it is &mut)
|
||||
*n += 1;
|
||||
|
||||
// Return something to the caller.
|
||||
// This can be any type, 'tap' is generic.
|
||||
*n
|
||||
});
|
||||
|
||||
format!("{} visits", count)
|
||||
}
|
||||
Reference in New Issue
Block a user