translation(appendix/rust-versions) : 1.75

pull/1354/head
Eucalypt 9 months ago committed by GitHub
parent 1e287ffd85
commit fa0bbb9b10
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -378,3 +378,4 @@
- [1.72](appendix/rust-versions/1.72.md) - [1.72](appendix/rust-versions/1.72.md)
- [1.73](appendix/rust-versions/1.73.md) - [1.73](appendix/rust-versions/1.73.md)
- [1.74](appendix/rust-versions/1.74.md) - [1.74](appendix/rust-versions/1.74.md)
- [1.75](appendix/rust-versions/1.75.md)

@ -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)
Loading…
Cancel
Save