首页›Mara Bos›文章

Behind the Scenes of Rust String Formatting: format_args!()

2023年12月5日

AI 摘要 AI 生成,可能有误

这篇博客文章探讨了 Rust 的 fmt::Arguments 类型和 format_args!() 宏,它们为 print!()、format!() 和 log::info!() 等常见文本格式化宏提供支持。作者将 fmt::Arguments 描述为一个出色的构建模块,几乎每个 Rust 程序都会间接地使用它。这篇文章涵盖了它的工作原理、目前的实现方式,以及它在未来可能发生的变化。

The fmt::Arguments type is one of my favorite types in the Rust standard library. It’s not particularly amazing, but it is a great building block that is indirectly used in nearly every Rust program. This type, together with the format_args!() macro, is the power behind print!(), format!(), log::info!() and many more text formatting macros, both from the standard library and community crates.

In this blog post, we learn how it works, how it is implemented today, and how that might change in the future.

继续阅读全文

为了尊重作者,这里只展示开头几段。你可以去原文阅读,或者在 HorizonReader 里读:划线做笔记、让 AI 帮忙。

更多来自 Mara Bos

Rust Temporary Lifetimes and "Super Let"

AI 摘要This article explores the complicated and often overlooked topic of temporary lifetimes in Rust, noting that while simple cases work automatically, there are many situations where temporaries don't last exactly as long as desired. The authors rediscover the rules governing temporary lifetimes, examine several use cases for temporary lifetime extension, and introduce a proposed new language feature called 'super let' that would give developers more control over temporary lifetimes.

Do we need a "Rust Standard"?

AI 摘要This blog post examines whether Rust should receive a formal standards document like those that exist for C and C++. The author argues that while Rust needs an accurate specification, full 'standardization' may not be necessary depending on how it is defined. The post also provides an overview of the current state of Rust's stability guarantees and specification efforts.

Comparing Rust's and C++'s Concurrency Library

AI 摘要The article compares Rust's concurrency library with C++'s, noting that Rust's standard library features—threads, atomics, mutexes, and condition variables—closely resemble those introduced in C++11. C++ has since gained additional concurrency features through C++17 and C++20, with more proposals for future versions. The article reviews these C++ features, discusses what Rust equivalents could look like, and what it would take to implement them.

Converting Integers to Floats Using Hyperfocus

AI 摘要The author recounts how, through an unexpected chain of events, they implemented a conversion from 128-bit integers to 64-bit floats that turned out to be faster than the built-in conversion of every compiler they tested. The blog post explains what happened, how floats work, how the conversion functions, and how the project got a bit out of hand.

Rust is not a Company

AI 摘要The author, a contributor to the Rust project, initially perceived the project's hierarchy of teams and leaders as just another typical organizational structure. After becoming more involved—joining the library team and eventually becoming its team lead—they started reflecting more deeply on why this structure exists and what purpose these teams actually serve.