|
|
@ -0,0 +1,46 @@
|
|
|
|
|
|
|
|
# Rust 新版解读 | 1.67 | `#[must_use]` in `async fn`
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
> Rust 1.67 官方 release doc: [Announcing Rust 1.67.0 | Rust Blog](https://blog.rust-lang.org/2023/01/26/Rust-1.67.0.html)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
通过 [rustup](https://www.rust-lang.org/tools/install) 安装的同学可以使用以下命令升级到 1.67 版本:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
```shell
|
|
|
|
|
|
|
|
$ rustup update stable
|
|
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2023新年好!大年初五更新的新版本,来看看有什么新变化~
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
## `#[must_use]` 作用于 `async fn` 上
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
注明了 `#[must_use]` 的 `async` 函数会把该属性应用在返回的 `impl Future` 结果上。`Future` trait 已经注明了 `#[must_use]` ,所以所有实现了 `Future` 的类型都会自动加上 `#[must_use]`。
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
所以在 1.67 版本,编译器会警告返回值没有被使用:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
```rust
|
|
|
|
|
|
|
|
#[must_use]
|
|
|
|
|
|
|
|
async fn bar() -> u32 { 0 }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async fn caller() {
|
|
|
|
|
|
|
|
bar().await;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
```text
|
|
|
|
|
|
|
|
warning: unused output of future returned by `bar` that must be used
|
|
|
|
|
|
|
|
--> src/lib.rs:5:5
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
5 | bar().await;
|
|
|
|
|
|
|
|
| ^^^^^^^^^^^
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
= note: `#[warn(unused_must_use)]` on by default
|
|
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
## `std::sync::mpsc` 实现更新
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
标准库里的 mpsc(多生产者单消费者) 通道自从 1.0 版本就有了,这次版本更新将其实现修改成了基于 [`crossbeam-channel`](https://crates.io/crates/crossbeam-channel)。不涉及到API的变更,但是修改了一些已有的bug,提升了性能和代码可维护性。用户应该不太会感知到明显的变化。
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
## Others
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
其它更新细节,和稳定的API列表,参考[原Blog](https://blog.rust-lang.org/2023/01/26/Rust-1.67.0.html#stabilized-apis)
|
|
|
|
|
|
|
|
|