内容简介:Rust 1.58.0 现已发布,该版本带来了在格式字符串中捕获的标识符、改变了 Windows 上的 Command 搜索路径,在标准库中增加了 #[must_use] 注释,以及一些新的库稳定性。如果你此前已通过 rustup 安装了以前的 Ru...
Rust 1.58.0 现已发布,该版本带来了在格式字符串中捕获的标识符、改变了 Windows 上的 Command 搜索路径,在标准库中增加了 #[must_use] 注释,以及一些新的库稳定性。如果你此前已通过 rustup 安装了以前的 Rust 版本,运行以下命令即可升级至最新版本:
rustup update stable
具体更新内容包括:
格式字符串中捕获的标识符
格式字符串现在可以通过在字符串中写入 {ident} 来捕获参数。格式长期以来接受位置参数(可选地通过索引)和命名参数,例如:
println!("Hello, {}!", get_person()); // implicit position
println!("Hello, {0}!", get_person()); // explicit index
println!("Hello, {person}!", person = get_person()); // named
现在命名参数也可以从周围的范围中捕获,例如:
let person = get_person();
// ...
println!("Hello, {person}!"); // captures the local `person`
这也可以用于格式化参数:
let (width, precision) = get_format();
for (name, score) in get_scores() {
println!("{name}: {score:width$.precision$}");
}
格式字符串只能捕获普通标识符,不能捕获任意路径或表达式。对于更复杂的参数,要么先将它们分配给本地名称,要么使用旧name = expression样式的格式化参数。
减少 WindowsCommand搜索路径
在 Windows targets 上,std::process::Command 将不再搜索当前目录中的可执行文件。Rust 现在在没有当前目录的情况下执行自己的搜索,并且不包括旧的 16 位目录,因为没有 API 来发现它的位置。所以 Windows 上 Rust 的新Command搜索顺序是:
PATH子环境变量中列出的目录。- 加载应用程序的目录。
- 32 位 Windows 系统目录。
- Windows 目录。
PATH环境变量中列出的目录。
Non-Windows targets 继续使用其特定于平台的行为,通常只考虑子或父PATH环境变量。
标准库中更多的#[must_use]
Library proposal 35 在 2021 年 10 月被批准,以审核和扩大 #[must_use] 在整个标准库中的应用,涵盖更多以返回值为主要作用的 functions。这类似于 function purity 的想法,但比真正的语言特性要宽松。其中一些新增功能在 1.57.0 版本中出现过,现在在 1.58.0 版本中已完成。
稳定的 API
以下方法和特性的实现被稳定化:
Metadata::is_symlinkPath::is_symlink{integer}::saturating_divOption::unwrap_uncheckedResult::unwrap_uncheckedResult::unwrap_err_uncheckedFile::options
以下以前稳定的功能现在是const。
Duration::newDuration::checked_addDuration::saturating_addDuration::checked_subDuration::saturating_subDuration::checked_mulDuration::saturating_mulDuration::checked_div
更多详情可查看官方博客。
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网
猜你喜欢:- NPM包(模块)发布、更新、撤销发布
- 有赞灰度发布与蓝绿发布实践
- 【重磅发布】Linkis 0.10.0 版本发布
- BeetlSQL 3.0.9 发布,Idea 插件发布
- 贝密游戏 0.7.0 发布,发布斗地主
- 【重磅发布】DataSphere Studio 0.9.0 版本发布
本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
Practical Django Projects, Second Edition
James Bennett / Apress / 2009 / 44.99
Build a django content management system, blog, and social networking site with James Bennett as he introduces version 1.1 of the popular Django framework. You’ll work through the development of ea......一起来看看 《Practical Django Projects, Second Edition》 这本书的介绍吧!