pub use self::module::PlumeRocket; #[cfg(not(test))] mod module { use crate::{search, users}; use rocket::{ request::{self, FlashMessage, FromRequest, Request}, Outcome, State, }; use scheduled_thread_pool::ScheduledThreadPool; use std::sync::Arc; /// Common context needed by most routes and operations on models pub struct PlumeRocket { pub intl: rocket_i18n::I18n, pub user: Option, pub searcher: Arc, pub worker: Arc, pub flash_msg: Option<(String, String)>, } impl<'a, 'r> FromRequest<'a, 'r> for PlumeRocket { type Error = (); fn from_request(request: &'a Request<'r>) -> request::Outcome { let intl = request.guard::()?; let user = request.guard::().succeeded(); let worker = request.guard::<'_, State<'_, Arc>>()?; let searcher = request.guard::<'_, State<'_, Arc>>()?; let flash_msg = request.guard::>().succeeded(); Outcome::Success(PlumeRocket { intl, user, flash_msg: flash_msg.map(|f| (f.name().into(), f.msg().into())), worker: worker.clone(), searcher: searcher.clone(), }) } } } #[cfg(test)] mod module { use crate::{search, users}; use rocket::{ request::{self, FromRequest, Request}, Outcome, State, }; use scheduled_thread_pool::ScheduledThreadPool; use std::sync::Arc; /// Common context needed by most routes and operations on models pub struct PlumeRocket { pub user: Option, pub searcher: Arc, pub worker: Arc, } impl<'a, 'r> FromRequest<'a, 'r> for PlumeRocket { type Error = (); fn from_request(request: &'a Request<'r>) -> request::Outcome { let user = request.guard::().succeeded(); let worker = request.guard::<'_, State<'_, Arc>>()?; let searcher = request.guard::<'_, State<'_, Arc>>()?; Outcome::Success(PlumeRocket { user, worker: worker.clone(), searcher: searcher.clone(), }) } } }