10月にリリースされるRust言語の第3版であるRust2021を発表できることを嬉しく思います。Rust 2021には、Rustの使いやすさを大幅に向上させるいくつかの小さな変更が含まれています。
編集委員会とは何ですか?
Rust 1.0リリースでは、Rustの基本ルールとして「停滞のない安定性」が確立されました。1.0リリース以降、安定バージョンで機能をリリースすることにより、将来のすべてのリリースでその機能をサポートすることを約束するというルールがあります。
ただし、下位互換性がない場合でも、言語に小さな変更を加える機能が役立つ場合があります。最も明白な例は、同じ名前の変数を無効にする新しいキーワードの導入です。たとえば、Rustの最初のバージョンでは、キーワードasync
とはありませんでしたawait
。これらの単語を新しいバージョンのキーワードに突然変更すると、たとえば、コードがlet async = 1;
機能しなくなります。
リビジョンは、この問題に対処するために使用するメカニズムです。下位互換性のない機能をリリースしたい場合は、新しいRustエディションの一部にします。リビジョンはオプションであり、明示的に記述する必要があるため、既存のパッケージは、新しいバージョンに明示的にアップグレードするまで、これらの変更を確認できません。つまり、2018年以降が選択されない限り、最新バージョンのRustでもキーワードとは見なされませんasync
。この選択は、パッケージごとに 行われます Cargo.toml
。作成された新しいパッケージcargo new
は、常に最新の安定版リリースを使用するように設定されています。
エディトリアルはエコシステムを共有しません
: . , .
, . , , "". Rust, , .
— . , . , . , Rust 2018 , async
, : r#async
.
: . , .
, . , , . , , . , , , .
Rust 2021?
Rust 2021 , . . , . -, () Rust. -, , , .
— , , . , Option
, Vec
, drop
Clone
.
Rust , , . , - . , example
, pub struct Option;
, use example::*;
Option
example
.
. x.try_into()
MyTryInto
, TryInto
std
, . TryInto
— .
Rust 2021 . , :
Cargo
Rust 1.51.0, Cargo resolver = "2"
Cargo.toml
.
Rust 2021 . edition = "2021"
Cargo.toml
resolver = "2"
.
, . Rust 1.51.
IntoIterator
Rust 1.53 IntoIterator
. , &[1, 2, 3]
&mut [1, 2, 3]
, [1, 2, 3]
.
for &e in &[1, 2, 3] {} // Ok :)
for e in [1, 2, 3] {} // :(
, , . . array.into_iter()
, (&array).into_iter()
- . .
( ) "" . .
" IntoIterator
Rust 2021". : , .
, Rust 1.53.0. , Rust 2021. Rust 2015 2018 - array.into_iter()
(&array).into_iter()
, . .into_iter()
, for e in [1, 2, 3]
, iter.zip([1, 2, 3])
. .
, , , . , .
, . , || a.x + 1
a
a.x
. . () , , , .
let a = SomeStruct::new();
drop(a.x); //
println!("{}", a.y); // :
let c = || println!("{}", a.y); // : `a`
c();
Rust 2021, , . Rust 2021.
, , . — . , . let _ = &a;
, , .
panic!()
— Rust. , — - .
panic!("{}", 1); // , "1"
panic!("{}"); // , "{}"
panic!()
, . .
let a = "{";
println!(a); // :
panic!(a); // : panic
( , panic!(123)
, , , ).
. println!("hello {name}")
println!("hello {}", name)
. panic!("hello {name}")
, panic!()
.
, Rust 2021 — panic!()
. panic!()
. — println!()
— . panic!()
, panic_any()
- .
, core::panic!()
std::panic!()
Rust 2021. , #![no_std]
.
, : prefix#identifier
, prefix"string"
, prefix'c'
prefix#123
, prefix
( , — , b'...'
r"..."
).
, hello"world"
, : hello
"world"
. () — : hello "world"
.
, RFC . , — — .
, :
f""
. ,f"hello {name}"
format_args!()
.c""
z""
- .k#keyword
, , . ,async
2015,k#async
2015, 2018,async
.
Rust 2021. .
"" macro_rules
Rust 1.53.0 |
, . Some(1 | 2)
Some(1) | Some(2)
. , .
macro_rules
. :pat
. :pat
|
, Rust 1.53 ( ) |
. , A | B
, matches!()
, - $($_:pat)|+
. , , :pat
Rust 1.53.0, |
.
Rust 2021. :pat
A | B
, - |
, :pat_param
. : .
?
, , 2021 Rust 1.56.0. Rust 1.56.0 - , 21 .
, Rust — , . , Rust, , . , , , .
, , . , Rust 2021!
. , .
, Nightly, -Zunstable-options --edition=2021
.
Rust - . , .
OpenCollective.
fan-tom, blandger, Belanchuk, TelegaOvoshey andreevlex.