-
Notifications
You must be signed in to change notification settings - Fork 112
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Officially deprecate lazy_static #214
Comments
To align more with the upcoming standardizations within the Rust ecosystem which started with the release of `1.70.0` and the inevitable deprecation of `lazy_static`: rust-lang-nursery/lazy-static.rs#214
To align more with the upcoming standardizations within the Rust ecosystem which started with the release of `1.70.0` and the inevitable deprecation of `lazy_static`: rust-lang-nursery/lazy-static.rs#214
To align more with the upcoming standardizations within the Rust ecosystem which started with the release of `1.70.0` and the inevitable deprecation of `lazy_static`: rust-lang-nursery/lazy-static.rs#214
I think this library is still worth having, but with it's implementation switched to The interface of E.g. static regexes from string literals. |
I opened a PR for documenting in the README that one can now utilize the stable |
Are there currently any alternatives that provide a macro on top of |
use std::collections::HashMap;
use std::sync::OnceLock;
fn hashmap() -> &'static HashMap<u32, &'static str> {
static HASHMAP: OnceLock<HashMap<u32, &str>> = OnceLock::new();
HASHMAP.get_or_init(|| {
let mut m = HashMap::new();
m.insert(0, "foo");
m.insert(1, "bar");
m.insert(2, "baz");
m
})
}
fn main() {
// First access to `HASHMAP` initializes it
println!("The entry for `0` is \"{}\".", hashmap().get(&0).unwrap());
// Any further access to `HASHMAP` just returns the computed value
println!("The entry for `1` is \"{}\".", hashmap().get(&1).unwrap());
} |
@KodrAus Sorry, another month went by too fast 😅 I just sent you the crates.io ownership invite. |
While a bit niche, this crate is commonly used in This usecase makes swapping to a oncelock wrapper potentially problematic. Edit: Looking at OnceCell, it might be a suitable alternative. |
@Kimundi Sorry, it looks like I managed to miss this until the invite expired 🙃 Is there any chance of resending it? I can see us going around in circles a bit here though so if I ping a random member of the nursery team with permissions to push............ @cuviper could I trouble you to |
Published! |
Thanks @cuviper! |
Two cents: I don't think this repo should be deprecated until |
RHEL 9.4 and 8.10 both have Rust 1.75, so they have The "unmaintained" status here is true whether we issue an advisory or not. |
What are the alternatives for async? // Cannot use std::cell::OnceCell because it does not support async initialization
lazy_static! {
pub(crate) static ref CONFIG: AsyncOnce<Config> = AsyncOnce::new(async { Config::from_env().await });
} |
|
The example in #214 (comment) is more like a The problems reducing usability of
Footnotes
|
**NOTE**: This uses `LazyLock` which was stabilised recently in Rust 1.80. This means we're effectively pushing the MSRV (minimum supported Rust version) to 1.80+ which is relatively fresh ([July 2024]). I'm not too keen on [the alternatives]: 1. No nothing: Create a new datetime every time the `validate_date()` is called - possibly slow/unnecesary, although maybe not a tragedy 2. Use a dependency just for this (either `lazy_static` or `once_cell`) - just seems wrong to use a crate when this is now in the standard library I think `LazyLock` is just too good to pass on and we should keep it simple and just use it. From local testing we require 1.74+ anyway so we're "just" pushing the MSRV 6 Rust releases ahead. And update Rust with `rustup update` is trivial. [July 2024]: https://blog.rust-lang.org/2024/07/25/Rust-1.80.0.html [the alternatives]: rust-lang-nursery/lazy-static.rs#214
**NOTE**: This uses `LazyLock` which was stabilised recently in Rust 1.80. This means we're effectively pushing the MSRV (minimum supported Rust version) to 1.80+ which is relatively fresh ([July 2024]). I'm not too keen on [the alternatives]: 1. No nothing: Create a new datetime every time the `validate_date()` is called - possibly slow/unnecesary, although maybe not a tragedy 2. Use a dependency just for this (either `lazy_static` or `once_cell`) - just seems wrong to use a crate when this is now in the standard library I think `LazyLock` is just too good to pass on and we should keep it simple and just use it. From local testing we require 1.74+ anyway so we're "just" pushing the MSRV 6 Rust releases ahead. And update Rust with `rustup update` is trivial. [July 2024]: https://blog.rust-lang.org/2024/07/25/Rust-1.80.0.html [the alternatives]: rust-lang-nursery/lazy-static.rs#214
**NOTE**: This uses `LazyLock` which was stabilised recently in Rust 1.80. This means we're effectively pushing the MSRV (minimum supported Rust version) to 1.80+ which is relatively fresh ([July 2024]). I'm not too keen on [the alternatives]: 1. No nothing: Create a new datetime every time the `validate_date()` is called - possibly slow/unnecesary, although maybe not a tragedy 2. Use a dependency just for this (either `lazy_static` or `once_cell`) - just seems wrong to use a crate when this is now in the standard library I think `LazyLock` is just too good to pass on and we should keep it simple and just use it. From local testing we require 1.74+ anyway so we're "just" pushing the MSRV 6 Rust releases ahead. And update Rust with `rustup update` is trivial. [July 2024]: https://blog.rust-lang.org/2024/07/25/Rust-1.80.0.html [the alternatives]: rust-lang-nursery/lazy-static.rs#214
lazy_static
has served the community well over the better part of a decade. Over that time, the Rust language has evolved, and better alternatives built on that evolution have emerged. That functionality has now made its way into the standard library, with aspects of it stabilizing from1.70.0
.This library hasn't seen steady maintainership in some time. To support migration off
lazy_static
and towardsonce_cell
or the standard library's types I propose we formally deprecate this library.cc @rust-lang-nursery/libs-contributors
The text was updated successfully, but these errors were encountered: