Rust 1.40.0 发布
Rust 1.40.0已经正式发布。该版本的亮点包括有#[non_exhaustive]和macros!()and#[attribute]s的改进。 具体更新内容如下: #[non_exhaustive]结构,枚举和变体 当属性#[non_exhaustive]附加到struct或的变体时enum,它将防止定义它的板条箱外部的代码构造所述struct或变体。为了避免将来损坏,还防止其他包装箱在田地上进行彻底匹配。以下示例说明了beta取决于的错误alpha: // alpha/lib.rs: #[non_exhaustive] struct Foo { pub a: bool, } enum Bar { #[non_exhaustive] Variant { b: u8 } } fn make_foo() -> Foo { ... } fn make_bar() -> Bar { ... } // beta/lib.rs: let x = Foo { a: true }; //~ ERROR let Foo { a } = ...