”sparce” protocol for crates.io, OnceCell and OnceLock, debug information labels

The Rust team is pleased to announce a new version of the language – 1.70.0. Rust is a programming language that allows anyone to create reliable and efficient software.

If you have a previous version of Rust installed via rustupthen to upgrade to version 1.70.0 you just need to run the command:

rustup update stable

If you haven’t already installed rustupyou can install it with corresponding page our website and see detailed release notes on GitHub.

If you want to help us test future releases, you can use beta (rustup default beta) or nightly (rustup default nightly) channel. Please, inform about all the errors you encountered.

What is stabilized in 1.70.0

‘sparce’ protocol is the default for crates.io

The ‘sparce’ Cargo protocol is now enabled by default for reading the index from crates.io. This feature was previously stabilized in Rust 1.68.0, but it still required some configuration to use it with crates.io. We promised this behavior would be the default in version 1.70.0 – and here it is!

You will see a significant performance improvement when extracting information from the crates.io index. Firewall restricted users will need to ensure that https://index.crates.io available. If for some reason you need to keep the previous default settings using the GitHub git index, you can use the config option registries.crates-io.protocol to change the protocol used.

The side effect of changing the accessor is that the path to the package cache also changes, and all dependencies are reloaded. Once you are fully committed to using the ‘sparce’ protocol, you will be able to remove the old cache $CARGO_HOME/registry/*/github.com-*.

OnceCell And OnceLock

Two new types have been stabilized for one-time initialization of shared data: OnceCell and its thread-safe counterpart OnceLock. They can be used wherever immediate creation is undesirable or even impossible, such as non-const data in global variables.

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(); // дайте им шанс...

        WINNER.get_or_init(|| "main")

    println!("{winner} победил!");

Packages like lazy_static And once_cellhave served this need in the past, but are now part of the standard library, ported from once_cell into modules unsync And sync. There are more methods that may be stabilized in the future, as well as companion types. LazyCell And LazyLockwhich retain their initialization function, but this first step in stabilization should already cover many use cases.


This newly stabilized trait has a single method is_terminal to determine if the implementation is a file descriptor or a terminal or TTY handle. This is another case of standardizing functionality that existed in external packages, such as atty And is-terminalusing C library functions isatty on target Unix systems, as well as elsewhere. This functionality is often used in programs that need to distinguish between scripting and interactive modes, such as representing colors or even the full TUI interactively.

use std::io::{stdout, IsTerminal};

fn main() {
    let use_color = stdout().is_terminal();
    // если так, добавляем коды цветов в вывод приложения...

Named debug info shortcuts

Compiler option -Cdebuginfo previously supported only numbers 0..=2 to increase the amount of debugging information, where Cargo used 2 by default in profiles dev And test and 0 in profiles release And bench. These debug levels are now named “none” (0), “limited” (1), and “full” (2). There are also two new levels: “line-directives-only” and “line-tables-only”.

The Cargo and rustc documentation previously referred to level 1 as “line tables only”, but contained no information about types and variables – only information about all functions. This level is now “limited”, and the new “line-tables-only” level is truncated to the minimum required for backtraces with filenames and line numbers. This may eventually become the level used for -Cdebuginfo=1. Another level line-directives-only is intended for NVPTX profiling and is not recommended for use in other cases.

Note that named options are not available for use in Cargo.toml. Their support is scheduled for the next release, 1.71.

Forced stabilization in test CLI

When functions #[test] compiled, the executable gets the command line interface from the package test. This CLI has several options, including those that are not yet stable and need to be specified. -Zunstable-options (like many other commands in the Rust toolbox). However, although this option is supposed to be allowed only in nightly builds, this restriction has not yet been active in test. Starting with version 1.70.0, stable and beta versions of Rust will no longer allow unstable options to be used when running tests, bringing these options in line with the documentation and making them only possible in nightly builds.

There have been cases where unstable settings could be used without the user’s knowledge, especially --format json, used by IntelliJ Rust and other IDE plugins. These projects are already adapting to this change, and the status of the JSON output can be monitored in appropriate task.

Stabilized APIs

Other changes

Check everything that has changed in Rust, Cargo And clippy.

Members 1.70.0

Many people have come together to create Rust 1.70.0. We wouldn’t have made it without you. Thank you!

From translators

For any questions about the Rust language, we can help you with Russian-language Telegram chat or in a similar chat for newbie questions. If you have questions about translations or want to help with them, please contact translators chat.

This article was jointly translated by TelegaOvoshey, kunansy, andreevlex and funkill.

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *