From d8f61486f9681ec84245e29cee5a57730cc87010 Mon Sep 17 00:00:00 2001 From: Paul van Tilburg Date: Fri, 11 Feb 2022 14:17:27 +0100 Subject: [PATCH] Replace the lazy_static by once_cell crate --- Cargo.lock | 6 +++--- Cargo.toml | 2 +- src/main.rs | 10 ++++------ 3 files changed, 8 insertions(+), 10 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index fda469a..cc2e58e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -83,7 +83,7 @@ name = "autarco-scraper" version = "0.1.1" dependencies = [ "color-eyre", - "lazy_static", + "once_cell", "reqwest", "rocket", "serde", @@ -817,9 +817,9 @@ dependencies = [ [[package]] name = "once_cell" -version = "1.8.0" +version = "1.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "692fcb63b64b1758029e0a96ee63e049ce8c5948587f2f7208df04625e5f6b56" +checksum = "da32515d9f6e6e489d7bc9d84c71b060db7247dc035bbe44eac88cf87486d8d5" [[package]] name = "openssl" diff --git a/Cargo.toml b/Cargo.toml index fdb1e4e..d884f5a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,7 +6,7 @@ edition = "2018" [dependencies] color-eyre = "0.5.6" -lazy_static = "1.4.0" +once_cell = "1.9.0" reqwest = { version = "0.11", features = ["cookies", "json"] } rocket = { version = "0.5.0-rc.1", features = ["json"] } serde = "1.0.116" diff --git a/src/main.rs b/src/main.rs index 3a80006..820267c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -2,7 +2,7 @@ use std::path::Path; use std::sync::Mutex; use color_eyre::Result; -use lazy_static::lazy_static; +use once_cell::sync::Lazy; use rocket::serde::json::Json; use rocket::tokio::fs::File; use rocket::tokio::io::AsyncReadExt; @@ -33,6 +33,9 @@ struct Config { site_id: String, } +/// The global, concurrently accessible current status. +static STATUS: Lazy>> = Lazy::new(|| Mutex::new(None)); + /// Loads the configuration. /// /// The configuration file `autarco.toml` should be located in the project path. @@ -63,11 +66,6 @@ struct Status { last_updated: u64, } -lazy_static! { - /// The concurrently accessible current status. - static ref STATUS: Mutex> = Mutex::new(None); -} - /// Returns the current (last known) status. #[get("/", format = "application/json")] async fn status() -> Option> {