Skip to content

Commit 39756b0

Browse files
committed
Get rid of dependency once_cell
1 parent 8f3e91c commit 39756b0

File tree

7 files changed

+11
-15
lines changed

7 files changed

+11
-15
lines changed

Cargo.lock

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ humansize = "2.1.3"
1717
humantime-serde = "1.1.1"
1818
image = "0.25.6"
1919
itertools = "0.14.0"
20-
once_cell = "1.21.3"
2120
paste = "1.0.15"
2221
rand = "0.9.2"
2322
reqwest = { version = "0.12.22", features = ["json", "gzip", "multipart"] }

src/config/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ pub struct Config {
3434
}
3535

3636
#[cfg(not(test))]
37-
static CONFIG: once_cell::sync::OnceCell<Config> = once_cell::sync::OnceCell::new();
37+
static CONFIG: std::sync::OnceLock<Config> = std::sync::OnceLock::new();
3838
#[cfg(test)]
3939
static CONFIG: parking_lot::RwLock<Option<std::sync::Arc<Config>>> = parking_lot::RwLock::new(None);
4040

src/lib.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,14 @@ mod reporter;
88
mod source;
99
mod task;
1010

11+
use std::sync::OnceLock;
12+
1113
use anyhow::anyhow;
12-
use once_cell::sync::OnceCell;
1314
use task::{Task, TaskReporter, TaskSubscription};
1415

1516
use crate::config::Config;
1617

17-
static CLI_ARGS: OnceCell<cli::Args> = OnceCell::new();
18+
static CLI_ARGS: OnceLock<cli::Args> = OnceLock::new();
1819

1920
pub fn cli_args() -> &'static cli::Args {
2021
CLI_ARGS.get().expect("global cli args not initialized")

src/platform/bilibili/source/playback/mod.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
pub mod bililive_recorder;
22

3-
use std::{fmt, future::Future, pin::Pin};
3+
use std::{fmt, future::Future, pin::Pin, sync::LazyLock};
44

55
use anyhow::anyhow;
66
use bililive_recorder::*;
7-
use once_cell::sync::Lazy;
87
use serde::Deserialize;
98
use spdlog::prelude::*;
109
use tokio::sync::mpsc;
@@ -54,7 +53,7 @@ const PLATFORM_METADATA: PlatformMetadata = PlatformMetadata {
5453
display_name: "bilibili 录播",
5554
};
5655

57-
static BACKEND: Lazy<BililiveRecorder> = Lazy::new(|| {
56+
static BACKEND: LazyLock<BililiveRecorder> = LazyLock::new(|| {
5857
BililiveRecorder::new(
5958
Config::global()
6059
.platform()

src/platform/telegram/notify/request.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
use std::{borrow::Cow, fmt, io::Cursor, mem, ops::Range, time::Duration};
1+
use std::{borrow::Cow, fmt, io::Cursor, mem, ops::Range, sync::LazyLock, time::Duration};
22

33
use anyhow::{anyhow, bail, ensure};
44
use bytes::Bytes;
55
use http::Uri;
66
use image::{imageops::FilterType as ImageFilterType, DynamicImage, GenericImageView, ImageFormat};
77
use itertools::Itertools;
8-
use once_cell::sync::Lazy;
98
use reqwest::multipart::{Form, Part};
109
use serde::{
1110
de::{DeserializeOwned, IgnoredAny},
@@ -248,7 +247,7 @@ impl<'a> Request<'a> {
248247
}
249248

250249
fn make_api_url(token: &str, method: &str, prefer_self_host: bool) -> String {
251-
static OFFICIAL: Lazy<Uri> = Lazy::new(|| "https://api.telegram.org".parse().unwrap());
250+
static OFFICIAL: LazyLock<Uri> = LazyLock::new(|| "https://api.telegram.org".parse().unwrap());
252251

253252
let url_opts = Config::global()
254253
.platform()

src/platform/twitter/source/mod.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,11 @@ use std::{
33
fmt,
44
future::Future,
55
pin::Pin,
6-
sync::Mutex as StdMutex,
6+
sync::{LazyLock, Mutex as StdMutex},
77
};
88

99
use anyhow::anyhow;
1010
use chrono::DateTime;
11-
use once_cell::sync::Lazy;
1211
use serde::Deserialize;
1312
use spdlog::prelude::*;
1413
use tokio::sync::Mutex;
@@ -546,8 +545,8 @@ fn parse_tweet(tweet: data::Tweet) -> anyhow::Result<Post> {
546545
.any(|kv| matches!(kv.value, data::TweetCardValue::Image { .. }))
547546
{
548547
// TODO: Make it more general for using in other places
549-
static REPORTED: Lazy<StdMutex<HashSet<String>>> =
550-
Lazy::new(|| StdMutex::new(HashSet::new()));
548+
static REPORTED: LazyLock<StdMutex<HashSet<String>>> =
549+
LazyLock::new(|| StdMutex::new(HashSet::new()));
551550

552551
if REPORTED
553552
.lock()

0 commit comments

Comments
 (0)