Rest 1.35

The Rust development team is pleased to present a new version of their 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, then you can upgrade with the command:
$ rustup update stable

The main thing in the update is the implementation of the closure traits Fn, FnOnce, FnMut, for Box , Box , Box , respectively. Adding the ability to cast closures to pointers to unsafe functions, calling the dbg!() macro is now possible without arguments, and the standard library has been stabilized.

To details:

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

    Also, you can call the closure directly from the Box :
    fn foo(x: Box ) {
    x()
    }

  • Now closures can be cast to pointers to unsafe fn.
    Now 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 ()
    }

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

  • Added the ability to call the dbg!() macro without arguments.
    If you pass some expression to this macro, the macro will display its result. Example:
    fnmain() {
    let mut x = 0;

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

    dbg!(x);
    }

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

    Now you can write like this:
    fnmain() {
    let condition = true;

    if condition {
    dbg!();
    }
    }

    When you run this 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

      Actually, the functions copy the sign of another number. Example:
      fnmain() {
      assert_eq!(3.5_f32.copysign(-0.42), -3.5);
      }

    • Added new methods 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 a sequence:
      fnmain() {
      if (0..=10).contains(&5) {
      println!("Five is included in zero to ten.");
      }
      }

    • You can find the full list of stabilized APIs here. here
  • In this update, Clippy (It's a program that checks your code for many bugs) has added a new check for drop_bounds. This check is triggered when you put a constraint: T: Drop - for generic functions:
    fn foo (x:T){}

    Having a T: Drop constraint is most often a mistake, as some types are immediately excluded, such as u8. (You can read more about this here)

  • A lot of improvements and fixes in Cargo (language package manager), full list of changes

Source: linux.org.ru

Buy reliable hosting for sites with DDoS protection, VPS VDS servers πŸ”₯ Buy reliable website hosting with DDoS protection, VPS VDS servers | ProHoster