From c27c8ea184fb3e59d05a7d155ae45ce19042c8ba Mon Sep 17 00:00:00 2001 From: Paolo Barbolini Date: Mon, 2 Dec 2024 12:23:59 +0100 Subject: [PATCH] refactor: replace once_cell with std equivalents (#242) --- Cargo.lock | 2 -- Cargo.toml | 1 - libs/badge/Cargo.toml | 1 - libs/badge/badge.rs | 5 +++-- src/engine/mod.rs | 5 ++--- src/server/mod.rs | 7 +++---- 6 files changed, 8 insertions(+), 13 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 9ced1e0..9a9150d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -376,7 +376,6 @@ name = "badge" version = "0.2.0" dependencies = [ "base64", - "once_cell", "rusttype", "serde", "serde_urlencoded", @@ -3590,7 +3589,6 @@ dependencies = [ "lru_time_cache", "maud", "mime", - "once_cell", "parking_lot", "pulldown-cmark", "relative-path", diff --git a/Cargo.toml b/Cargo.toml index aaf156f..17605ec 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -29,7 +29,6 @@ indexmap = { version = "2", features = ["serde"] } lru_time_cache = "0.11" maud = "0.26" mime = "0.3" -once_cell = "1" parking_lot = "0.12" pulldown-cmark = "0.12" relative-path = { version = "1", features = ["serde"] } diff --git a/libs/badge/Cargo.toml b/libs/badge/Cargo.toml index d7c4106..8e9103a 100644 --- a/libs/badge/Cargo.toml +++ b/libs/badge/Cargo.toml @@ -13,7 +13,6 @@ path = "badge.rs" [dependencies] base64 = "0.22" -once_cell = "1" rusttype = "0.9" serde = { version = "1", features = ["derive"] } diff --git a/libs/badge/badge.rs b/libs/badge/badge.rs index f328738..4d9918c 100644 --- a/libs/badge/badge.rs +++ b/libs/badge/badge.rs @@ -1,7 +1,8 @@ //! Simple badge generator +use std::sync::LazyLock; + use base64::display::Base64Display; -use once_cell::sync::Lazy; use rusttype::{point, Font, Point, PositionedGlyph, Scale}; use serde::Deserialize; @@ -63,7 +64,7 @@ struct BadgeStaticData { offset: Point, } -static DATA: Lazy = Lazy::new(|| { +static DATA: LazyLock = LazyLock::new(|| { let font = Font::try_from_bytes(FONT_DATA).expect("failed to parse font collection"); let v_metrics = font.v_metrics(SCALE); diff --git a/src/engine/mod.rs b/src/engine/mod.rs index d94b94b..2e53a5f 100644 --- a/src/engine/mod.rs +++ b/src/engine/mod.rs @@ -1,7 +1,7 @@ use std::{ collections::HashSet, panic::RefUnwindSafe, - sync::Arc, + sync::{Arc, LazyLock}, time::{Duration, Instant}, }; @@ -13,7 +13,6 @@ use futures_util::{ stream::{self, LocalBoxStream}, StreamExt as _, }; -use once_cell::sync::Lazy; use relative_path::{RelativePath, RelativePathBuf}; use rustsec::database::Database; use semver::VersionReq; @@ -296,7 +295,7 @@ async fn resolve_crate_with_engine( Ok(crate_res.releases) } -static POPULAR_REPO_BLOCK_LIST: Lazy> = Lazy::new(|| { +static POPULAR_REPO_BLOCK_LIST: LazyLock> = LazyLock::new(|| { vec![ RepoPath::from_parts("github", "rust-lang", "rust"), RepoPath::from_parts("github", "xi-editor", "xi-editor"), diff --git a/src/server/mod.rs b/src/server/mod.rs index a218047..cbfc2d6 100644 --- a/src/server/mod.rs +++ b/src/server/mod.rs @@ -1,4 +1,4 @@ -use std::env; +use std::{env, sync::LazyLock}; use actix_web::{ get, @@ -16,7 +16,6 @@ use actix_web_lab::{ use assets::STATIC_FAVICON_PATH; use badge::BadgeStyle; use futures_util::future; -use once_cell::sync::Lazy; use semver::VersionReq; use serde::Deserialize; @@ -304,8 +303,8 @@ pub(crate) async fn not_found() -> impl Responder { Html::new(views::html::error::render_404().0) } -static SELF_BASE_URL: Lazy = - Lazy::new(|| env::var("BASE_URL").unwrap_or_else(|_| "http://localhost:8080".to_string())); +static SELF_BASE_URL: LazyLock = + LazyLock::new(|| env::var("BASE_URL").unwrap_or_else(|_| "http://localhost:8080".to_string())); /// Configuration options supplied through Get Parameters #[derive(Debug, Clone, Default)]