Skip to content

Commit 3f32174

Browse files
author
Noam Raphael
committed
Update README.md to use LazyLock instead of OnceCell
1 parent 1a069b9 commit 3f32174

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -80,18 +80,18 @@ compilation itself expensive, but this also prevents optimizations that reuse
8080
allocations internally to the matching engines.
8181

8282
In Rust, it can sometimes be a pain to pass regular expressions around if
83-
they're used from inside a helper function. Instead, we recommend using the
84-
[`once_cell`](https://crates.io/crates/once_cell) crate to ensure that
85-
regular expressions are compiled exactly once. For example:
83+
they're used from inside a helper function. Instead, we recommend using
84+
[`LazyLock`](https://doc.rust-lang.org/stable/std/sync/struct.LazyLock.html)
85+
to ensure that regular expressions are compiled exactly once. For example:
8686

8787
```rust
8888
use {
89-
once_cell::sync::Lazy,
89+
std::sync::LazyLock,
9090
regex::Regex,
9191
};
9292

9393
fn some_helper_function(haystack: &str) -> bool {
94-
static RE: Lazy<Regex> = Lazy::new(|| Regex::new(r"...").unwrap());
94+
static RE: LazyLock<Regex> = LazyLock::new(|| Regex::new(r"...").unwrap());
9595
RE.is_match(haystack)
9696
}
9797

0 commit comments

Comments
 (0)