Release of Rust 1.82. New browser on Rust. Using Rust in Volvo

The release of the general-purpose programming language Rust 1.82 has been published, originally developed by Mozilla and now maintained under the auspices of the independent non-profit organization Rust Foundation. The language focuses on safe memory handling and provides means for achieving high parallelism of task execution, all without the use of a garbage collector and runtime (the runtime is reduced to basic initialization and maintenance of the standard library).

The memory management methods in Rust relieve developers from errors when manipulating pointers and protect against issues arising from low-level memory operations, such as accessing memory after it has been freed, dereferencing null pointers, buffer overflows, and so on. For distributing libraries, ensuring builds, and managing project dependencies, the package manager Cargo is being developed. A repository at crates.io supports library hosting.

Safe memory handling in Rust is ensured at compile time through reference checking, ownership tracking of objects, lifetime consideration (scope) of objects, and assessment of memory access correctness during code execution. Rust also provides means to protect against integer overflows, mandates the initialization of variable values before use, improved error handling in the standard library, employs the concept of immutability for references and variables by default, and offers strong static typing to minimize logical errors.

Key innovations:

  • The cargo package manager has introduced the 'info' command to output information about a package in the repository.
  • Support for the 'use' syntax in 'impl Trait' has been added, defining information about hidden types. For example, 'impl Trait + use' indicates that only parameters 'x' and 'T' are allowed in the hidden type.
  • A separate syntax for creating raw pointers has been proposed, replacing the previously used macros: the operator '&raw const expr' replaces the macro 'addr_of!(expr)', and the operator '&raw mut expr' replaces the macro 'addr_of_mut!(expr).\n\n struct Packed {\n not_aligned_field: i32,\n }\n fn main() {\n let p = Packed { not_aligned_field: 1_82 };\n\t\/\/ Old way of creating a raw pointer\n let ptr = std::ptr::addr_of!(p.not_aligned_field);\n\t\/\/ New way of creating a raw pointer\n let ptr = &raw const p.not_aligned_field;\n let val = unsafe { ptr.read_unaligned() };\n }
  • The ability to define safe functions and constants with a 'static' lifetime within 'extern' blocks marked as 'unsafe' has been provided (previously all elements in 'unsafe extern' could only have the 'unsafe' qualifier):\n\n unsafe extern {\n pub safe static TAU: f64;\n pub safe fn sqrt(x: f64) -> f64;\n pub unsafe fn strlen(p: *const u8) -> usize;\n }
  • The attributes no_mangle, link_section, and export_name, which can lead to undefined behavior, are now considered unsafe and require explicit marking with the 'unsafe' qualifier, for example:\n\n #[unsafe(no_mangle)]\n pub fn my_global_function() { }
  • When pattern matching, it is now allowed to skip empty types, such as 'enum Void {}' or structures with a visibly empty field.\n\n use std::convert::Infallible;\n pub fn unwrap_without_panic(x: Result) -> T {\n let Ok(x) = x; \t\/\/ 'Err' can be skipped\n x\n }
  • In types for floating-point numbers (f32 and f64), behavior has been standardized when handling non-numeric values NaN (0.0/0.0), and the use of floating-point operations in const fn has also been allowed.
  • The assembler inserts provide the ability to use operands with the 'const' qualifier for the direct use of integer values without first saving them in a register. const MSG: &str = "Hello, world!\n"; unsafe { core::arch::asm!( "mov rdx, {LEN} \/\/ the instruction 'mov rdx, 14' will be formed", LEN = const MSG.len(), … ); }
  • The addressing of expressions with the 'static' qualifier is allowed in a safe context without defining an unsafe block (the operators '&raw mut' and '&raw const' do not affect the operand's value and only create a pointer to it): static mut STATIC_MUT: Type = Type::new(); extern "C" { static EXTERN_STATIC: Type; } fn main() { let static_mut_ptr = &$raw mut STATIC_MUT; let extern_static_ptr = &$raw const EXTERN_STATIC; }
  • A new batch of APIs has been promoted to stable, including stabilized methods and trait implementations:
    • std::thread::Builder::spawn_unchecked
    • std::str::CharIndices::offset
    • std::option::Option::is_none_or
    • [T]::is_sorted
    • [T]::is_sorted_by
    • [T]::is_sorted_by_key
    • Iterator::is_sorted
    • Iterator::is_sorted_by
    • Iterator::is_sorted_by_key
    • std::future::Ready::into_inner
    • std::iter::repeat_n
    • impl DoubleEndedIterator for Take

      Source: opennet.ru
Buy reliable website hosting with DDoS protection, VPS VDS servers 🔥 Buy reliable website hosting with DDoS protection, VPS VDS servers | ProHoster