Rust programming language 1.45 release

Published release 1.45 of the systems programming language Rustfounded 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 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, 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:

  • Eliminated old imperfection when performing conversions between integers and floating point numbers. Since the Rust compiler uses LLVM as a backend, type conversion operations were performed through LLVM intermediate code instructions such as fptoui, which have one significant feature - undefined behavior if the resulting value does not fit in the target type. For example, when converting the real value 300 of type f32 to the integer type u8, the result is unpredictable and may differ on different systems. The problem is that this feature appears in code that is not marked as "unsafe".

    Starting with Rust 1.45, type size overflow behavior is tightly regulated, and the "as" conversion operation performs an overflow check and casts the value being converted to the maximum or minimum value of the target type (for the example above, 300 would be converted to 255). To disable such checks, additional API calls "{f64, f32}::to_int_unchecked" are provided, working in unsafe mode.

    fn cast(x: f32) -> u8 {
    x as u8
    }

    fnmain() {
    let too_big = 300.0;
    let too_small = -100.0;
    let nan = f32::NAN;

    let x: f32 = 1.0;
    let y: u8 = unsafe { x.to_int_unchecked() };

    println!("too_big_casted = {}", cast(too_big)); // output 255
    println!("too_small_casted = {}", cast(too_small)); // output 0
    println!("not_a_number_casted = {}", cast(nan)); // output 0
    }

  • Usage stabilized procedural macros, similar to functions, in expressions, templates, and assertions. Previously, such macros could not be called everywhere, but only in certain parts of the code (by a separate call, not intertwined with other code). Extending the ways to call macros to look like functions was one of the things we needed to make the web framework work. Rocket in stable releases of Rust. Previously, to achieve additional flexibility in specifying handlers in Rocket, it was necessary to enable the experimental "proc_macro_hygiene" feature, which is not available in stable versions of Rust. This functionality is now built into stable releases of the language.
  • It is allowed to use ranges with type "char" to iterate over range values ​​(ops::{Range, RangeFrom, RangeFull, RangeInclusive, RangeTo}):

    for ch in 'a'..='z' {
    print!("{}", ch);
    }
    println!(); // Will print "abcdefghijklmnopqrstuvwxyz"

  • A new portion of the API has been transferred to the category of stable, including stabilized
    Arc::as_ptr,
    BTreeMap::remove_entry,
    Rc::as_ptr,
    rc::weak::as_ptr,
    rc::Weak::from_raw,
    rc::Weak::into_raw,
    str::strip_prefix,
    str::strip_suffix,
    sync::Weak::as_ptr,
    sync::Weak::from_raw,
    sync::Weak::into_raw,
    char::UNICODE_VERSION
    span::resolved_at,
    span::located_at,
    span::mixed_site,
    unix::process::CommandExt::arg0.

  • Added support to the rustc compiler to override various target platform features with the "target-feature" flag, for example, "-C target-feature=+avx2,+fma". New flags have also been added:
    "force-unwind-tables" to generate "unwind" call tables, regardless of the crash handling strategy; "embed-bitcode" to control the inclusion of LLVM bitcode in generated rlibs. The "embed-bitcode" flag is enabled by default in Cargo to optimize build time and disk space consumption.

  • Provided third level support for mipsel-sony-psp and thumbv7a-uwp-windows-msvc platforms. The third level implies basic support, but without automated testing and publication of official builds.

Additionally, it can be noted story about creating a simple apps in the Rust language that starts with a system loader and is ready to self-sufficiently boot in place of the operating system.
The article is the first in a series dedicated to demonstrating techniques that are in demand in low-level programming and OS development.

Source: opennet.ru

Add a comment