Skip to content

Replace once_cell with std::sync::LazyLock #776

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

Merged
merged 1 commit into from
Apr 25, 2025
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
3 changes: 0 additions & 3 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 sentry-backtrace/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ rust-version = "1.81"

[dependencies]
backtrace = "0.3.44"
once_cell = "1"
regex = { version = "1.5.5", default-features = false, features = [
"std",
"unicode-perl",
Expand Down
5 changes: 3 additions & 2 deletions sentry-backtrace/src/parse.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
use once_cell::sync::Lazy;
use std::sync::LazyLock;

use regex::Regex;

use crate::utils::{demangle_symbol, filename, strip_symbol};
use crate::{Frame, Stacktrace};

static FRAME_RE: Lazy<Regex> = Lazy::new(|| {
static FRAME_RE: LazyLock<Regex> = LazyLock::new(|| {
Regex::new(
r#"(?xm)
^
Expand Down
11 changes: 5 additions & 6 deletions sentry-backtrace/src/utils.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
use std::borrow::Cow;
use std::{borrow::Cow, sync::LazyLock};

use once_cell::sync::Lazy;
use regex::{Captures, Regex};

static HASH_FUNC_RE: Lazy<Regex> = Lazy::new(|| {
static HASH_FUNC_RE: LazyLock<Regex> = LazyLock::new(|| {
Regex::new(
r#"(?x)
^(.*)::h[a-f0-9]{16}$
Expand All @@ -12,7 +11,7 @@ static HASH_FUNC_RE: Lazy<Regex> = Lazy::new(|| {
.unwrap()
});

static CRATE_HASH_RE: Lazy<Regex> = Lazy::new(|| {
static CRATE_HASH_RE: LazyLock<Regex> = LazyLock::new(|| {
Regex::new(
r"(?x)
\b(\[[a-f0-9]{16}\])
Expand All @@ -21,7 +20,7 @@ static CRATE_HASH_RE: Lazy<Regex> = Lazy::new(|| {
.unwrap()
});

static CRATE_RE: Lazy<Regex> = Lazy::new(|| {
static CRATE_RE: LazyLock<Regex> = LazyLock::new(|| {
Regex::new(
r"(?x)
^
Expand All @@ -34,7 +33,7 @@ static CRATE_RE: Lazy<Regex> = Lazy::new(|| {
.unwrap()
});

static COMMON_RUST_SYMBOL_ESCAPES_RE: Lazy<Regex> = Lazy::new(|| {
static COMMON_RUST_SYMBOL_ESCAPES_RE: LazyLock<Regex> = LazyLock::new(|| {
Regex::new(
r"(?x)
\$
Expand Down
1 change: 0 additions & 1 deletion sentry-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ release-health = []
cadence = { version = "1.4.0", optional = true }
crc32fast = { version = "1.4.0", optional = true }
log = { version = "0.4.8", optional = true, features = ["std"] }
once_cell = "1"
rand = { version = "0.9.0", optional = true }
regex = { version = "1.7.3", optional = true }
sentry-types = { version = "0.37.0", path = "../sentry-types" }
Expand Down
4 changes: 2 additions & 2 deletions sentry-core/src/constants.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
// Not all constants are used when building without the "client" feature
#![allow(dead_code)]

use once_cell::sync::Lazy;
use std::sync::LazyLock;

use crate::protocol::{ClientSdkInfo, ClientSdkPackage};

/// The version of the library
const VERSION: &str = env!("CARGO_PKG_VERSION");
pub(crate) const USER_AGENT: &str = concat!("sentry.rust/", env!("CARGO_PKG_VERSION"));

pub(crate) static SDK_INFO: Lazy<ClientSdkInfo> = Lazy::new(|| ClientSdkInfo {
pub(crate) static SDK_INFO: LazyLock<ClientSdkInfo> = LazyLock::new(|| ClientSdkInfo {
name: "sentry.rust".into(),
version: VERSION.into(),
packages: vec![ClientSdkPackage {
Expand Down
6 changes: 2 additions & 4 deletions sentry-core/src/hub_impl.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
use std::cell::{Cell, UnsafeCell};
use std::sync::{Arc, PoisonError, RwLock};
use std::sync::{Arc, LazyLock, PoisonError, RwLock};
use std::thread;

use crate::Scope;
use crate::{scope::Stack, Client, Hub};

use once_cell::sync::Lazy;

static PROCESS_HUB: Lazy<(Arc<Hub>, thread::ThreadId)> = Lazy::new(|| {
static PROCESS_HUB: LazyLock<(Arc<Hub>, thread::ThreadId)> = LazyLock::new(|| {
(
Arc::new(Hub::new(None, Arc::new(Default::default()))),
thread::current().id(),
Expand Down
7 changes: 3 additions & 4 deletions sentry-core/src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,14 @@
//! assert_eq!(events[0].message.as_ref().unwrap(), "Hello World!");
//! ```

use std::sync::{Arc, Mutex};

use once_cell::sync::Lazy;
use std::sync::{Arc, LazyLock, Mutex};

use crate::protocol::Event;
use crate::types::Dsn;
use crate::{ClientOptions, Envelope, Hub, Transport};

static TEST_DSN: Lazy<Dsn> = Lazy::new(|| "https://public@sentry.invalid/1".parse().unwrap());
static TEST_DSN: LazyLock<Dsn> =
LazyLock::new(|| "https://public@sentry.invalid/1".parse().unwrap());

/// Collects events instead of sending them.
///
Expand Down
1 change: 0 additions & 1 deletion sentry-debug-images/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,4 @@ rust-version = "1.81"

[dependencies]
findshlibs = "=0.10.2"
once_cell = "1"
sentry-core = { version = "0.37.0", path = "../sentry-core" }
4 changes: 2 additions & 2 deletions sentry-debug-images/src/integration.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::borrow::Cow;
use std::sync::LazyLock;

use once_cell::sync::Lazy;
use sentry_core::protocol::{DebugMeta, Event};
use sentry_core::{ClientOptions, Integration};

Expand Down Expand Up @@ -56,7 +56,7 @@ impl Integration for DebugImagesIntegration {
mut event: Event<'static>,
_opts: &ClientOptions,
) -> Option<Event<'static>> {
static DEBUG_META: Lazy<DebugMeta> = Lazy::new(|| DebugMeta {
static DEBUG_META: LazyLock<DebugMeta> = LazyLock::new(|| DebugMeta {
images: crate::debug_images(),
..Default::default()
});
Expand Down
Loading