2017-01-21 03:31:46 +00:00
|
|
|
#![feature(plugin)]
|
|
|
|
#![plugin(rocket_codegen)]
|
|
|
|
|
|
|
|
extern crate rocket;
|
|
|
|
|
|
|
|
#[cfg(test)] mod tests;
|
|
|
|
|
|
|
|
use std::sync::atomic::{AtomicUsize, Ordering};
|
|
|
|
|
|
|
|
use rocket::State;
|
|
|
|
use rocket::response::content;
|
|
|
|
|
|
|
|
struct HitCount(AtomicUsize);
|
|
|
|
|
|
|
|
#[get("/")]
|
2017-07-12 22:21:45 +00:00
|
|
|
fn index(hit_count: State<HitCount>) -> content::Html<String> {
|
2017-01-21 03:31:46 +00:00
|
|
|
hit_count.0.fetch_add(1, Ordering::Relaxed);
|
|
|
|
let msg = "Your visit has been recorded!";
|
|
|
|
let count = format!("Visits: {}", count(hit_count));
|
2017-07-12 22:21:45 +00:00
|
|
|
content::Html(format!("{}<br /><br />{}", msg, count))
|
2017-01-21 03:31:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[get("/count")]
|
|
|
|
fn count(hit_count: State<HitCount>) -> String {
|
|
|
|
hit_count.0.load(Ordering::Relaxed).to_string()
|
|
|
|
}
|
|
|
|
|
|
|
|
fn rocket() -> rocket::Rocket {
|
|
|
|
rocket::ignite()
|
|
|
|
.mount("/", routes![index, count])
|
|
|
|
.manage(HitCount(AtomicUsize::new(0)))
|
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
rocket().launch();
|
|
|
|
}
|