Replace the lazy_static by once_cell crate

This commit is contained in:
Paul van Tilburg 2022-02-11 14:17:27 +01:00
parent 7497ff9ddc
commit d8f61486f9
3 changed files with 8 additions and 10 deletions

6
Cargo.lock generated
View File

@ -83,7 +83,7 @@ name = "autarco-scraper"
version = "0.1.1" version = "0.1.1"
dependencies = [ dependencies = [
"color-eyre", "color-eyre",
"lazy_static", "once_cell",
"reqwest", "reqwest",
"rocket", "rocket",
"serde", "serde",
@ -817,9 +817,9 @@ dependencies = [
[[package]] [[package]]
name = "once_cell" name = "once_cell"
version = "1.8.0" version = "1.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "692fcb63b64b1758029e0a96ee63e049ce8c5948587f2f7208df04625e5f6b56" checksum = "da32515d9f6e6e489d7bc9d84c71b060db7247dc035bbe44eac88cf87486d8d5"
[[package]] [[package]]
name = "openssl" name = "openssl"

View File

@ -6,7 +6,7 @@ edition = "2018"
[dependencies] [dependencies]
color-eyre = "0.5.6" color-eyre = "0.5.6"
lazy_static = "1.4.0" once_cell = "1.9.0"
reqwest = { version = "0.11", features = ["cookies", "json"] } reqwest = { version = "0.11", features = ["cookies", "json"] }
rocket = { version = "0.5.0-rc.1", features = ["json"] } rocket = { version = "0.5.0-rc.1", features = ["json"] }
serde = "1.0.116" serde = "1.0.116"

View File

@ -2,7 +2,7 @@ use std::path::Path;
use std::sync::Mutex; use std::sync::Mutex;
use color_eyre::Result; use color_eyre::Result;
use lazy_static::lazy_static; use once_cell::sync::Lazy;
use rocket::serde::json::Json; use rocket::serde::json::Json;
use rocket::tokio::fs::File; use rocket::tokio::fs::File;
use rocket::tokio::io::AsyncReadExt; use rocket::tokio::io::AsyncReadExt;
@ -33,6 +33,9 @@ struct Config {
site_id: String, site_id: String,
} }
/// The global, concurrently accessible current status.
static STATUS: Lazy<Mutex<Option<Status>>> = Lazy::new(|| Mutex::new(None));
/// Loads the configuration. /// Loads the configuration.
/// ///
/// The configuration file `autarco.toml` should be located in the project path. /// The configuration file `autarco.toml` should be located in the project path.
@ -63,11 +66,6 @@ struct Status {
last_updated: u64, last_updated: u64,
} }
lazy_static! {
/// The concurrently accessible current status.
static ref STATUS: Mutex<Option<Status>> = Mutex::new(None);
}
/// Returns the current (last known) status. /// Returns the current (last known) status.
#[get("/", format = "application/json")] #[get("/", format = "application/json")]
async fn status() -> Option<Json<Status>> { async fn status() -> Option<Json<Status>> {