forked from packages/rocket_session
Compare commits
7 Commits
Author | SHA1 | Date |
---|---|---|
Ondřej Hruška | 82f9519f95 | 2 years ago |
Ondřej Hruška | f30b1f5be1 | 2 years ago |
Ondřej Hruška | b0a2d8c910 | 2 years ago |
Jeff Weiss | bc2180d1e4 | 2 years ago |
Ondřej Hruška | c5a9767881 | 4 years ago |
Ondřej Hruška | 89bebc6b03 | 5 years ago |
Ondřej Hruška | 4046e7f185 | 5 years ago |
@ -0,0 +1,13 @@ |
||||
# [0.3.0] |
||||
|
||||
- Update dependencies |
||||
- Added new example |
||||
- Port to rocket `0.5.0-rc.2` |
||||
|
||||
# [0.2.2] |
||||
|
||||
- Update dependencies |
||||
|
||||
# [0.2.1] |
||||
|
||||
- change from `thread_rng` to `OsRng` for better session ID entropy |
@ -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) |
||||
} |
Loading…
Reference in new issue