Skip to content

Commit c65475b

Browse files
committed
Rust 1.48 release post
1 parent 813b00d commit c65475b

File tree

1 file changed

+224
-0
lines changed

1 file changed

+224
-0
lines changed

posts/2020-11-19-Rust-1.48.md

Lines changed: 224 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,224 @@
1+
---
2+
layout: post
3+
title: "Announcing Rust 1.48.0"
4+
author: The Rust Release Team
5+
release: true
6+
---
7+
8+
The Rust team is happy to announce a new version of Rust, 1.48.0. Rust is a
9+
programming language that is empowering everyone to build reliable and
10+
efficient software.
11+
12+
If you have a previous version of Rust installed via rustup, getting Rust
13+
1.48.0 is as easy as:
14+
15+
```console
16+
rustup update stable
17+
```
18+
19+
If you don't have it already, you can [get `rustup`][install] from the
20+
appropriate page on our website, and check out the [detailed release notes for
21+
1.48.0][notes] on GitHub.
22+
23+
[install]: https://www.rust-lang.org/tools/install
24+
[notes]: https://github.com/rust-lang/rust/blob/master/RELEASES.md#version-1480-2020-11-19
25+
26+
## What's in 1.48.0 stable
27+
28+
The star of this release is Rustdoc, with a few changes to make writing
29+
documentation even easier! See the [detailed release notes][notes] to learn
30+
about other changes not covered by this post.
31+
32+
### Easier linking in rustdoc
33+
34+
Rustdoc, the library documentation tool included in the Rust distribution,
35+
lets you write documentation in Markdown. This makes it very easy to use, but
36+
also has some pain points. Let's say that you are writing some documentation
37+
for some Rust code that looks like this:
38+
39+
```rust
40+
pub mod foo {
41+
pub struct Foo;
42+
}
43+
44+
pub mod bar {
45+
pub struct Bar;
46+
}
47+
```
48+
49+
We have two modules, each with a struct inside. Imagine we wanted to use these
50+
two structs together; we may want to note this in the documentation. So we'd
51+
write some docs that look like this:
52+
53+
```rust
54+
pub mod foo {
55+
/// Some docs for `Foo`
56+
///
57+
/// You may want to use `Foo` with `Bar`.
58+
pub struct Foo;
59+
}
60+
61+
pub mod bar {
62+
/// Some docs for `Bar`
63+
///
64+
/// You may want to use `Bar` with `Foo`.
65+
pub struct Bar;
66+
}
67+
```
68+
69+
That's all well and good, but it would be really nice if we could link to these
70+
other types. That would make it much easier for the users of our library to
71+
navigate between them in our docs.
72+
73+
The problem here is that Markdown doesn't know anything about Rust, and the
74+
URLs that rustdoc generates. So what Rust programmers have had to do is write
75+
those links out manually:
76+
77+
```rust
78+
pub mod foo {
79+
/// Some docs for `Foo`
80+
///
81+
/// You may want to use `Foo` with [`Bar`].
82+
///
83+
/// [`Bar`]: ../bar/struct.Bar.html
84+
pub struct Foo;
85+
}
86+
87+
pub mod bar {
88+
/// Some docs for `Bar`
89+
///
90+
/// You may want to use `Bar` with [`Foo`].
91+
///
92+
/// [`Foo`]: ../foo/struct.Foo.html
93+
pub struct Bar;
94+
}
95+
```
96+
97+
Note that we've also had to use relative links, so that this works offline.
98+
Not only is this process tedious, and error prone, but it's also just wrong
99+
in places. If we put a `pub use bar::Bar` in our crate root, that would
100+
re-export `Bar` in our root. Now our links are wrong. But if we fix them,
101+
then they end up being wrong when we navigate to the `Bar` that lives inside
102+
the module. You can't actually write these links by hand, and have them all
103+
be accurate.
104+
105+
In this release, you can use some syntax to let rustdoc know that you're
106+
trying to link to a type, and it will generate the URLs for you. Here's
107+
two different examples, based off of our code before:
108+
109+
```rust
110+
pub mod foo {
111+
/// Some docs for `Foo`
112+
///
113+
/// You may want to use `Foo` with [Bar](crate::bar::Bar).
114+
pub struct Foo;
115+
}
116+
117+
pub mod bar {
118+
/// Some docs for `Bar`
119+
///
120+
/// You may want to use `Bar` with [`crate::foo::Foo`].
121+
pub struct Bar;
122+
}
123+
```
124+
125+
The first example will show the same text as before; but generate the proper
126+
link to the `Bar` type. The second will link to `Foo`, but will show the whole
127+
`crate::foo::Foo` as the link text.
128+
129+
There are a bunch of options you can use here. Please see the ["Linking to
130+
items by
131+
name"](https://doc.rust-lang.org/stable/rustdoc/linking-to-items-by-name.html)
132+
section of the rustdoc book for more.
133+
134+
### Adding search aliases
135+
136+
[You can now specify `#[doc(alias = "<alias>")]` on items to add search
137+
aliases when searching through `rustdoc`'s UI.][75740] This is a smaller change,
138+
but still useful. It looks like this:
139+
140+
```rust
141+
#[doc(alias = "bar")]
142+
struct Foo;
143+
```
144+
145+
With this annotation, if we search for "bar" in rustdoc's search, `Foo` will
146+
come up as part of the results, even though our search text doesn't have
147+
"Foo" in it.
148+
149+
[75740]: https://github.com/rust-lang/rust/pull/75740/
150+
151+
### Library changes
152+
153+
The most significant API change is kind of a mouthful: `[T; N]: TryFrom<Vec<T>>`
154+
is now stable. What does this mean? Well, you can use this to try and turn
155+
a vector into an array of a given length:
156+
157+
```rust
158+
use std::convert::TryInto;
159+
160+
let v1: Vec<u32> = vec![1, 2, 3];
161+
162+
// This will succeed; our vector has a length of three, we're trying to
163+
// make an array of length three.
164+
let a1: [u32; 3] = v1.try_into().expect("wrong length");
165+
166+
// But if we try to do it with a vector of length five...
167+
let v2: Vec<u32> = vec![1, 2, 3, 4, 5];
168+
169+
// ... this will panic, since we have the wrong length.
170+
let a2: [u32; 3] = v2.try_into().expect("wrong length");
171+
```
172+
173+
In the last release, we talked about the standard library being able to use
174+
const generics. This is a good example of the kinds of APIs that we can add
175+
with these sorts of features. Expect to hear more about the stabilization of
176+
const generics soon.
177+
178+
Additionally, five new APIs were stabilized this release:
179+
180+
- [`slice::as_ptr_range`]
181+
- [`slice::as_mut_ptr_range`]
182+
- [`VecDeque::make_contiguous`]
183+
- [`future::pending`]
184+
- [`future::ready`]
185+
186+
The following previously stable APIs have now been made `const`:
187+
188+
- [`Option::is_some`]
189+
- [`Option::is_none`]
190+
- [`Option::as_ref`]
191+
- [`Result::is_ok`]
192+
- [`Result::is_err`]
193+
- [`Result::as_ref`]
194+
- [`Ordering::reverse`]
195+
- [`Ordering::then`]
196+
197+
See the [detailed release notes][notes] for more.
198+
199+
[`Option::is_some`]: https://doc.rust-lang.org/std/option/enum.Option.html#method.is_some
200+
[`Option::is_none`]: https://doc.rust-lang.org/std/option/enum.Option.html#method.is_none
201+
[`Option::as_ref`]: https://doc.rust-lang.org/std/option/enum.Option.html#method.as_ref
202+
[`Result::is_ok`]: https://doc.rust-lang.org/std/result/enum.Result.html#method.is_ok
203+
[`Result::is_err`]: https://doc.rust-lang.org/std/result/enum.Result.html#method.is_err
204+
[`Result::as_ref`]: https://doc.rust-lang.org/std/result/enum.Result.html#method.as_ref
205+
[`Ordering::reverse`]: https://doc.rust-lang.org/std/cmp/enum.Ordering.html#method.reverse
206+
[`Ordering::then`]: https://doc.rust-lang.org/std/cmp/enum.Ordering.html#method.then
207+
[`slice::as_ptr_range`]: https://doc.rust-lang.org/std/primitive.slice.html#method.as_ptr_range
208+
[`slice::as_mut_ptr_range`]: https://doc.rust-lang.org/std/primitive.slice.html#method.as_mut_ptr_range
209+
[`VecDeque::make_contiguous`]: https://doc.rust-lang.org/std/collections/struct.VecDeque.html#method.make_contiguous
210+
[`future::pending`]: https://doc.rust-lang.org/std/future/fn.pending.html
211+
[`future::ready`]: https://doc.rust-lang.org/std/future/fn.ready.html
212+
213+
### Other changes
214+
215+
[relnotes-cargo]: https://github.com/rust-lang/cargo/blob/master/CHANGELOG.md#cargo-148-2020-11-19
216+
[relnotes-clippy]: https://github.com/rust-lang/rust-clippy/blob/master/CHANGELOG.md#rust-148
217+
218+
There are other changes in the Rust 1.48.0 release: check out what changed in
219+
[Rust][notes], [Cargo][relnotes-cargo], and [Clippy][relnotes-clippy].
220+
221+
## Contributors to 1.48.0
222+
223+
Many people came together to create Rust 1.48.0. We couldn't have done it
224+
without all of you. [Thanks!](https://thanks.rust-lang.org/rust/1.48.0/)

0 commit comments

Comments
 (0)