Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: replace once_cell with std equivalents #242

Merged
merged 1 commit into from
Dec 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }
Expand Down
1 change: 0 additions & 1 deletion libs/badge/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ path = "badge.rs"

[dependencies]
base64 = "0.22"
once_cell = "1"
rusttype = "0.9"
serde = { version = "1", features = ["derive"] }

Expand Down
5 changes: 3 additions & 2 deletions libs/badge/badge.rs
Original file line number Diff line number Diff line change
@@ -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;

Expand Down Expand Up @@ -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);
Expand Down
5 changes: 2 additions & 3 deletions src/engine/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::{
collections::HashSet,
panic::RefUnwindSafe,
sync::Arc,
sync::{Arc, LazyLock},
time::{Duration, Instant},
};

Expand All @@ -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;
Expand Down Expand Up @@ -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"),
Expand Down
7 changes: 3 additions & 4 deletions src/server/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::env;
use std::{env, sync::LazyLock};

use actix_web::{
get,
Expand All @@ -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;

Expand Down Expand Up @@ -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)]
Expand Down
Loading