Rust programming language release 2021 (1.56)

The release of the system programming language Rust 1.56, founded by the Mozilla project, but now developed under the auspices of the independent non-profit organization Rust Foundation, has been published. In addition to the regular version number, the release is also labeled as Rust 2021 and marks the stabilization of the changes proposed over the past three years. Rust 2021 will also serve as the basis for feature builds over the next three years, similar to how the Rust 2018 release has been the basis for language development over the past three years.

To maintain compatibility, developers can use the "2015", "2018", and "2021" tags in their programs to link programs to language state slices corresponding to selected Rust editions. Revisions were introduced to separate incompatible changes and are configured in the metadata of cargo packages via the "edition" field in the "[package]" section. For example, the 2018 edition includes functionality that was stabilized at the end of 2018 and also covers all future changes that do not violate compatibility. The 2021 edition additionally includes compatibility breaking features proposed in the current 1.56 release and approved for implementation in the future. In addition to the language itself, the editors also take into account the state of the tools and documentation.

The main incompatibilities fixed in Rust 2021 are:

  • Separate Capture in Closures - Closures can now capture individual field names instead of the entire ID. For example, "|| ax + 1" will only capture "ax" instead of "a".
  • The IntoIterator trait for arrays: array.into_iter() allows you to iterate over the elements of an array by value rather than by reference.
  • Processing of "|" expressions has been changed in macro_rules (logical OR operation) in patterns - The ":pat" specifier in matches now respects the patterns "A | B".
  • The cargo package manager includes by default the second version of the feature resolver, support for which was introduced in Rust 1.51.
  • The traits TryFrom, TryInto, and FromIterator have been added to the prelude standard library module.
  • The panic!(..) and assert!(expr, ..) macros now always use format_args!(..) to format strings, similar to println!().
  • The expressions ident#, ident"…" and ident'…' are reserved in the syntax of the language.
  • The bare_trait_objects and ellipsis_inclusive_range_patterns warnings have been moved to the error category.

New in Rust 1.56:

  • In Cargo.toml, in the "[package]" section, the rust-version field has been added, through which you can determine the minimum supported version of Rust for the crate package. If the current version does not match the specified parameter, Cargo will abort with an error.
  • When pattern matching using "binding @ pattern" expressions, support is provided for specifying additional bindings (for example, "let matrix @ Matrix { row_len, .. } = get_matrix();").
  • A new portion of the API has been moved to the category of stable, including the methods and implementations of traits have been stabilized:
    • std::os::unix::fs::chroot
    • UnsafeCell::raw_get
    • BufWriter::into_parts
    • core::panic::{UnwindSafe, RefUnwindSafe, AssertUnwindSafe}
    • Vec::shrink_to
    • String::shrink_to
    • OsString::shrink_to
    • PathBuf::shrink_to
    • BinaryHeap::shrink_to
    • VecDeque::shrink_to
    • HashMap::shrink_to
    • HashSet::shrink_to
  • The "const" attribute, which determines the possibility of using it in any context instead of constants, is used in functions
    • std::mem::transmute
    • [T]::first
    • [T]::split_first
    • [T]::last
    • [T]::split_last
  • The compiler has been switched to use LLVM version 13.
  • Implemented level 64 support for the aarch32-apple-ios-sim platform and level XNUMX support for the powerpc-unknown-freebsd and riscvXNUMXimc-esp-espidf platforms. The third level implies basic support, but without automated testing, publishing official builds and checking the ability to build the code.

Recall that the Rust language focuses on safe memory management, provides automatic memory management, and provides a means to achieve high parallelism of job execution, while doing without the use of a garbage collector and runtime (runtime is reduced to basic initialization and maintenance of the standard library).

Rust's automatic memory management saves the developer from errors when manipulating pointers and protects against problems that arise due to low-level memory manipulation, 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.

Source: opennet.ru

Add a comment