Contact Info

Atlas Cloud LLC 600 Cleveland Street Suite 348 Clearwater, FL 33755 USA

[email protected]

Client Area
Recommended Services
Supported Scripts
WordPress
Hubspot
Joomla
Drupal
Wix
Shopify
Magento
Typeo3

Rust 1.80 stabilizes LazyCell and LazyLock, two new types that can be used to delay initialization of data until the first time they are accessed. It also brings support for exclusive ranges as well as a couple of related lint warnings. Additionally, it allows variadic functions without a named parameter for compatibility with C23, stabilizes many APIs, and more.

LazyCell and LazyLock enable lazy initialization of shared data, with LazyLock being thread-safe. Their companions OnceCell and OnceLock, which enable one-time initialization of shared data, were stabilized in Rust 1.70 and could be used for lazy initialization, too, but in a less ergonomic way.

This is how you can define a lazily-initialized global using LazyLock:

Compare that with OnceLock syntax, where you define a value without explicitly initializing it. Instead, you use the OnceLock::get_or_init() function the first time you access it:

OnceLock and OnceCell serve a different purpose than their Lazy* counterparts, namely ensuring that a value is initialized only once. Using them for lazy initialization would require you to use the same initialization statement in every place where you access them, which is cumbersome.

Of the four types, LazyLock is the one that you can safely use in most contexts, with LazyCell being indicated if you want to remove any overhead related to concurrency and OnceLock and OnceCell being more flexible in terms of how you can handle initialization logic and supporting more complex use-cases.

Another useful addition to the language is support for exclusive ranges in pattern matching. Before version 1.80, Rust only supported inclusive endpoints, written as a..=b or ..=b. Now, you can also use a..b and ..b. With that, you can write:

To remove the chance of off-by-one errors, Rust 1.80 introduced two new lints, non_contiguous_range_endpoints and overlapping_range_endpoints which will detect mistakes when adopting exclusive patterns in existing code.

Rust 1.80 introduces many more changes in the language, compiler, and standard library. One minor but notable new feature is support for variadic functions without a named parameter. This amounted to just removing a static check disallowing such functions, but makes the language a tad closer to C23, which supports that syntax.

For a detailed list of all new features and stabilizations in Rust 1.80, do not miss the official release notes.


Welcome to DediRock, your trusted partner in high-performance hosting solutions. At DediRock, we specialize in providing dedicated servers, VPS hosting, and cloud services tailored to meet the unique needs of businesses and individuals alike. Our mission is to deliver reliable, scalable, and secure hosting solutions that empower our clients to achieve their digital goals. With a commitment to exceptional customer support, cutting-edge technology, and robust infrastructure, DediRock stands out as a leader in the hosting industry. Join us and experience the difference that dedicated service and unwavering reliability can make for your online presence. Launch our website.

Share this Post
0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x