Rust programming language 1.42 release

Published system programming language release Rest 1.42founded by the Mozilla project. The language focuses on safe memory management, provides automatic memory management, and provides the means to achieve high job parallelism while avoiding the use of a garbage collector and runtime.

Rust's automatic memory management saves the developer from manipulating pointers and protects against problems arising from low-level memory manipulation, such as accessing a memory area after it has been freed, dereferencing null pointers, buffer overruns, etc. To distribute libraries, ensure assembly and manage dependencies, the project develops a package manager Job, which allows you to get the libraries you need for the program in one click. A repository is supported to host libraries crates.io.

All innovations:

  • Added by support for templates for matching parts of slices (dynamic arrays, slice). Previously, exact matches were allowed, but now it is possible to use constructs marked ".." to cover the remaining elements of the array. For example:

    fn foo(words: &[&str]) {
    match words {

    // checks the starting elements of the array and ignores
    elements following them
    ["Hello", "World", "!", ..] => println!("Hello World!"),

    // checks the first two elements "Foo" and "Bar", and the rest is not important
    ["Foo", "Bar", ..] => println!("Baz"),

    // ignore everything, but the last element must be "!".
    [.., “!”] => println!(“!!!”),

    // in the start slice we include everything except the last element, which should be “z”
    [start @ .., "z"] => println!("starts with: {:?}", start),

    // in the end slice we put everything except the first element, which should be “a”.
    ["a", end @ ..] => println!("ends with: {:?}", end),

    rest => println!("{:?}", rest),
    }
    }

  • Added a new macro “matches!”, which takes an expression and a pattern as input, and returns “true” if the pattern matches the expression. The template can use “|” operations and "if".

    match self.partial_cmp(other) {
    Some(Less) => true,
    _ => false,
    }

    matches!(self.partial_cmp(other), Some(Less))

    let foo = 'f';
    assert!(matches!(foo, 'A'..='Z' | 'a'..='z'));

    let bar = Some(4);
    assert!(matches!(bar, Some(x) if x > 2));

  • In panic messages displayed when used incorrectly
    types Option and Result, now display line numbers with a link to the code that made the problematic call, rather than links to the code implementing the call in libcore. For example, the change affects calls to unwrap and expect over Option::None, or crashes when using unwrap_err, expect, expect_err, and similar methods on the Result type.

  • The Cargo package manager provides automatic substitution of “proc_macro crate” into the “extern” block for packages with procedural macros. This change allows the "use" directive to be applied to procedural macros without having to specify "extern crate proc_macro;" in the code. For example, if the program uses the line “use proc_macro::TokenStream;”, then the code will now remain working if “extern crate proc_macro;” is removed from it.
  • The capabilities of the standard library have been expanded. In iter::Empty added Send and Sync support for any T values.
    Calls Pin::{map_unchecked, map_unchecked_mut} spared from having to return a type value for the "Sized" implementation.
    In io::Cursor implemented PartialEq and Eq. The “const” attribute determines the possibility of use in any context instead of constants, applied for the Layout::new method.

  • A new portion of the API has been transferred to the stable category, including the stabilized CondVar::wait_while, CondVar::wait_timeout_while,
    DebugMap::key, DebugMap::value,
    ManuallyDrop::take,
    ptr::slice_from_raw_parts_mut and ptr::slice_from_raw_parts.

  • The Error::description method has been deprecated.
  • Provided second level support for armv7a-none-eabi and riscv64gc-unknown-linux-gnu platforms. Support for the standard library for the riscv64gc-unknown-linux-gnu platform has been provided.
    Apple 32-bit platforms demoted up to the third level of support, which implies basic support, but without automated testing and publication of official builds. The downgrade in support is due to Apple no longer supporting 32-bit platforms.

Source: opennet.ru

Add a comment