Skip to content

Commit 326de84

Browse files
committed
Switch from lazy_static to once_cell
1 parent 6f286aa commit 326de84

File tree

3 files changed

+11
-11
lines changed

3 files changed

+11
-11
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ ansi-parsing = []
1919

2020
[dependencies]
2121
libc = "0.2.99"
22+
once_cell = "1.8"
2223
unicode-width = { version = "0.2", optional = true }
23-
lazy_static = "1.4.0"
2424

2525
[target.'cfg(windows)'.dependencies]
2626
encode_unicode = "1"

src/ansi.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -271,18 +271,18 @@ impl FusedIterator for AnsiCodeIterator<'_> {}
271271
mod tests {
272272
use super::*;
273273

274-
use lazy_static::lazy_static;
274+
use once_cell::sync::Lazy;
275275
use proptest::prelude::*;
276276
use regex::Regex;
277277

278278
// The manual dfa `State` is a handwritten translation from the previously used regex. That
279279
// regex is kept here and used to ensure that the new matches are the same as the old
280-
lazy_static! {
281-
static ref STRIP_ANSI_RE: Regex = Regex::new(
280+
static STRIP_ANSI_RE: Lazy<Regex> = Lazy::new(|| {
281+
Regex::new(
282282
r"[\x1b\x9b]([()][012AB]|[\[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-PRZcf-nqry=><])",
283283
)
284-
.unwrap();
285-
}
284+
.unwrap()
285+
});
286286

287287
impl<'a> PartialEq<Match<'a>> for regex::Match<'_> {
288288
fn eq(&self, other: &Match<'a>) -> bool {

src/utils.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use std::env;
44
use std::fmt;
55
use std::sync::atomic::{AtomicBool, Ordering};
66

7-
use lazy_static::lazy_static;
7+
use once_cell::sync::Lazy;
88

99
use crate::term::{wants_emoji, Term};
1010

@@ -22,10 +22,10 @@ fn default_colors_enabled(out: &Term) -> bool {
2222
|| &env::var("CLICOLOR_FORCE").unwrap_or_else(|_| "0".into()) != "0"
2323
}
2424

25-
lazy_static! {
26-
static ref STDOUT_COLORS: AtomicBool = AtomicBool::new(default_colors_enabled(&Term::stdout()));
27-
static ref STDERR_COLORS: AtomicBool = AtomicBool::new(default_colors_enabled(&Term::stderr()));
28-
}
25+
static STDOUT_COLORS: Lazy<AtomicBool> =
26+
Lazy::new(|| AtomicBool::new(default_colors_enabled(&Term::stdout())));
27+
static STDERR_COLORS: Lazy<AtomicBool> =
28+
Lazy::new(|| AtomicBool::new(default_colors_enabled(&Term::stderr())));
2929

3030
/// Returns `true` if colors should be enabled for stdout.
3131
///

0 commit comments

Comments
 (0)