C-like lines, offset_of!, recursive async fn, strip in release profiles

C-like lines, offset_of!, recursive async fn, strip in release profiles

The Rust team is pleased to announce a new version of the language – 1.77.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.77.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.77.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.

C-string literals

Rust now supports C-like string literals (c"abc"), which are issued in memory by type &'static CStr and are converted to null-terminated strings. This makes it easier to write code that interacts with the interfaces of languages ​​that require nul-terminated strings. At the same time, appropriate checks for errors (for example, the absence of a nul byte) during compilation are preserved.

Recursive support async fn

Previously, asynchronous functions could not call themselves due to compiler limitations. In version 1.77, this restriction was removed, so recursive calls are allowed as long as they use some form of indirection to avoid an infinite function state size.

This means that the following code now works:

async fn fib(n: u32) -> u32 {
   match n {
       0 | 1 => 1,
       _ => Box::pin(fib(n-1)).await + Box::pin(fib(n-2)).await
   }
}

offset_of!

Macro is stabilized in 1.77.0 offset_of!which provides access to the byte offset of the corresponding public field of the structure. This macro is most useful when you want to offset a field without an existing instance of the type. The implementation of such a macro is already possible in stable, but without an instance of the type, the implementation would require complex unsafe code, which easily allows undefined behavior.

Users can now access the offset of a public field using offset_of!(StructName, field). This extends to expression usize with an offset in bytes from the beginning of the structure.

Enabling strip in release profiles by default

Cargo profiles that do not include debuginfo in the output (eg debug = 0), now include by default strip = "debuginfo".

This is necessary primarily because the precompiled standard library comes with debuginfo. This means that statically linked libraries and programs will include debuginfo from the standard library, even if debuginfo was not explicitly required.

Users who need debuginfo can enable it using the debug flag in the corresponding Cargo profile.

Stable APIs

Other changes

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

Who worked on 1.77.0

Many people came together to make Rust 1.77.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 translations or want to help with them, contact the translators’ chat.

This article was co-translated by TelegaOvoshey and funkill.

Related posts