Announcing Rust 1.80.0
Francesco Ciulla

Francesco Ciulla @francescoxx

About: Check YouTube: https://www.youtube.com/@francescociulla

Location:
Rome, Italy
Joined:
Mar 2, 2020

Announcing Rust 1.80.0

Publish Date: Jul 25 '24
40 4

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

Comments 4 total

  • Abhishek Shukla
    Abhishek ShuklaJul 25, 2024

    Awesome Post Fran Thanks for Sharing 💛🎊

  • Paweł Kubik
    Paweł KubikJul 26, 2024

    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.

    • Francesco Ciulla
      Francesco CiullaJul 26, 2024

      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

Add comment