الصدأ 1.45.0: تثبيت وحدات الماكرو الإجرائية الوظيفية وإصلاحات عيوب التحويل

يسر فريق Rust الإعلان عن إصدار الإصدار الجديد 1.45.0. Rust هي لغة برمجة تسمح لأي شخص بإنشاء برامج موثوقة وفعالة.



إذا قمت بتثبيت إصدار سابق من Rust باستخدام الأدوات rustup، فعندئذٍ للترقية إلى الإصدار 1.45.0 ، تحتاج فقط إلى تشغيل الأمر التالي:



rustup update stable


إذا لم يكن لديك بالفعل rustup، فيمكنك تثبيته من الصفحة المناسبة على موقعنا الإلكتروني وإلقاء نظرة عليه أيضًا على GitHub .



ما هو مدرج في الإصدار الثابت 1.45.0



يحتوي هذا الإصدار على تغييرين كبيرين: إصلاح العيوب القديمة في التحويل بين الأعداد الصحيحة وأرقام الفاصلة العائمة ، وتثبيت الميزات الضرورية لإطار عمل ويب واحد على الأقل للعمل على Rust المستقر.



تصحيح عيوب التحولات



في البداية تم فتح الإصدار 10184 في أكتوبر 2013 ، لمدة عام ونصف قبل الإصدار Rust 1.0. نظرًا لأنه rustcيستخدم LLVM كمترجم خلفي خاص به ، عند كتابة كود مثل هذا:



pub fn cast(x: f32) -> u8 {
    x as u8
}


قام مترجم Rust في الإصدارات 1.44.0 وما قبلها بإنشاء LLVM-IR التالي:



define i8 @_ZN10playground4cast17h1bdf307357423fcfE(float %x) unnamed_addr #0 {
start:
  %0 = fptoui float %x to i8
  ret i8 %0
}


fptoui "floating point to unsigned integer".



, :



‘fptoui’ ( ) . ty2, .

The ‘fptoui’ instruction converts its floating-point operand into the nearest (rounding towards zero) unsigned integer value. If the value cannot fit in ty2, the result is a poison value.


, , . , : , .



, , :



fn cast(x: f32) -> u8 {
    x as u8
}

fn main() {
    let f = 300.0;

    let x = cast(f);

    println!("x: {}", x);
}


Rust 1.44.0 "x: 0", .. , . «» ( unsafe ) — , . I-unsound, .



. , , .



:



  • as " " (saturating cast),
  • unsafe , .


, :



  • array[i] , , array i + 1 ,
  • unsafe { array.get_unchecked(i) }, .


, ? :



fn cast(x: f32) -> u8 {
    x as u8
}

fn main() {
    let too_big = 300.0;
    let too_small = -100.0;
    let nan = f32::NAN;

    println!("too_big_casted = {}", cast(too_big));
    println!("too_small_casted = {}", cast(too_small));
    println!("not_a_number_casted = {}", cast(nan));
}


:



too_big_casted = 255
too_small_casted = 0
not_a_number_casted = 0


. ( ). NaN .



API :



let x: f32 = 1.0;
let y: u8 = unsafe { x.to_int_unchecked() };


, , . , , , .



,



Rust 1.30.0 « ». , gnome-class:



Gnome- — Rust. Rust- -, , GObject, , , GObject. , .

:



gobject_gen! {
    class MyClass: GObject {
        foo: Cell<i32>,
        bar: RefCell<String>,
    }

    impl MyClass {
        virtual fn my_virtual_method(&self, x: i32) {
            ... do something with x ...
        }
    }
}


" " — , , gobject_gen! .



Rust 1.45.0 :



// ,      "mac"

mac!(); //  , ,    

//    3 :
fn main() {
  let expr = mac!(); //  

  match expr {
      mac!() => {} //  
  }

  mac!(); //  
}


, , : Rocket. - Rocket, 2016 , , Rust. ", " :



#[macro_use] extern crate rocket;

#[get("/<name>/<age>")]
fn hello(name: String, age: u8) -> String {
    format!("Hello, {} year old named {}!", age, name)
}

#[launch]
fn rocket() -> rocket::Rocket {
    rocket::ignite().mount("/hello", routes![hello])
}


Rocket . , , Rocket proc_macro_hygiene . , , ! Rocket. !



Rocket , , :)





Rust 1.45.0 :





char :



for ch in 'a'..='z' {
    print!("{}", ch);
}
println!();
//  "abcdefghijklmnopqrstuvwxyz"


.





, Cargo Clippy .



1.45.0



, Rust 1.45.0. , !





Rust - . , .



nlinker, funkill, Hirrolot blandger.




All Articles