Rocket/examples/managed_queue/src/main.rs

31 lines
578 B
Rust
Raw Normal View History

2018-10-06 04:56:46 +00:00
#![feature(proc_macro_hygiene, decl_macro)]
2017-02-19 06:01:27 +00:00
#[macro_use] extern crate rocket;
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::SegQueue;
2017-02-19 06:01:27 +00:00
struct LogChannel(SegQueue<String>);
2017-02-19 06:01:27 +00:00
2017-04-14 21:53:41 +00:00
#[put("/push?<event>")]
2019-06-13 02:41:29 +00:00
fn push(event: String, queue: State<'_, LogChannel>) {
2017-02-19 06:01:27 +00:00
queue.0.push(event);
}
#[get("/pop")]
2019-06-13 02:41:29 +00:00
fn pop(queue: State<'_, LogChannel>) -> Option<String> {
queue.0.pop().ok()
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(SegQueue::new()))
2017-02-19 06:01:27 +00:00
}
2017-04-14 21:53:41 +00:00
fn main() {
rocket().launch();
}