2017-08-29 03:14:59 +00:00
|
|
|
#![feature(plugin, decl_macro, custom_derive)]
|
2017-02-19 06:01:27 +00:00
|
|
|
#![plugin(rocket_codegen)]
|
|
|
|
|
|
|
|
extern crate crossbeam;
|
|
|
|
extern crate rocket;
|
|
|
|
|
2017-04-14 21:53:41 +00:00
|
|
|
#[cfg(test)] mod tests;
|
|
|
|
|
2017-02-19 06:01:27 +00:00
|
|
|
use crossbeam::sync::MsQueue;
|
|
|
|
use rocket::State;
|
|
|
|
|
|
|
|
#[derive(FromForm, Debug)]
|
|
|
|
struct Event {
|
|
|
|
description: String
|
|
|
|
}
|
|
|
|
|
|
|
|
struct LogChannel(MsQueue<Event>);
|
|
|
|
|
2017-04-14 21:53:41 +00:00
|
|
|
#[put("/push?<event>")]
|
|
|
|
fn push(event: Event, queue: State<LogChannel>) {
|
2017-02-19 06:01:27 +00:00
|
|
|
queue.0.push(event);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[get("/pop")]
|
|
|
|
fn pop(queue: State<LogChannel>) -> String {
|
2017-04-14 21:53:41 +00:00
|
|
|
let queue = &queue.0;
|
|
|
|
queue.pop().description
|
2017-02-19 06:01:27 +00:00
|
|
|
}
|
|
|
|
|
2017-04-14 21:53:41 +00:00
|
|
|
fn rocket() -> rocket::Rocket {
|
2017-02-19 06:01:27 +00:00
|
|
|
rocket::ignite()
|
2017-04-14 21:53:41 +00:00
|
|
|
.mount("/", routes![push, pop])
|
|
|
|
.manage(LogChannel(MsQueue::new()))
|
2017-02-19 06:01:27 +00:00
|
|
|
}
|
|
|
|
|
2017-04-14 21:53:41 +00:00
|
|
|
fn main() {
|
|
|
|
rocket().launch();
|
|
|
|
}
|