首页›Mara Bos›文章

Rust Temporary Lifetimes and "Super Let"

2023年11月30日

AI 摘要 AI 生成,可能有误

本文探讨了 Rust 中临时值生命周期这一复杂且常被忽视的话题,指出虽然简单场景可以自动正常工作,但在许多情况下,临时值的存活时间并不完全符合预期。作者重新梳理了临时值生命周期的相关规则,考察了临时生命周期扩展的若干使用场景,并介绍了一项名为 'super let' 的拟议新语言特性,该特性将让开发者能够更好地控制临时值的生命周期。

The lifetime of temporaries in Rust is a complicated but often ignored topic. In simple cases, Rust keeps temporaries around for exactly long enough, such that we don’t have to think about them. However, there are plenty of cases were we might not get exactly what we want, right away.

In this post, we (re)discover the rules for the lifetime of temporaries, go over a few use cases for temporary lifetime extension, and explore a new language idea, super let, to give us more control.

继续阅读全文

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

更多来自 Mara Bos

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

AI 摘要This blog post explores Rust's fmt::Arguments type and the format_args!() macro, which power common text formatting macros such as print!(), format!(), and log::info!(). The author describes fmt::Arguments as a great building block that is indirectly used in nearly every Rust program. The post covers how it works, how it is implemented today, and how it might change in the future.

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.