内容简介:Rust 1.57.0 现已发布,该版本为 const contexts 带来了 panic!,为 Cargo 增加了对自定义配置文件的支持,并稳定了易出错的 reservation API。如果你此前已通过 rustup 安装了以前的 Rust 版本,运行以下命令即可...
Rust 1.57.0 现已发布,该版本为 const contexts 带来了 panic!,为 Cargo 增加了对自定义配置文件的支持,并稳定了易出错的 reservation API。如果你此前已通过 rustup 安装了以前的 Rust 版本,运行以下命令即可升级至最新版本:
rustup update stable
具体更新内容包括:
panic! in const contexts
在以前的 Rust 版本中,panic!macro 在 const fn 和其他 compile-time contexts 中是不能使用的。现在,这一点已经稳定下来了。连同panic!的稳定,其他几个标准库的 API 现在也可以在 const 中使用,比如assert!。
这种稳定性还不包括完整的格式化基础结构,因此必须使用静态字符串 (panic!("..."))或者用单个&str内插值 (panic!("{}", a)) 来调用panic!macro 宏。
预计将来这种支持会扩展,但这种最低限度的稳定性已经支持直接的编译时断言,例如验证类型的大小:
const _: () = assert!(std::mem::size_of::<u64>() == 8);
const _: () = assert!(std::mem::size_of::<u8>() == 1);
Cargo support for custom profiles
Cargo 长期以来一直支持四种配置文件:dev、release、test和bench。在 Rust 1.57 中,增加了对任意命名的配置文件的支持。
例如,如果你想只在最终生产构建时启用链接时间优化(LTO),那么在 Cargo.toml 中添加以下片段,在选择此配置文件时启用 lto flag,但避免在常规发布构建时启用它。
[profile.production]
inherits = "release"
lto = true
Fallible allocation
Rust 1.57 为Vec、String、HashMap、HashSet和VecDeque稳定了try_reserve。此 API 使调用者能够错误地为这些类型分配 backing storage。
如果全局分配器失败,Rust 通常会中止进程,这并不总是可取的。此 API 提供了一种在使用标准库集合时避免中止的方法。但是,Rust 不保证返回的内存实际上是由内核分配的:例如,如果在 Linux 上启用了 overcommit,则在尝试使用内存时可能无法使用该内存。
稳定的 API
以下方法和特性的实现被稳定化:
[T; N]::as_mut_slice[T; N]::as_slicecollections::TryReserveErrorHashMap::try_reserveHashSet::try_reserveString::try_reserveString::try_reserve_exactVec::try_reserveVec::try_reserve_exactVecDeque::try_reserveVecDeque::try_reserve_exactIterator::map_whileiter::MapWhileproc_macro::is_availableCommand::get_programCommand::get_argsCommand::get_envsCommand::get_current_dirCommandArgsCommandEnvs
以下以前稳定的功能现在是const。
更多详情可查看官方博客。
以上所述就是小编给大家介绍的《Rust 1.57.0 发布》,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对 码农网 的支持!
本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
PHP for the World Wide Web, Second Edition (Visual QuickStart Gu
Larry Ullman / Peachpit Press / 2004-02-02 / USD 29.99
So you know HTML, even JavaScript, but the idea of learning an actual programming language like PHP terrifies you? Well, stop quaking and get going with this easy task-based guide! Aimed at beginning ......一起来看看 《PHP for the World Wide Web, Second Edition (Visual QuickStart Gu》 这本书的介绍吧!
