@@ -471,23 +471,20 @@ to a few **milliseconds** depending on the size of the pattern.) Not only is
471471compilation itself expensive, but this also prevents optimizations that reuse
472472allocations internally to the regex engine.
473473
474- In Rust, it can sometimes be a pain to pass regexes around if they're used from
475- inside a helper function. Instead, we recommend using crates like [`once_cell`]
476- and [`lazy_static`] to ensure that patterns are compiled exactly once.
474+ In Rust, it can sometimes be a pain to pass regular expressions around if
475+ they're used from inside a helper function. Instead, we recommend using
476+ [`std::sync::LazyLock`], or the [`once_cell`] crate,
477+ if you can't use the standard library.
477478
478- [`once_cell`]: https://crates.io/crates/once_cell
479- [`lazy_static`]: https://crates.io/crates/lazy_static
480-
481- This example shows how to use `once_cell`:
479+ This example shows how to use `std::sync::LazyLock`:
482480
483481```rust
484- use {
485- once_cell::sync::Lazy,
486- regex::Regex,
487- };
482+ use std::sync::LazyLock;
483+
484+ use regex::Regex;
488485
489486fn some_helper_function(haystack: &str) -> bool {
490- static RE: Lazy <Regex> = Lazy ::new(|| Regex::new(r"...").unwrap());
487+ static RE: LazyLock <Regex> = LazyLock ::new(|| Regex::new(r"...").unwrap());
491488 RE.is_match(haystack)
492489}
493490
@@ -501,6 +498,9 @@ Specifically, in this example, the regex will be compiled when it is used for
501498the first time. On subsequent uses, it will reuse the previously built `Regex`.
502499Notice how one can define the `Regex` locally to a specific function.
503500
501+ [`std::sync::LazyLock`]: https://doc.rust-lang.org/std/sync/struct.LazyLock.html
502+ [`once_cell`]: https://crates.io/crates/once_cell
503+
504504### Sharing a regex across threads can result in contention
505505
506506While a single `Regex` can be freely used from multiple threads simultaneously,
0 commit comments