يسر فريق Rust أن يعلن عن إصدار نسخة جديدة ، 1.42.0. Rust هي لغة برمجة تتيح للجميع إنشاء برامج موثوقة وفعالة.
إذا قمت بتثبيت الإصدار السابق من Rust باستخدام أدوات rustup
، فعندئذٍ للترقية إلى الإصدار 1.42.0 ، ما عليك سوى تشغيل الأمر التالي:
rustup update stable
إذا لم تكن قد قمت بتثبيته بالفعل rustup
، يمكنك تثبيته من الصفحة المقابلة على موقعنا ، وكذلك الاطلاع على ملاحظات الإصدار التفصيلية على GitHub.
ما هو مدرج في الإصدار المستقر 1.42.0
الابتكارات الرئيسية لـ Rust 1.42.0 هي رسائل ذعر أكثر ملاءمة في حالة إجراء مكالمة unwrap
، قوالب شرائح ، إعلان عفا عليها الزمن Error::description
وأكثر من ذلك بكثير. انظر ملاحظات الإصدار لمزيد من المعلومات.
ذعر الرسائل من Option
و Result
تشمل الآن أرقام الأسطر مفيدة
في Rust 1.41.1 ، نتج عن استدعاء unwrap()
قيمة Option::None
رسالة خطأ مشابهة لما يلي:
thread 'main' panicked at 'called `Option::unwrap()` on a `None` value', /.../src/libcore/macros/mod.rs:15:40
وبالمثل، أرقام الأسطر في رسائل الذعر الناتجة عن المكالمات unwrap_err
، expect
و expect_err
، مثل الطرق المقابلة لنوع Result
، وأشار أيضا إلى الداخلية core
.
في Rust 1.42.0 ، تولد كل هذه الوظائف الثماني رسائل ذعر تتضمن أرقام الأسطر من حيث تم الاتصال بها. تبدو المشاركات الجديدة على النحو التالي:
thread 'main' panicked at 'called `Option::unwrap()` on a `None` value', src/main.rs:2:5
هذا يعني أن المكالمة الخاطئة unwrap
كانت في السطر 2 في الملف src/main.rs
.
#[track_caller]
. Rust, , .
Rust 1.26 " ", . :
fn foo(words: &[&str]) {
match words {
[] => println!("empty slice!"),
[one] => println!("one element: {:?}", one),
[one, two] => println!("two elements: {:?} {:?}", one, two),
_ => println!("I'm not sure how many elements!"),
}
}
, . , , .
Rust 1.42 :
fn foo(words: &[&str]) {
match words {
["Hello", "World", "!", ..] => println!("Hello World!"),
["Foo", "Bar", ..] => println!("Baz"),
rest => println!("{:?}", rest),
}
}
..
" " (rest pattern), . , :
fn foo(words: &[&str]) {
match words {
[.., "!"] => println!("!!!"),
[start @ .., "z"] => println!("starts with: {:?}", start),
["a", end @ ..] => println!("ends with: {:?}", end),
rest => println!("{:?}", rest),
}
}
, Inside Rust , ! .
, matches!
, , true
, . :
match self.partial_cmp(other) {
Some(Less) => true,
_ => false,
}
matches!(self.partial_cmp(other), Some(Less))
|
if
:
let foo = 'f';
assert!(matches!(foo, 'A'..='Z' | 'a'..='z'));
let bar = Some(4);
assert!(matches!(bar, Some(x) if x > 2));
use proc_macro::TokenStream;
Rust 2018 extern crate
. - , , , - extern crate proc_macro;
.
, Cargo, 2018, ; use
. , use proc_macro::TokenStream;
, , extern crate proc_macro;
. , .
API
Rust 1.42.0: Rust Cargo.
: 32- Apple 3.
Error::description
. Error::description
. :
fn description(&self) -> &str
description
&str
, , . Error
; , , , : String
. , Rust , Display
/Debug
, .
API Rust 1.0. : Rust 1.27, " ". , . , Error
. , , Error
. , description
, — , .
Apple 32- , . 3. , .
1.42.0
, Rust 1.42.0. , !
Rust - .
andreevlex, funkill, Hirrolot nlinker.