Rust programming language 1.61 release

The general-purpose programming language Rust 1.61, founded by the Mozilla project but now developed under the auspices of the independent non-profit organization Rust Foundation, has been released. The language focuses on memory safety and provides the means to achieve high job parallelism while avoiding the use of a garbage collector and runtime (runtime is reduced to basic initialization and maintenance of the standard library).

Rust's memory handling methods save the developer from errors when manipulating pointers and protect against problems that arise due to low-level memory handling, such as accessing a memory area after it has been freed, dereferencing null pointers, buffer overruns, etc. To distribute libraries, provide builds and manage dependencies, the project develops the Cargo package manager. The crates.io repository is supported for hosting libraries.

Memory safety is provided in Rust at compile time through reference checking, keeping track of object ownership, keeping track of object lifetimes (scopes), and assessing the correctness of memory access during code execution. Rust also provides protection against integer overflows, requires mandatory initialization of variable values ​​before use, handles errors better in the standard library, applies the concept of immutable references and variables by default, offers strong static typing to minimize logical errors.

Main innovations:

  • The ability to define your own return codes from the main function is provided. Initially, Rust's main function could only return the "()" (unit) type, which always indicated a successful exit status, unless the developer explicitly called the "process::exit(code)" function. In Rust 1.26, the unstable Termination trait in the main function provided the ability to return "Ok" and "Err" values, corresponding to EXIT_SUCCESS and EXIT_FAILURE codes in C programs. In Rust 1.61, the Termination trait has been made stable, and a separate ExitCode type has been introduced to represent a specific return code, which abstracts platform-specific return types by providing both the predefined SUCCESS and FAILURE constants and the From method. to return an arbitrary return code. use std::process::ExitCode; fn main() -> ExitCode { if !check_foo() { return ExitCode::from(8); } ExitCode::SUCCESS }
  • Stabilized additional features of functions defined using the "const fn" expression, which can be called not only as normal functions, but also used in any context instead of constants. These functions are evaluated at compile time, not at run time, so they are subject to certain restrictions, such as being able to read only from constants. In the new version, basic operations with pointers to functions are allowed inside const functions (it is allowed to create, pass and cast pointers, but not calling a function by pointer); trait bounds for generic parameters of const functions, such as T: Copy; dynamically dispatched traits (dyn Trait); impl Trait types for function arguments and return values.
  • std::io stream handles Stdin, Stdout, and Stderr now have a static lifetime ("'static") when locked, allowing constructs like "let out = std::io::stdout().lock();" with getting a handle and setting a lock in one expression.
  • A new portion of the API has been moved to the category of stable, including the methods and implementations of traits have been stabilized:
    • Pin::static_mut
    • Pin::static_ref
    • Vec::retain_mut
    • VecDeque::retain_mut
    • Write for Cursor<[u8; N]>
    • std::os::unix::net::SocketAddr::from_pathname
    • std::process::ExitCode
    • std::process::Termination
    • std::thread::JoinHandle::is_finished
  • The "const" attribute, which determines the possibility of using it in any context instead of constants, is used in functions:
    • <*const T>::offset and <*mut T>::offset
    • <*const T>::wrapping_offset and <*mut T>::wrapping_offset
    • <*const T>::add and <*mut T>::add
    • <*const T>::sub and <*mut T>::sub
    • <*const T>::wrapping_add and <*mut T>::wrapping_add
    • <*const T>::wrapping_sub and <*mut T>::wrapping_sub
    • <[T]>::as_mut_ptr
    • <[T]>::as_ptr_range
    • <[T]>::as_mut_ptr_range

Additionally, we can note the article "Rust: A Critical Retrospective" with a summary of impressions about the Rust language after writing 100 thousand lines of code in it during the development of the Xous microkernel operating system used in firmware. Among the shortcomings, the syntax is difficult to understand, the incompleteness and continued development of the language, the lack of repeatable builds, the typical problems with trusting dependencies in Crates.io, the need to maintain a certain discipline to write safe code. Of the possibilities that exceeded expectations, the means for refactoring the code and reworking the β€œhacks” added during rapid prototyping are mentioned.

Source: opennet.ru

Add a comment