refactor: replace once_cell with std equivalents (#242)

This commit is contained in:
Paolo Barbolini 2024-12-02 12:23:59 +01:00 committed by GitHub
parent 3a2e134c40
commit c27c8ea184
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 8 additions and 13 deletions

2
Cargo.lock generated
View file

@ -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",

View file

@ -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"] }

View file

@ -13,7 +13,6 @@ path = "badge.rs"
[dependencies]
base64 = "0.22"
once_cell = "1"
rusttype = "0.9"
serde = { version = "1", features = ["derive"] }

View file

@ -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<f32>,
}
static DATA: Lazy<BadgeStaticData> = Lazy::new(|| {
static DATA: LazyLock<BadgeStaticData> = LazyLock::new(|| {
let font = Font::try_from_bytes(FONT_DATA).expect("failed to parse font collection");
let v_metrics = font.v_metrics(SCALE);

View file

@ -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<HashSet<RepoPath>> = Lazy::new(|| {
static POPULAR_REPO_BLOCK_LIST: LazyLock<HashSet<RepoPath>> = LazyLock::new(|| {
vec![
RepoPath::from_parts("github", "rust-lang", "rust"),
RepoPath::from_parts("github", "xi-editor", "xi-editor"),

View file

@ -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<String> =
Lazy::new(|| env::var("BASE_URL").unwrap_or_else(|_| "http://localhost:8080".to_string()));
static SELF_BASE_URL: LazyLock<String> =
LazyLock::new(|| env::var("BASE_URL").unwrap_or_else(|_| "http://localhost:8080".to_string()));
/// Configuration options supplied through Get Parameters
#[derive(Debug, Clone, Default)]