Rocket/examples/managed_queue/src/main.rs

32 lines
596 B
Rust
Raw Normal View History

#![feature(proc_macro_non_items, proc_macro_gen, decl_macro)]
2017-02-19 06:01:27 +00:00
#[macro_use] extern crate rocket;
extern crate crossbeam;
2017-02-19 06:01:27 +00:00
2017-04-14 21:53:41 +00:00
#[cfg(test)] mod tests;
2017-02-19 06:01:27 +00:00
use rocket::State;
use crossbeam::queue::MsQueue;
2017-02-19 06:01:27 +00:00
struct LogChannel(MsQueue<String>);
2017-02-19 06:01:27 +00:00
2017-04-14 21:53:41 +00:00
#[put("/push?<event>")]
fn push(event: String, queue: State<LogChannel>) {
2017-02-19 06:01:27 +00:00
queue.0.push(event);
}
#[get("/pop")]
fn pop(queue: State<LogChannel>) -> String {
queue.0.pop()
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();
}