Rust programming language 1.34 release

The system programming language Rust 1.34, developed by the Mozilla project, has been released. The language focuses on memory safety, provides automatic memory management, and provides a means to achieve high task parallelism without using a garbage collector or runtime.

Rust's automatic memory management frees the developer from pointer manipulation and protects against problems arising from low-level memory manipulation, such as after-free memory accesses, null pointer dereferences, buffer overruns, and the like. To distribute libraries, ensure assembly and manage dependencies, the project is developing the Cargo package manager, which allows you to get the libraries needed for the program in one click. The crates.io repository is supported for hosting libraries.

Main innovations:

  • Added tools to the Cargo package manager to work with alternative package registries that can coexist with the crates.io public registry. For example, private application developers can now use their own private registry that can be used when listing dependencies in Cargo.toml and use a versioning model similar to crates.io for their products, as well as reference both crates.io and crates.io in dependencies. to your own registry.

    To add an external registry to ~/.cargo/config
    a new option β€œmy-registry” is provided in the β€œ[registries]” section, and an β€œother-crate” option has been added to mention the external registry in dependencies in Cargo.toml in the β€œ[dependencies]” section. To connect to an additional registry, simply place the authentication token in the ~/.cargo/credentials file and run the command
    "cargo login --registry=my-registry", and to publish the package -
    "cargo publish --registry=my-registry";

  • Added full support for using the β€œ?” operator. in doctests, which allow you to use example code from the documentation as tests. Previously operator
    "?" could be used to handle errors during test execution only if there was a "fn main()" function or in the "#[test]" functions;

  • In custom attributes defined using procedural macros, it is possible to use arbitrary sets of tokens (β€œ#[attr($tokens)]”, β€œ#[attr[$tokens]] and #[attr{$tokens}]”) . Previously, elements could only be specified in a tree/recursive form using string literals, for example β€œ#[foo(bar, baz(quux, foo = β€œbar”))]”, but now it is possible to use enumerations ('#[range(0. .10)]') and constructions like β€œ#[bound(T: MyTrait)]”;
  • The TryFrom and TryInto traits have been stabilized, allowing type conversions with error handling. For example, methods like from_be_bytes with integer types use arrays as input, but the data often comes in a Slice type, and converting between arrays and slices is problematic to do manually. With the help of new traits, the specified operation can be performed on the fly through a call to .try_into(), for example, β€œlet num = u32::from_be_bytes(slice.try_into()?)”. For conversions that always succeed (for example, from type u8 to u32), an Infallible error type has been added to allow transparent use of
    TryFrom for all existing "From" implementations;

  • Deprecated the CommandExt::before_exec function, which allowed execution of a handler before exec that was executed in the context of a child process forked after the fork() call. Under such conditions, some resources of the parent process, such as file descriptors and mapped memory areas, could be duplicated, which could lead to undefined behavior and incorrect operation of libraries.
    Instead of before_exec, it is recommended to use the unsafe function CommandExt::pre_exec.

  • Stabilized signed and unsigned atomic integer types ranging in size from 8 to 64 bits (for example, AtomicU8), as well as signed types NonZeroI[8|16|32|54|128].
  • A new portion of the API has been moved to the category of stable, including the methods Any::type_id, Error::type_id, slice::sort_by_cached_key, str::escape_*, str::split_ascii_whitespace, Instant::checked_[add|sub] and SystemTime are stabilized ::checked_[add|sub]. The iter::from_fn and iter::successors functions have been stabilized;
  • For all integer types, the checked_pow, saturating_pow, wrapping_pow, and overflowing_pow methods are implemented;
  • Added the ability to enable optimizations at the linking stage by specifying the β€œ-C linker-plugin-lto” build option (rustc compiles Rust code into LLVM bitcode, which allows LTO optimizations to be applied).

Source: opennet.ru

Add a comment