Rust 1.48.0 发布

Rust 1.48.0 版本现已发布,此版本最大的变化是对文档系统的改进。具体更新内容如下:

Easier linking in rustdoc

Rustdoc 是 Rust 发行版中包含的库文档工具,可以让你用 Markdown 编写文档。在 1.48.0 版本中,Rustdoc 能够使用 item 路径作为链接直接链接到 Markdown 文档中的其他 rustdoc 页面。例如,/// Uses [`std::future`]将自动生成指向std::future的文档的链接。

在下面示例的代码中,所有的链接都会链接到 Bar 的 rustdoc 页面:

#![allow(unused)] 
fn main() { 
/// This struct is not [Bar] 
pub struct Foo1;

/// This struct is also not [bar](Bar)
pub struct Foo2;

/// This struct is also not [bar][b]
///
/// [b]: Bar
pub struct Foo3;

/// This struct is also not [`Bar`]
pub struct Foo4;

pub struct Bar; 
}

更多信息可查看“Linking to items by name”。

添加 search aliases

现在用户可以在项目上指定 #[doc(alias = "<alias>")],以便在通过 rustdoc 的用户界面搜索时添加 search aliases。如下所示:

#[doc(alias = "bar")]
struct Foo;

有了这个注释,即使搜索文本中没有 "Foo",但如果用户在 rustdoc 的搜索中搜索 "bar",Foo 也会作为结果的一部分出现。

别名的一个有趣的用例是 FFI wrapper crates,每个 Rust 函数都可以被别名为它所包装的 C 函数。这样,底层 C 库的现有用户就能轻松地搜索到正确的 Rust 函数。

Library changes

[T; N]: TryFrom<Vec<T>> 已经 stable。这意味着用户现在可以用它来尝试将一个向量变成一个给定长度的数组。

use std::convert::TryInto;

let v1: Vec<u32> = vec![1, 2, 3];

// This will succeed; our vector has a length of three, we're trying to
// make an array of length three.
let a1: [u32; 3] = v1.try_into().expect("wrong length");

// But if we try to do it with a vector of length five...
let v2: Vec<u32> = vec![1, 2, 3, 4, 5];

// ... this will panic, since we have the wrong length.
let a2: [u32; 3] = v2.try_into().expect("wrong length");

1.47 版本中曾提到了能够使用 const 泛型的标准库。Rust 方面表示,这是他们可以通过这些功能添加的各种 API 的一个很好的例子,期待很快就能听到更多关于 const 泛型稳定的消息。

此外,此版本还稳定了五个新的 API:

以下之前稳定的 API 现在已经const

有关更多信息,请参见详细的发行说明

猜你喜欢

转载自www.oschina.net/news/121221/rust-1-48-0-released