Rocket/examples/managed_queue/src/main.rs

26 lines
513 B
Rust
Raw Normal View History

#[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
}
#[rocket::launch]
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
}