docs.rs failed to build fe_session-0.5.0
Please check the build logs for more information.
See Builds for ideas on how to fix a failed build, or Metadata for how to configure docs.rs builds.
If you believe this is docs.rs' fault, open an issue.
Please check the build logs for more information.
See Builds for ideas on how to fix a failed build, or Metadata for how to configure docs.rs builds.
If you believe this is docs.rs' fault, open an issue.
Overview
This crate provides a session object for applications developed in Iron. This session object is an object implemented by your application and is associated with a single HTTP client. All requests from this HTTP client will have access to this object. The session object is destroyed after a configurable amount of idle time. So if no requests from a client come in for 30 minutes the session is destroyed and the memory is reclaimed.
Examples
use std::fmt::Write;
use std::sync::{Arc, Mutex};
use iron::{Iron, Chain, Request, Response};
use iron::status::Status;
use fe_session::{FeSessionStorage, FeSession, FeConnection, FeSessionRequest, FeSessionState};
let mut chain = Chain::new(|req : &mut Request| {
let mut session = req.get_session::<usize>();
let mut result = String::new();
match session.state() {
FeSessionState::Expired => { // Old session expired, create a new one.
req.create_session(0 as usize);
write!(result, "{}", 0).unwrap();
},
FeSessionState::None => { // No session, create a new one.
req.create_session(0 as usize);
write!(result, "{}", 0).unwrap();
},
FeSessionState::Active => { // Active session, increment the count.
let mut count = session.get();
*count += 1;
write!(result, "{}", *count).unwrap();
}
}
Ok(Response::with((Status::Ok, result)))
});
chain.around(FeSessionStorage::<usize>::new());
let mut iron = Iron::new(chain).http(("localhost", 3000)).unwrap();
let mut conn1 = FeConnection::new("localhost", 3000);
let mut conn2 = FeConnection::new("localhost", 3000);
assert_eq!(conn1.get_string("/"), "0");
assert_eq!(conn2.get_string("/"), "0");
assert_eq!(conn1.get_string("/"), "1");
assert_eq!(conn1.get_string("/"), "2");
assert_eq!(conn2.get_string("/"), "1");
iron.close().unwrap();