The release of the general-purpose programming language Rust 1.78 has been published. It was originally developed by Mozilla but is now being advanced under the auspices of the independent non-profit organization Rust Foundation. The language focuses on safe memory management and provides tools for achieving high task parallelism without relying on garbage collection and runtime (runtime is limited to basic initialization and supporting the standard library).
The memory management methods in Rust relieve developers from 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, and so on. For distributing libraries, ensuring builds, and managing project dependencies, the package manager Cargo is being developed. A repository at crates.io supports library hosting.
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:
- A new namespace for attributes, "#[diagnostic]", has been proposed, providing means to influence the error messages produced by the compiler. The first attribute in the new namespace is "#[diagnostic::on_unimplemented]", which can be used to customize error messages when a trait that is required for a type is not implemented. #[diagnostic::on_unimplemented( message = "My Message for `ImportantTrait` is not implemented for `{Self}" , label = "My Label", note = "Note 1", note = "Note 2" )] trait ImportantTrait {} fn use_my_trait(_: impl ImportantTrait) {} fn main() { use_my_trait(String::new()); } error[E0277]: My Message for `ImportantTrait` is not implemented for `String` —> src/main.rs:12:18 | 12 | use_my_trait(String::new()); | ———— ^^^^^^^^^^^^^ My Label | | | required by a bound introduced by this call | = help: the trait `ImportantTrait` is not implemented for `String` = note: Note 1 = note: Note 2
- Preliminary assert checks applied to unsafe functions can now be deferred until the code generation stage, allowing these checks to be performed without the need to build the standard library in "#[cfg(debug_assertions)]" mode. To trigger checks, it is now sufficient to enable debug assertions for test or debug builds of your code.
- The behavior of functions in the standard library that affect pointer alignment and slices is now predictable at runtime and depends on the input data. The function pointer::align_offset, which calculates the offset for pointer alignment, now returns usize::MAX only when the operation cannot be performed. The functions slice::align_to and slice::align_to_mut, which convert slices into a representation with aligned slices and the original start and end slices, now always return the largest aligned part.
- The following have been promoted to stable:
- impl Read for &Stdin
- The use of non-static lifetimes for certain implementations related to std::error::Error is now allowed.
- In the implementation impl, the use of the value ?Sized is now permitted.
- impl From for io::Error
- The function Barrier::new() has been stabilized for use with the 'const' qualifier in any context instead of being constant.
- For the target platforms x86_64-pc-windows-msvc, i686-pc-windows-msvc, x86_64-pc-windows-gnu, i686-pc-windows-gnu, x86_64-pc-windows-gnullvm, and i686-pc-windows-gnullvm, at least Windows 10 is now required.
- A third level of support has been implemented for the platforms wasm32-wasip2, arm64ec-pc-windows-msvc, armv8r-none-eabihf, and loongarch64-unknown-linux-musl. The third level implies basic support but without automated testing, publication of official builds, and verification of code buildability.
- A second level of support has been implemented for the target platform Add wasm32-wasip1. The second level of support guarantees buildability.
- The platform wasm32-wasi-preview1-threads has been renamed to wasm32-wasip1-threads.
- The compiler has been transitioned to use LLVM 18. When using LLVM 18 for the x86-32 and x86-64 architectures, the ABI related to the types u128 and i128 has been changed.
- In the package manager Cargo, version 4 of lockfiles (lockfile v4) has been stabilized.
- In Cargo, a global cache storing information about the last usage of data has been stabilized. The cache is stored in the file $CARGO_HOME/.global-cache using SQLite, is updated automatically, and reflects the latest changes related to the index, crate file, code directory, git clone, and git checkout.
Additionally, the programming language Borgo can be noted, which aims to be more expressive than Go while being less complex than Rust. Borgo combines the best features of Go and Rust, addressing the shortcomings of each language. For instance, Go is simple and easy to understand but does not provide advanced tools for type safety. Rust provides means for safe programming but is overly complicated. The project is developed by Marco Sampellegrini, author of 'The Simple Haskell Handbook' and developer of the continuous integration system Quad CI.

Borgo uses static typing, similar types to Go, and a syntax reminiscent of Rust. Specifying semicolons at the end of lines in Borgo code is not mandatory. Borgo code compiles to Go representation, which is fully compatible with existing Go packages. The compiler code is written in Rust and is distributed under the ISC license. use fmt enum NetworkState { Loading, Failed(int), Success(T), } struct Response { title: string, duration: int, } fn main() { let res = Response { title: 'Hello world', duration: 0, } let state = NetworkState.Success(res) let msg = match state { NetworkState.Loading => 'still loading', NetworkState.Failed(code) => fmt.Sprintf('Got error code: %d', code), NetworkState.Success(res) => res.title, } fmt.Println(msg) }
Source: opennet.ru
