A5下载 - 努力做内容最丰富最安全的下载站!

A5站长下载站

当前位置:A5下载 > 源码动态 > Rust 1.65.0 稳定版发布,泛型关联类型 (GATs) 正式稳定

Rust 1.65.0 稳定版发布,泛型关联类型 (GATs) 正式稳定

时间:2022-11-09 09:49作者:qazwsxzxc人气:6489

 

Rust 1.65.0 稳定版已发布。此版本包含多项重要的语法变更,以及编辑器和标准库方面的改动。值得关注的是,Rust 1.65 现在还启用了 MIR 内联来优化编译,为 crate 提供了 3-10% 的编译时间改进。

 

语言特性

为枚举类型使用#[non_exhaustive]变体进行 as转换添加错误处理
let else正式稳定
let PATTERN: TYPE = EXPRESSION else {
DIVERGING_CODE;
};
泛型关联类型 (Generic Associated Types, GATs) 正式稳定
Lifetime、type 和 const 泛型现在可以在关联类型上进行定义,如下所示:

trait Foo {
type Bar<'x>;
}
下面是一些使用示例:

/// An `Iterator`-like trait that can borrow from `Self`
trait LendingIterator {
type Item<'a> where Self: 'a;

fn next<'a>(&'a mut self) -> Option<Self::Item<'a>>;
}

/// Can be implemented over smart pointers, like `Rc` or `Arc`,
/// in order to allow being generic over the pointer type
trait PointerFamily {
type Pointer<T>: Deref<Target = T>;

fn new<T>(value: T) -> Self::Pointer<T>;
}

/// Allows borrowing an array of items. Useful for
/// `NdArray`-like types that don't necessarily store
/// data contiguously.
trait BorrowArray<T> {
type Array<'x, const N: usize> where Self: 'x;

fn borrow_array<'a, const N: usize>(&'a self) -> Self::Array<'a, N>;
}
从 Clippy 添加 lintslet_underscore_drop,let_underscore_lock 和 let_underscore_must_use
未初始化的整数、浮点数和原始指针现在会被视作未定义行为 (immediate UB)
适用于 Windows x86_64, aarch64 和 thumbv7a 架构的 raw-dylib 正式稳定
不允许在外部 ADTs 中 Dropimpl

 

标签Rust,1.0,正式版,发布,Mozilla,编程语言,R

相关下载

查看所有评论+

网友评论

网友
您的评论需要经过审核才能显示

公众号