DEV Community

Cover image for Announcing Rust 1.80.0
Francesco Ciulla
Francesco Ciulla

Posted on

Announcing Rust 1.80.0

Announcing Rust 1.80.0

The Rust team just announced the release of Rust 1.80.0.

This article aims to give you a quick recap of the main updates.

To update to this latest version, run:

$ rustup update stable
Enter fullscreen mode Exit fullscreen mode

Key Updates in Rust 1.80.0

LazyCell and LazyLock

These new types delay data initialization until first access.

LazyLock is thread-safe, suitable for static values, while LazyCell is not thread-safe but can be used in thread-local statics.

Example using LazyLock:

use std::sync::LazyLock;
use std::time::Instant;

static LAZY_TIME: LazyLock<Instant> = LazyLock::new(Instant::now);

fn main() {
    let start = Instant::now();
    std::thread::scope(|s| {
        s.spawn(|| {
            println!("Thread lazy time is {:?}", LAZY_TIME.duration_since(start));
        });
        println!("Main lazy time is {:?}", LAZY_TIME.duration_since(start));
    });
}
Enter fullscreen mode Exit fullscreen mode

Checked cfg Names and Values

Cargo 1.80 now includes checks for cfg names and values to catch typos and misconfigurations, improving the reliability of conditional configurations.

Example demonstrating cfg check:

fn main() {
    println!("Hello, world!");

    #[cfg(feature = "crayon")]
    rayon::join(
        || println!("Hello, Thing One!"),
        || println!("Hello, Thing Two!"),
    );
}
Enter fullscreen mode Exit fullscreen mode

Warning output:

warning: unexpected `cfg` condition value: `crayon`
 --> src/main.rs:4:11
  |
4 |     #[cfg(feature = "crayon")]
  |           ^^^^^^^^^^--------
  |                     |
  |                     help: there is an expected value with a similar name: `"rayon"`
  |
  = note: expected values for `feature` are: `rayon`
  = help: consider adding `crayon` as a feature in `Cargo.toml`
Enter fullscreen mode Exit fullscreen mode

Exclusive Ranges in Patterns

Rust now supports exclusive range patterns (a..b), enhancing pattern matching and reducing the need for separate constants for inclusive endpoints.

Example using exclusive range patterns:

pub fn size_prefix(n: u32) -> &'static str {
    const K: u32 = 10u32.pow(3);
    const M: u32 = 10u32.pow(6);
    const G: u32 = 10u32.pow(9);
    match n {
        ..K => "",
        K..M => "k",
        M..G => "M",
        G.. => "G",
    }
}
Enter fullscreen mode Exit fullscreen mode

Stabilized APIs

New stable APIs include implementations for Rc and Arc types, enhancements to Duration, Option, Seek, BinaryHeap, NonNull, and more.

Read more

This is just a quick recap. For more details, check out here

Have a great day

Francesco

Top comments (4)

Collapse
 
shukla007_47 profile image
Abhishek Shukla

Awesome Post Fran Thanks for Sharing 💛🎊

Collapse
 
francescoxx profile image
Francesco Ciulla

you are welcome

Collapse
 
pkubik profile image
Paweł Kubik

I understand your excitement, but isn't that straight plagiarism from blog.rust-lang.org/2024/07/25/Rust...

Forgive me if I'm wrong but I believe that copying content without attribution doesn't bring us any good.

Collapse
 
francescoxx profile image
Francesco Ciulla

I just used some parts and there is the redirection to the original article at the end. Yes you cna say I am excited. IF I get a complain from there, I will take it down but I am just trying to help