软件资讯
IntelliJ IDEA 2023.1 最新变化
IntelliJ IDEA 新 UI 速览
PicList V1.6.1 发布 云存储 - 图床管理和图片上传工具 bug 修复
Calibre 6.15 发布,功能强大的开源电子书工具
Netty 4.1.91.Final 发布
Electron 24.0 正式发布
FerretDB 1.0 正式 GA,MongoDB 开源替代品
fastjson 2.0.28 发布
Apache Dubbo 3.2.0 发布,Dubbo 3 的全新版本
Jvmm是一个同时支持操作系统监控和Java虚拟机监控的工具
Rust 1.69.0 稳定版已发布
Glarity - Summary for Google/YouTube with ChatGPT
MrDoc 0.8.9 发布,类似语雀、飞书的开源在线文档和知识库系统
Layui 2.8.0 正式发布,朴实归来
Easy Retry 发布第一个 1.0.0
全网最美的Mysql客户端软件,使用教程
Motrix 时隔 2 年发布新版本,多功能开源跨平台下载工具
Quarkus 3.0 Final 发布,基于 Jakarta EE 10
一款开源免费的SSH/SFTP客户端Electerm
翻译工具 “沉浸式翻译” 已被收购
数据库管理工具
使用MYSQL作为MEMOS的数据库
RetroArch 1.17 发布,游戏模拟器
微软计划 3 月底发布首款 AI PC
Java Native-OpenJ9-HotSpot (solon) 与 Go (gin) 对比测试
🔥🔥🔥 EasyRetry 3.1.0 发布,Spring Boot3.x时代已经开启🎉🎉
SmartInput插件使用说明之Intellij产品、Windows系统
Linux Mint 22 “Wilma” 正式发布
Rust 1.80.0 发布
SqlBean 1.6.1 发布,Mybatis 自动建表、维护表结构
本文档使用 MrDoc 发布
-
+
Rust 1.80.0 发布
[如何从自建开源 Prometheus 迁移到阿里云托管 Prometheus 服务](https://click.aliyun.com/m/1000395910/) Rust 1.80.0 稳定版现已发布,主要带来以下变化: #### **`LazyCell`和`LazyLock`** 新的“lazy”类型将值的初始化延迟到首次访问,它们类似于[1.70 中稳定的](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fblog.rust-lang.org%2F2023%2F06%2F01%2FRust-1.70.0.html%23oncecell-and-oncelock)`OnceCell`和`OnceLock`类型,但单元格中包含了初始化函数。这完成了从流行的和板条箱中采用到标准库中的功能的稳定化。完成了从[`lazy_static`](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fcrates.io%2Fcrates%2Flazy-static)和[`once_cell`](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fcrates.io%2Fcrates%2Fonce_cell)crates 到标准库中所采用功能的稳定化。 LazyLock 是线程安全选项,适用于`static` values 等地方。 ```rust use std::sync::LazyLock; use std::time::Instant; static LAZY_TIME: LazyLock<Instant> = LazyLock::new(Instant::now); fn main() { let start = Instant::now(); std::thread::scope(|s| { s.spawn(|| { println!("Thread lazy time is {:?}", LAZY_TIME.duration_since(start)); }); println!("Main lazy time is {:?}", LAZY_TIME.duration_since(start)); }); } ``` LazyCell 缺乏线程同步,因此没有实现`static`所需的 Sync,但仍可用于`thread_local!` statics。Rust团队表示,根据线程安全的需要,这两种类型也可用于其他数据结构,因此 lazy initialization 在任何地方都可用。 #### **Checked `cfg` names and values** 在 1.79 中,`rustc`稳定了一个[`--check-cfg`flag](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdoc.rust-lang.org%2Frustc%2Fcheck-cfg.html),现在 Cargo 1.80 正在对其知道的所有`cfg`名称和值启用这些检查(除了来自`rustc`的[众所周知的名称和值](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdoc.rust-lang.org%2Frustc%2Fcheck-cfg.html%23well-known-names-and-values))。包括来自`Cargo.toml`的功能名称以及来自构建脚本的新`cargo::rustc-check-cfg`output。 `unexpected_cfgs`会被 warning-by-default unexpected\_cfgs lint 报告,用于捕获拼写错误或其他错误配置。例如,在具有可选`rayon`依赖项的项目中,此代码配置了错误的`feature`值: ```rust fn main() { println!("Hello, world!"); #[cfg(feature = "crayon")] rayon::join( || println!("Hello, Thing One!"), || println!("Hello, Thing Two!"), ); } ``` ```console warning: unexpected `cfg` condition value: `crayon` --> src/main.rs:4:11 | 4 | #[cfg(feature = "crayon")] | ^^^^^^^^^^-------- | | | help: there is a expected value with a similar name: `"rayon"` | = note: expected values for `feature` are: `rayon` = help: consider adding `crayon` as a feature in `Cargo.toml` = note: see <https://doc.rust-lang.org/nightly/rustc/check-cfg/cargo-specifics.html> for more information about checking conditional configuration = note: `#[warn(unexpected_cfgs)]` on by default ``` 无论实际的`rayon`功能是否启用,都会报告相同的警告。 还可以使用`Cargo.toml`清单中的`[lints]`表来扩展自定义`cfg`的已知名称和值列表。`rustc`会自动提供警告中使用的[语法。](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fdoc.rust-lang.org%2Frustc%2Fcheck-cfg.html%23specifying-expected-names-and-values) ```toml [lints.rust] unexpected_cfgs = { level = "warn", check-cfg = ['cfg(foo, values("bar"))'] } ``` 可以在[之前的博客文章](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fblog.rust-lang.org%2F2024%2F05%2F06%2Fcheck-cfg.html)中阅读有关此功能的更多信息。 #### **Exclusive ranges in patterns** Rust ranged 模式现在可以使用 exclusive endpoints,写成`a..b`或`..b`,类似于`Range` 和 `RangeTo`表达式类型。例如,以下模式现在可以在一个模式的终点和下一个模式的起点使用相同的常量: ```rust pub fn size_prefix(n: u32) -> &'static str { const K: u32 = 10u32.pow(3); const M: u32 = 10u32.pow(6); const G: u32 = 10u32.pow(9); match n { ..K => "", K..M => "k", M..G => "M", G.. => "G", } } ``` Exclusive ranges 一直以来作为一个不稳定的功能提供。Rust 团队表示,阻碍因素在于它们可能会增加混乱并增加模式中出现 off-by-one errors 的可能性。在 Rust 1.80 中,exhaustiveness checking 得到了增强,可以更好地检测模式匹配中的差距,新的 lint`non_contiguous_range_endpoints`和`overlapping_range_endpoints`将有助于检测在哪些情况下需要将 exclusive 模式切换为 inclusive 模式,反之亦然。 Rust 1.80 还稳定了许多 API,详情可[查看官方公告](https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fblog.rust-lang.org%2F2024%2F07%2F25%2FRust-1.80.0.html)。
admin
2024年7月28日 07:41
转发文档
收藏文档
上一篇
下一篇
手机扫码
复制链接
手机扫一扫转发分享
复制链接
Markdown文件
PDF文档(打印)
分享
链接
类型
密码
更新密码