Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

translation(appendix/rust-versions) : 1.75 #1354

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -378,3 +378,4 @@
- [1.72](appendix/rust-versions/1.72.md)
- [1.73](appendix/rust-versions/1.73.md)
- [1.74](appendix/rust-versions/1.74.md)
- [1.75](appendix/rust-versions/1.75.md)
39 changes: 39 additions & 0 deletions src/appendix/rust-versions/1.75.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Rust 新版解读 | 1.75 | async trait 和 RPITIT

> Rust 1.75 官方 release doc: [Announcing Rust 1.75.0 | Rust Blog](https://blog.rust-lang.org/2023/12/28/Rust-1.75.0.html)
通过 [rustup](https://www.rust-lang.org/tools/install) 安装的同学可以使用以下命令升级到 1.75 版本:

```shell
$ rustup update stable
```

## 在 traits 里使用 `async fn``impl Trait` 形式的返回值

之前的[文章](https://blog.rust-lang.org/2023/12/21/async-fn-rpit-in-traits.html)里也提到了,Rust 1.75 将支持在 traits 里使用 `async fn``impl Trait` 形式的返回值。不过如同前文所说这个版本还是有一些限制。

译者注:实践上来说,即使不考虑兼容低版本的rustc,目前也还是需要使用主流的 async-trait 三方库来写出简洁灵活的 async traits。不过相信官方团队最终肯定会都跟进吸纳这些实用的功能的。

## 指针字节偏移API

裸指针(`*const T``*mut T`)以前主要用作操作某个具体的类型为T的对象。例如,`<* const T>::add(1)` 会将大小是 `size_of::<T>()` 的字节数添加到指针指向的地址上。在某些情况下,使用字节偏移更方便,这些新API避免了调用者需要先将指针转换为 `*const u8` / `*mut u8` 的情况。

* [`pointer::byte_add`](https://doc.rust-lang.org/stable/core/primitive.pointer.html#method.byte_add)
* [`pointer::byte_offset`](https://doc.rust-lang.org/stable/core/primitive.pointer.html#method.byte_offset)
* [`pointer::byte_offset_from`](https://doc.rust-lang.org/stable/core/primitive.pointer.html#method.byte_offset_from)
* [`pointer::byte_sub`](https://doc.rust-lang.org/stable/core/primitive.pointer.html#method.byte_sub)
* [`pointer::wrapping_byte_add`](https://doc.rust-lang.org/stable/core/primitive.pointer.html#method.wrapping_byte_add)
* [`pointer::wrapping_byte_offset`](https://doc.rust-lang.org/stable/core/primitive.pointer.html#method.wrapping_byte_offset)
* [`pointer::wrapping_byte_sub`](https://doc.rust-lang.org/stable/core/primitive.pointer.html#method.wrapping_byte_sub)

## rustc 的代码布局优化

Rust编译器的的速度一直在优化,当前新版本应用了[LLVM - BOLT](https://github.com/llvm/llvm-project/blob/main/bolt/README.md)到二进制发布包,使得我们的基准测试用时时间改善了2%。这个工具优化了librustc_driver.so库的布局,能更好地利用缓存。

我们现在也用 `-Ccodegen-units=1` 来构建rustc,这为LLVM提供了更多的优化机会。这个优化使得我们的基准测试平均用时又提高了1.5%。

这些优化暂时仅限于x86_64-unknown-linux-gnu编译器,但我们预计后续会扩展到更多平台。

## Others

其它更新细节,和稳定的API列表,参考[原Blog](https://blog.rust-lang.org/2023/12/28/Rust-1.75.0.html#stabilized-apis)