C-like strings, 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 run the command:

$ rustup update stable

If you don't have it installed yet rustupyou can install it with corresponding page our website and also see detailed release notes on GitHub.

If you'd like to help us test future releases, you can use the beta channel (rustup default beta) or nightly (rustup default nightly). Please, report about all the errors you encounter.

What is stabilized in 1.77.0

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

C-like string literals

Rust now supports C-like string literals (c"abc"), which are represented in memory by the type &'static CStr and are converted to null-terminated strings. This makes it easier to write code that interacts with interfaces in languages ​​that require nul-terminated strings. This preserves all relevant error checking (for example, missing nul bytes) at compile time.

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 infinitely sized function state.

This means that code like this 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!

The macro has been 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 need to offset a field without an existing instance of the type. Implementation of such a macro is already possible in stable, but without an instance of the type, implementation would require complex unsafe code that easily allows undefined behavior.

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

Enabling strip in release profiles by default

Profiles Cargo, which are not included in the output debuginfo (For example debug = 0), now enabled 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 requested.

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

Stabilized APIs

Other changes

Check everything that has changed in Rust, Cargo And Clippy.

Who worked on 1.77.0

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

From translators

They can help you with any questions about the Rust language. Russian-language Telegram chat or similar chat for newbie questions. If you have questions about translations or want help with them, please contact translators chat.

This article was jointly translated by TelegaOvoshey and funkill.

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *