The release of the Rust programming language 1.99 has been published, initially based on the Mozilla project but now developed under the auspices of the independent non-profit organization Rust Foundation. The language focuses on safe memory management and provides tools to achieve high parallelism in task execution without the use of a garbage collector and runtime (runtime is limited to basic initialization and supporting the standard library).
Memory handling methods in Rust aim to eliminate errors when manipulating pointers and protect against issues arising from low-level memory operations, such as accessing memory after it has been freed, dereferencing null pointers, buffer overflows, etc. To facilitate library distribution, ensure compilation, and manage project dependencies, the package manager Cargo is being developed. A repository, crates.io, is supported for hosting libraries.
Safe memory handling in Rust is ensured at compile time through reference checking, ownership tracking of objects, lifetime consideration (scope) of objects, and assessment of memory access correctness during code execution. Rust also provides means to protect against integer overflows, mandates the initialization of variable values before use, improved error handling in the standard library, employs the concept of immutability for references and variables by default, and offers strong static typing to minimize logical errors.
Key innovations:
- The ability to create variadic functions in Rust, exportable for calls from C projects (C ABI), has been introduced. The last element in the parameter list of such functions can be specified using the '...' construct, which is handled in Rust with a special VaList type, functioning similarly to va_list in C. unsafe extern "C" fn sum(mut args: ...) -> i32 { let a = unsafe { args.next_arg::() }; let b = unsafe { args.next_arg::() }; a + b } fn foo() -> i32 { unsafe { sum(0i32, 2i32) } }
- The functions Layout::for_value_raw, mem::size_of_val_raw, and mem::align_of_val_raw have been stabilized, allowing safe determination of size and alignment by raw pointers, including when using types with dynamically determined sizes, such as slices, without the need to create references to data.
- Documentation has been updated to recommend avoiding the release of memory obtained via a static reference with an unrestricted lifetime (&’static) by calling Box::leak (round-trip unleaking), as such actions may potentially lead to issues due to incompatibility with future compiler optimizations and memory allocation mechanisms. Instead of creating a static reference for temporary ownership transfer, it is advisable to use raw pointers, for example, by calling Box::into_non_null.
- A new batch of APIs has been promoted to stable, including stabilized methods and trait implementations:
- IntoIterator for Box
- IntoIterator for &Box
- IntoIterator for &mut Box
- VecDeque::retain_back
- core::ffi::VaList
- Box::into_non_null
- Box::from_non_null
- Vec::into_parts
- Vec::from_parts
- core::mem::size_of_val_raw
- core::mem::align_of_val_raw
- core::alloc::Layout::for_value_raw
- String::from_utf8_lossy_owned
- string::FromUtf8Error::into_utf8_lossy
- FusedIterator for StepBy
- std::fs::set_times
- std::fs::set_times_nofollow
- A new built-in profile 'debug' has been implemented in the cargo package manager, similar to the 'dev' profile (in the future, debugging and development capabilities are planned to be separated). Incremental compilation is disabled by default during CI builds.
- The target platform riscv64-unknown-linux-musl has been moved to the second level of support, which ensures successful builds but does not guarantee passing the test suite.
Additionally, recent announced projects and events related to Rust can be noted:
- Microsoft has promoted Rust to a first-level language and will provide full support at all stages of development within the company. Previously, first-level support was available for C++, C#, and TypeScript. It is noted that Rust is already used in over 100 Microsoft repositories. Among other things, Rust components are already utilized in products like Microsoft 365 and Copilot, and a separate backend rustc_codegen_utc for Rust has been prepared for the MSVC compiler, based on the rustc compiler.
The main goal of using Rust at Microsoft is to enhance the security of critical code. According to the Technical Director of Microsoft Azure, about 70% of all vulnerabilities in Windows are caused by memory-related issues that can be avoided by using Rust.
- Google has removed the old implementation of the inter-process communication mechanism Binder, written in C, from the Linux kernel in favor of a new Binder IPC driver, rewritten in Rust. It is noted that the old driver had accumulated significant technical debt and a multitude of complications over its 15-year existence, making it difficult to debug, maintain, and add new features. The Binder IPC driver in Rust is now considered the main implementation and is no longer presented as an experimental development.
- The release of Arti 2.7.0, an implementation of the Tor toolkit written in Rust, has been published. When the Arti code reaches a level capable of fully replacing the C version, Tor developers plan to give Arti the status of the main Tor implementation and gradually discontinue the maintenance of the C implementation. The new version has introduced functionality for relays. servers Directory Authority, related to document parsing, support for directory server mirroring, and DNS traffic processing. RPC implementation has been added to change and verify configurations. Several vulnerabilities have been fixed—onion service administrators are advised to urgently update their systems.
Source: opennet.ru
