Skip to main content

Command Palette

Search for a command to run...

Announcing Rust 1.80.0

Updated
2 min read
Announcing Rust 1.80.0
F

👋 Hi, I Am Francesco

  • I am a Computer Scientist interested in Web3 and DevRel.

  • I worked from 2017 to 2020 on the Copernicus project for the ESA European Space Agency as a Fullstack Developer.

  • Docker Captain

  • I have interviewed 195+ Developers on my YouTube Channel

  • I am a Developer Advocate at daily.dev

  • I have founded 4C, a community focused on Content Creation.

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

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));
    });
}

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!"),
    );
}

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`

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",
    }
}

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

B

I wanted to take a moment to share an incredible opportunity with you. I've been working closely with Catherine E. Russell, a professional trader whose expertise and guidance have truly transformed my approach to investing.Catherine's dedication to her craft and her proven track record in the trading world make her an invaluable asset. She possesses the unique ability to navigate the complexities of the market with precision and insight, consistently delivering impressive results.I wholeheartedly believe that partnering with Catherine as your trading advisor will not only enhance your investment journey but also provide you with the guidance and support you need to achieve your financial goals.Don't miss out on this opportunity to work with the best in the business. Catherine E. Russell on facebook is the epitome of professionalism and excellence, and I give her my full endorsement without hesitation.Let's seize this opportunity together and embark on a journey to financial success with Catherine by our side.

1