File tree Expand file tree Collapse file tree 1 file changed +5
-5
lines changed
Expand file tree Collapse file tree 1 file changed +5
-5
lines changed Original file line number Diff line number Diff line change @@ -80,18 +80,18 @@ compilation itself expensive, but this also prevents optimizations that reuse
8080allocations internally to the matching engines.
8181
8282In 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
8888use {
89- once_cell :: sync :: Lazy ,
89+ std :: sync :: LazyLock ,
9090 regex :: Regex ,
9191};
9292
9393fn 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
You can’t perform that action at this time.
0 commit comments