Rust adds support for C-string literals

Support for C-string literals makes it easier to write code that interoperates with foreign language interfaces requiring null-terminated strings.

chain rust link heavy iron metal
cortixxx (CC0)

Rust 1.77, the latest version of the Mozilla Research-founded programming language focused on safety, speed, and concurrency, adds support for C-string literals.

C-string literals in Rust expand to a null-byte terminated string in memory of type & ‘static CStr. This makes it easier to write code that will interoperate with foreign language interfaces that require null-terminated strings. All relevant error-checking, such as for a missing interior null byte, is performed at compile time.

Announced March 21, Rust 1.77 can be installed using rustup:

$ rustup update stable

Another improvement in Rust 1.77 is support for recursion in async fn. Async functions previously could not call themselves due to a compiler limitation, but Rust 1.77 lifts that limitation. Recursive calls now are permitted as long as they use a form of indirection to avoid an infinite size for the state of the function.

Also in Rust 1.77, the offsetof! macro for struct fields has been stabilized. This provides access to the byte offset of the relevant public field of a struct. This macro can be most useful when the offset of a field is needed without an existing instance of a type, the Rust team said.

Additionally, Cargo package manager profiles in Rust 1.77 that do not enable debuginfo in outputs will enable strip = "debugiinfo" by default. This is mostly needed because the precompiled standard library ships with debuginfo, meaning that statically linked results would include the debuginfo from the standard library even if the local compilation did not explicitly request debuginfo.

Finally, Clippy in Rust 1.77 adds a new lint, incompatible_msrv, which will tell users if functionality being referenced is only available on newer versions than the declared minimum supported Rust version.

Rust 1.77 follows last month’s release of Rust 1.76, which featured ABI compatibility updates.

Copyright © 2024 IDG Communications, Inc.