On the anniversary of the release of the Rust programming language 1.0 (the Rust project was founded in 2006, the release 0.1 was created in 2012, and the first stable version was presented in 2015), the Rust 1.87 release was published. The language focuses on safe memory handling and provides means to achieve high parallelism in task execution while avoiding the use of a garbage collector and runtime (runtime is limited 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 standard library now includes support for anonymous pipes. The method std::io::pipe() is proposed for creating anonymous pipes, which can be used alongside std::process::Command to handle standard input and output streams as well as to combine stdout and stderr streams. use std::process::Command; use std::io::Read; let (mut recv, send) = std::io::pipe()?; let mut command = Command::new("path/to/bin") // merging stdout and stderr into one pipe .stdout(send.try_clone()?) .stderr(send) .spawn()?; let mut output = Vec::new(); recv.read_to_end(&mut output)?; assert!(command.wait()?.success());
- Calling most of the compiler's built-in functions (Intrinsics) std::arch from safe code is now allowed. The change applies to the std::arch built-in functions that were marked as unsafe only due to binding to certain functionality, if that functionality is enabled. For instance, _mm256_add_epi32 can be called from safe code if the application uses ‘#[target_feature(enable = "avx2")]’.
- It is now permitted to jump from "asm!" blocks with assembly code to blocks containing Rust code, simplifying the development of low-level code, for example, implementing optimizations in the kernel or organizing hardware interaction. The jump point for the assembly command "jmp" is specified in the "asm!" macro using the new operand "label," which contains a block expression with Rust code. unsafe { asm!( "jmp {}", label { println!("Jumped from asm!"); } ); }
- It is allowed to specify captured generalized types and lifetimes in trait definitions using the return types impl Trait. trait Foo { fn method(&'a self) -> impl Sized; type Implicit1: Sized; fn method_desugared(&'a self) -> Self::Implicit1; fn precise(&'a self) -> impl Sized + use; type Implicit2: Sized; fn precise_desugared(&'a self) -> Self::Implicit2; }
- A new batch of APIs has been promoted to stable, including stabilized methods and trait implementations:
- Vec::extract_if
- vec::ExtractIf
- LinkedList::extract_if
- linked_list::ExtractIf
- ::split_off
- ::split_off_mut
- ::split_off_first
- ::split_off_first_mut
- ::split_off_last
- ::split_off_last_mut
- String::extend_from_within
- os_str::Display
- OsString::display
- OsStr::display
- io::pipe
- io::PipeReader
- io::PipeWriter
- impl From for OwnedHandle
- impl From for OwnedHandle
- impl From for Stdio
- impl From for Stdio
- impl From for OwnedFd
- impl From for OwnedFd
- Box<MaybeUninit>::write
- impl TryFrom<Vec> for String
- ::offset_from_unsigned
- ::byte_offset_from_unsigned
- ::offset_from_unsigned
- ::byte_offset_from_unsigned
- NonNull::offset_from_unsigned
- NonNull::byte_offset_from_unsigned
- ::cast_signed
- NonZero::::cast_signed.
- ::cast_unsigned.
- NonZero::::cast_unsigned.
- ::is_multiple_of
- ::unbounded_shl
- ::unbounded_shr
- ::unbounded_shl
- ::unbounded_shr
- ::midpoint
- ::from_utf8
- ::from_utf8_mut
- ::from_utf8_unchecked
- ::from_utf8_unchecked_mut
- The ‘const’ attribute has been applied in the functions:
- core::str::from_utf8_mut
- ::copy_from_slice
- SocketAddr::set_ip
- SocketAddr::set_port,
- SocketAddrV4::set_ip
- SocketAddrV4::set_port,
- SocketAddrV6::set_ip
- SocketAddrV6::set_port
- SocketAddrV6::set_flowinfo
- SocketAddrV6::set_scope_id
- char::is_digit
- char::is_whitespace
- <N::as_flattened
- <N::as_flattened_mut
- String::into_bytes
- String::as_str
- String::capacity
- String::as_bytes
- String::len
- String::is_empty
- String::as_mut_str
- String::as_mut_vec
- Vec::as_ptr
- Vec::as_slice
- Vec::capacity
- Vec::len
- Vec::is_empty
- Vec::as_mut_slice
- Vec::as_mut_ptr
- The second level of support for the target platform i586-pc-windows-msvc has been removed. It is recommended to use the i686-pc-windows-msvc platform, which has support for SSE2 instructions. The i586-pc-windows-msvc platform has lost its relevance, as Windows 10 requires SSE2 support, and earlier releases of Windows are not supported in Rust.
Source: opennet.ru
