rust-course
rust-course copied to clipboard
附录/版本更新内容 翻译工作
今天偶尔翻到附录里的版本更新内容,停更在了 1.62 ,前几天 rust 刚刚发布了 1.67
想借此机会多了解一下最新内容补充更多的知识水平,所以考虑翻译一下1.63-1.67这几次更新的内容。如果是已经完成了没有发出来麻烦告知我。
刚刚试着翻译了两段:
Rust 新版解读 | 1.63 | 重点: TODO!
Rust 1.63 官方 release doc: Announcing Rust 1.63.0 | Rust Blog
通过 rustup 安装的同学可以使用以下命令升级到 1.61 版本:
$ rustup update stable
范围线程 Scoped threads
Rust 从 1.0 版本起,就可以使用 std::thread::spawn
来创建一个线程,但是这个函数要求了其生成的线程必须拥有任何传递进去的参数的所有权,也就是说你不能把引用数据传递进去。在一些线程会在方法末尾退出的情况下(通常使用 join()
方法),这个严格的约束显得不必要,在此之前也通常使用 Arc
包裹数据的的方法来妥协。
随着 1.63 版本的推出,标准库新增了范围线程,允许在范围内创建使用当前调用栈内引用数据的线程。std::thread::scope
的API保证其中创建的线程会在自身返回前推出,也就允许安全的借用数据。看下面的例子,在 scope
内创建两个线程来,分别借用了数据:
let mut a = vec![1, 2, 3];
let mut x = 0;
std::thread::scope(|s| {
s.spawn(|| {
println!("hello from the first scoped thread");
// 可以借用变量 `a`
dbg!(&a);
});
s.spawn(|| {
println!("hello from the second scoped thread");
// 没有其它线程在使用,所以也可以可变借用 `x`
x += a[0] + a[2];
});
println!("hello from the main thread");
});
// Scope 退出后,可以继续修改、访问变量。
a.push(4);
assert_eq!(x, a.len());
完成了 Non-lexical-lifetime 的生命周期检查器的迁移
1.63 的rustc,完全删除了之前的词法借用检查,完全启用了新的 NLL 借用检查器。这不会对编译结果有任何变化,但对编译器的借用检查有优化效果。
如果对NLL不了解,在本书 引用与借用 一章里有介绍。
或者看官方博客的介绍 NLL
更详细内容可以看原博客 blog
如果 @sunface @AllanDowney (看到前几次更新内容都是你发布的) 没有什么意见的话,我就斗胆接过这项工作,尽一份力了,后续完成后逐个发PR。
不过水平有限,也期待其它有兴趣的伙伴一起补充。
非常棒
无敌~~以后就拜托兄弟了,之前的已经合并
@EluvK @sunface Hello, 1.78 is not visible on the side navigation in Rust Previous Version Updates, this link will prompt 404 when it is clicked.
@EluvK @sunface Hello, 1.78 is not visible on the side navigation in Rust Previous Version Updates, this link will prompt 404 when it is clicked.
Deployment has not been triggered after #1419
Maybe consider using github action to auto re-deployment after merge? @sunface
@EluvK @sunface Hello, 1.78 is not visible on the side navigation in Rust Previous Version Updates, this link will prompt 404 when it is clicked.
Deployment has not been triggered after #1419
Maybe consider using github action to auto re-deployment after merge? @sunface
We can use this action,and i added this #1423.
@sunface @EluvK 目前的问题是执行
mdbook test
命令构建的 ci 无法跳过.md
文件中的代码块,导致构建出错。
这个应该类似于 rust doc 里会尝试编译运行这些代码块吧?
可以加上 ignore
忽略这个代码块不编译、no_run
仅检查编译但是不运行之类的标记。ref
比如书里内容是演示编译报错或者展示部分代码块,就要加上 ignore
了。
这个要做起来,工作量还挺大的。
@sunface @EluvK 目前的问题是执行
mdbook test
命令构建的 ci 无法跳过.md
文件中的代码块,导致构建出错。这个应该类似于 rust doc 里会尝试编译运行这些代码块吧? 可以加上
ignore
忽略这个代码块不编译、no_run
仅检查编译但是不运行之类的标记。ref比如书里内容是演示编译报错或者展示部分代码块,就要加上
ignore
了。这个要做起来,工作量还挺大的。
是的,我昨天已经验证过了,需要代码块添加ignore,mdbook-runnable
,我的具体操作如下:
- 批量查找
src
目录下包含rust
,并替换为rust,ignore,mdbook-runnable
- 运行
mdbook test
命令,直到出现以下内容(个别代码块(运行结果)可能要添加console
)
:green_heart: 稍后我会发起一个 #1426