Paul Krill
Editor at Large

Rust adds support for C-string literals

news
Mar 21, 20242 mins

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
Credit: cortixxx

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.

Paul Krill

Paul Krill is editor at large at InfoWorld. Paul has been covering computer technology as a news and feature reporter for more than 35 years, including 30 years at InfoWorld. He has specialized in coverage of software development tools and technologies since the 1990s, and he continues to lead InfoWorld’s news coverage of software development platforms including Java and .NET and programming languages including JavaScript, TypeScript, PHP, Python, Ruby, Rust, and Go. Long trusted as a reporter who prioritizes accuracy, integrity, and the best interests of readers, Paul is sought out by technology companies and industry organizations who want to reach InfoWorld’s audience of software developers and other information technology professionals. Paul has won a “Best Technology News Coverage” award from IDG.

More from this author