From 3f32174fa781da5c4d5f68828568e92cae63308c Mon Sep 17 00:00:00 2001 From: Noam Raphael Date: Mon, 17 Feb 2025 17:22:07 +0200 Subject: [PATCH] Update README.md to use LazyLock instead of OnceCell --- README.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index f1e4c404a..e658df67b 100644 --- a/README.md +++ b/README.md @@ -80,18 +80,18 @@ compilation itself expensive, but this also prevents optimizations that reuse allocations internally to the matching engines. In Rust, it can sometimes be a pain to pass regular expressions around if -they're used from inside a helper function. Instead, we recommend using the -[`once_cell`](https://crates.io/crates/once_cell) crate to ensure that -regular expressions are compiled exactly once. For example: +they're used from inside a helper function. Instead, we recommend using +[`LazyLock`](https://doc.rust-lang.org/stable/std/sync/struct.LazyLock.html) +to ensure that regular expressions are compiled exactly once. For example: ```rust use { - once_cell::sync::Lazy, + std::sync::LazyLock, regex::Regex, }; fn some_helper_function(haystack: &str) -> bool { - static RE: Lazy = Lazy::new(|| Regex::new(r"...").unwrap()); + static RE: LazyLock = LazyLock::new(|| Regex::new(r"...").unwrap()); RE.is_match(haystack) }