updating ABI compatibility, getting a type name from a reference / Habr

updating ABI compatibility, getting a type name from a reference / Habr

The Rust team is pleased to announce a new version of the language – 1.76.0. Rust is a programming language that allows anyone to create reliable and efficient software.

If you have a previous version of Rust installed via rustupthen to update to version 1.76.0 you just need to execute the command:

rustup update stable

If you don’t already have it installed rustupYou can install it from the relevant page on our website, and you can also view the detailed release notes on GitHub.

If you want to help us test future releases, you can use the beta channel (rustup default beta) or nightly (rustup default nightly). Please report any bugs you encounter.

Which is stabilized to 1.76.0

This release is relatively small, but as always, even small improvements add up to something bigger. Some changes will be covered in this announcement, while others are more niche and can be found in the detailed release notes.

ABI compatibility update

A new “ABI Compatibility” section in the function pointers documentation specifies the ABI compatibility of function signatures. It describes the compatibility between argument types and the return type, and lists the types that are currently considered compatible in Rust. For the most part, this documentation doesn’t add any new guarantees, just describes the current state of compatibility.

The only new addition is that char and u32 are now guaranteed to have a compatible ABI. They always have the same size and alignment, but now, according to the documentation above, they are treated as equivalent even in the function call ABI.

Getting a type name from a reference

For debugging in Rust 1.38 was added any::type_name::<T>() to return a string describing the type THowever, this required the type parameter to be explicitly specified. It wasn’t always easy to specify a specific type, especially for unnamed types like closures or opaque return types. Now type_name_of_val(&T) provides the ability to derive a descriptive name from any type reference.

fn get_iter() -> impl Iterator<Item = i32> {
    [1, 2, 3].into_iter()
}

fn main() {
    let iter = get_iter();
    let iter_name = std::any::type_name_of_val(&iter);
    let sum: i32 = iter.sum();
    println!("The sum of the `{iter_name}` is {sum}.");
}

It will now output:

The sum of the `core::array::iter::IntoIter<i32, 3>` is 6.

Stable APIs

Other changes

Check out everything that’s changed in Rust, Cargo, and Clippy.

Who worked on 1.76.0

Many people came together to create Rust 1.76.0. We couldn’t have done it without you. Thank you!

From translators

With any questions about the Rust language, you will be able to help in the Russian-language Telegram chat or in a similar chat for beginner questions. If you have questions about translation or want to help with them, please contact the translators’ chat.

This article was translated by Browning, TelegaOvoshey and funkill.

Related posts