Rust 1.35

The Rust development team is pleased to introduce the new version of its language: 1.35. Rust is a programming language that allows you to write reliable and efficient programs.

If you already have Rust installed via rustup, you can update using the command:
$ rustup update stable

The main feature of this update is the implementation of the closure traits Fn, FnOnce, and FnMut for Box, Box, and Box, respectively. It adds the ability to cast closures to pointers to unsafe functions, and calling the dbg!() macro is now possible without arguments; the stabilization of the standard library has also been completed.

Details:

  • The new version includes implementations for the traits Fn, FnOnce, and FnMut for Box, Box, and Box, respectively.
    Now this code will work:
    fn foo(x: Box u8>) -> Vec {
    vec![1, 2, 3, 4].into_iter().map(x).collect()
    }

    You can also invoke a closure directly from Box:
    fn foo(x: Box) {
    x()
    }

  • Closures can now be cast to pointers to unsafe fn.
    Currently, this code is valid:
    /// The safety invariants are those of the `unsafe fn` pointer passed.
    unsafe fn call_unsafe_fn_ptr(f: unsafe fn()) {
    f()
    }

    fn main() {
    // SAFETY: There are no invariants.
    // The closure is statically prevented from doing unsafe things.
    unsafe {
    call_unsafe_fn_ptr(|| {
    dbg!();
    });
    }
    }

  • The ability to call the dbg!() macro without arguments has been added.
    If you pass an expression to this macro, it will output its result. For example:
    fn main() {
    let mut x = 0;

    if dbg!(x == 1) {
    x += 1;
    }

    dbg!(x);
    }

    When you run such code, you will see:
    [src/main.rs:4] x == 1 = false
    [src/main.rs:8] x = 0

    Now you can write it like this:
    fn main() {
    let condition = true;

    if condition {
    dbg!();
    }
    }

    When running such code, you will see:
    [src/main.rs:5]

  • Some parts of the standard library have been stabilized.
    • New methods for f32 and f64:
      • f32::copysign
      • f64::copysign

      In fact, these functions copy the sign of another number. Example:
      fn main() {
      assert_eq!(3.5_f32.copysign(-0.42), -3.5);
      }

    • New methods have been added for Range types:
      • Range::contains
      • RangeFrom::contains
      • RangeTo::contains
      • RangeInclusive::contains
      • RangeToInclusive::contains

      With these methods, you can easily check if a certain value is in the sequence:
      fn main() {
      if (0..=10).contains(&5) {
      println!("Five is included in zero to ten.");
      }
      }

    • You can find the complete list of stabilized APIs. here
  • In this update, Clippy (a program that checks your code for many errors) added a new check for drop_bounds. This check triggers when you place the restriction: T: Drop — for generic functions:
    fn foo(x: T) {}

    Having a T: Drop restriction is often an error, as it immediately excludes certain types, such as u8. (You can read more about this) here)

  • A lot has been improved and fixed in Cargo (the language's package manager), the complete list of changes

Source: linux.org.ru

Buy reliable website hosting with DDoS protection, VPS VDS servers 🔥 Buy reliable website hosting with DDoS protection, VPS VDS servers | ProHoster