diff --git a/src/api.rs b/src/api.rs index fec5f17..d93cdff 100644 --- a/src/api.rs +++ b/src/api.rs @@ -7,13 +7,12 @@ use rocket::http::Status; use rocket::response::status; use xml::writer::{EmitterConfig, XmlEvent}; - /// Holds the config for torznab-toolkit. -/// +/// /// A search function (`/api?t=search`) and capabilities (`/api?t=caps` - `Caps`) are required, everything else is optional. -/// +/// ///
It's required to be set to something, which is why it's an Option set to None. -/// +/// /// However, this is NOT optional, and attempting to do anything with CONFIG not set will return an `Err`.
pub static mut CONFIG: Option = None; @@ -23,11 +22,14 @@ pub static mut CONFIG: Option = None; #[get("/api?t=caps")] pub(crate) fn caps() -> status::Custom { unsafe { - if CONFIG == None { - return status::Custom( - Status::InternalServerError, - "500 Internal server error: Config not specified".to_string(), - ); + match CONFIG { + None => { + return status::Custom( + Status::InternalServerError, + "500 Internal server error: Config not specified".to_string(), + ); + } + Some(_) => {} } } @@ -121,7 +123,7 @@ mod tests { CONFIG = Some(create_config()); println!("{:?}", CONFIG); } - caps(); + println!("{:?}", caps()); } #[test] @@ -129,6 +131,6 @@ mod tests { unsafe { println!("{:?}", CONFIG); } - caps(); + println!("{:?}", caps()); } }