The Rust team recently released a new version of Rust 1.70.0.
3 min readThe Rust team recently released a new version of Rust 1.70.0.
- Huawei Mate 60 Pro Makes Satellite Calls: Only US$0.18/minute
- Huawei Mate60 Pro: First Smart Phone Supports Satellite Calls
- 14000 cores + 450W: RTX 4080 graphics card perfectly replaces the RTX 3080
- Big upgrade: The difference between Bluetooth 5.0 and 5.2
- Geeks Disappointed that RTX 4080/4090 doesn’t come with PCIe 5.0
- What are advantages and disadvantages of different load balancing?
The Rust team recently released a new version of Rust 1.70.0. The noteworthy changes in the new version include:
Crates.io enables sparse indexing by default
Cargo’s “sparse” protocol is now enabled by default for reading indexes from crates.io. This feature was previously stabilized in Rust 1.68.0, but still requires configuration to be available in crates.io.
The original plan was to enable this feature by default in 1.70.0, but it didn’t happen until now.
You should see a huge performance boost when fetching information from crates.io’s index.
If for some reason you need to keep the previous default, which is to use the GitHub-hosted git index, you can use registries.crates-io.protocola configuration setting to change the default.
It should be noted that a side effect of changing the access method is that this also changes the path of the crate cache, so dependencies will be re-downloaded.
OnceCell and OnceLock
OnceCelland its thread-safe counterpart OnceLockTwo new types have been stabilized for one-time initialization of shared data. These two types can be used anywhere that immediate construction is not desired.
use std::sync::OnceLock;
static WINNER: OnceLock<&str> = OnceLock::new();
fn main() {
let winner = std::thread::scope(|s| {
s.spawn(|| WINNER.set("thread"));
std::thread::yield_now(); // give them a chance...
WINNER.get_or_init(|| "main")
});
println!("{winner} wins!");
}
Crates such as lazy_static
and once_cell
have filled this need in the past, but these building blocks are now part of the standard library, ported over once_cell
by unsync
and sync
modules of . There are many more methods that may be stabilized in the future, along with supporting LazyCell
and LazyLock
types that store their initializers.
IsTerminal
This new stable feature is_terminal
is used to determine whether a given file descriptor (descriptor) or handle (handle) represents a terminal or TTY. A common use case is to let the program distinguish between running in script mode and interactive mode, such as rendering colors or full TUI in interactive mode.
use std::io::{stdout, IsTerminal};
fn main() {
let use_color = stdout().is_terminal();
// if so, add color codes to program output...
}
Named levels of debug information
-Cdebuginfo
Compiler options previously only supported numbers 0…=2 to increase the amount of debug information, Cargo defaulted to 2 in development and test profiles, and 0 in release and bench profiles. These debug levels can now be set by name: “none” (0), “limited” (1) and “full” (2), and two new levels: “line-directives-only” and “line-tables -only”.
Note that these named options are not yet Cargo.toml
available , support for this will be in the next 1.71 release.
test CLI options
The executable gets a command-line interface from the crate when #[test]
the function is compiled. test
This CLI has many options, including some that are not yet stable, that need to be specified -Zunstable-options
, just like many other commands in the Rust toolchain. However, while this is only allowed in nightly builds, this restriction does not apply test
in . However, starting with 1.70.0, the stable and beta versions of Rust will no longer allow the unstable test
option .
There are known cases where unstable options may be used without the user’s knowledge, especially in IntelliJ Rust and other IDE plugins --format json
.
More details can be found at: https://blog.rust-lang.org/2023/06/01/Rust-1.70.0.html
- DIY a PBX (Phone System) on Raspberry Pi
- How to host multiple websites on Raspberry Pi 3/4?
- A Free Intercom/Paging system with Raspberry pi and old Android phones
- DIY project: How to use Raspberry Pi to build DNS server?
- Raspberry Pi project : How to use Raspberry Pi to build git server?