Rust programming language 1.73 release

The general-purpose programming language Rust 1.73, 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 format of messages issued by the default program crash handler (panic) has been redesigned. The text specified in the "panic!" macro is now shown on a separate line without quotation marks, making the message easier to read and eliminating confusion when nested quotes are present or split across multiple lines. fn main() { let file = "ferris.txt"; panic!("oh no! {file:?} not found!"); } There was thread 'main' panicked at 'oh no! "ferris.txt" not found!', src/main.rs:3:5 Thread 'main' panicked at src/main.rs:3:5: oh no! "ferris.txt" not found!

    The output of messages shown when the “assert_eq” and “assert_ne” macros are triggered has also been reworked. fn main() { assert_eq!("🦀", "🐟", "ferris is not a fish"); } There was thread 'main' panicked at 'assertion failed: `(left == right)` left: `"🦀"`, right: `"🐟"`: ferris is not a fish', src/main.rs:2 :5 Thread 'main' panicked at src/main.rs:2:5: assertion `left == right` failed: ferris is not a fish left: “🦀” right: “🐟”

  • In accordance with RFC 3184, the ability to directly manipulate thread-local (thread_local) LocalKey storage keys has been added > and LocalKey > through the use of get(), set(), take() and replace() methods, instead of using a "with(|inner| ...)" closure, which eliminates the need to perform additional initialization code for the default values ​​specified for new threads when using the macro “thread_local!” thread_local! { static THINGS: Cell > = Cell::new(Vec::new()); } fn f() { // was THINGS.with(|i| i.set(vec![32, 1, 2])); // became THINGS.set(vec![3, 1, 2]); // ... // was let v = THINGS.with(|i| i.take()); // became let v: Vec = THINGS.take(); }
  • A new portion of the API has been moved to the category of stable, including the methods and implementations of traits have been stabilized:
    • Unsigned {integer}::div_ceil
    • Unsigned {integer}::next_multiple_of
    • Unsigned {integer}::checked_next_multiple_of
    • std::ffi::FromBytesUntilNulError
    • std::os::unix::fs::chown
    • std::os::unix::fs::fchown
    • std::os::unix::fs::lfchown
    • LocalKey:: >::get
    • LocalKey:: >::set
    • LocalKey:: >::take
    • LocalKey:: >::replace
    • LocalKey:: >::with_borrow
    • LocalKey:: >::with_borrow_mut
    • LocalKey:: >::set
    • LocalKey:: >::take
    • LocalKey:: >::replace
  • The "const" attribute, which determines the possibility of using it in any context instead of constants, is used in functions:
    • rc::Weak::new
    • sync::Weak::new
    • NonNull::as_ref
  • The compiler provides recording of version information in the “.comment” section, similar to GCC and Clang.
  • The third level of support has been implemented for the platforms aarch64-unknown-teeos, csky-unknown-linux-gnuabiv2, riscv64-linux-android, riscv64gc-unknown-hermit, x86_64-unikraft-linux-musl and x86_64-unknown-linux-ohos. The third level involves basic support, but without automated testing, publishing official builds, or checking whether the code can be built.
  • The second level of support for the target platform wasm32-wasi-preview1-threads has been implemented. The second level of support involves an assembly guarantee.

Source: opennet.ru

Add a comment