Rust 1.82 tso tawm. Tshiab browser raws li Rust. Siv Rust hauv Volvo

Kev tso tawm ntawm Rust 1.82 cov lus qhia dav dav, tsim los ntawm Mozilla qhov project, tab sis tam sim no tsim los ntawm kev txhawb nqa ntawm lub koom haum ywj pheej tsis muaj txiaj ntsig Rust Foundation, tau tshaj tawm. Cov lus qhia txog kev nyab xeeb ntawm kev nco thiab muab txoj hauv kev kom ua tiav txoj haujlwm siab sib luag thaum tsis txhob siv cov khoom siv khib nyiab thiab lub sijhawm ua haujlwm (runtime raug txo qis rau kev pib pib thiab kev saib xyuas ntawm lub tsev qiv ntawv txheem).

Rust lub cim xeeb tuav txoj kev cawm tus tsim tawm los ntawm kev ua yuam kev thaum tswj cov taw qhia thiab tiv thaiv cov teeb meem uas tshwm sim los ntawm kev ua haujlwm qis qis, xws li nkag mus rau thaj chaw nco tom qab nws tau tso tawm, dereferencing null pointers, tsis overruns, thiab lwm yam. Txhawm rau faib cov tsev qiv ntawv, muab kev tsim kho thiab tswj hwm kev vam khom, qhov project tsim tus thawj tswj hwm pob khoom. Lub crates.io repository yog txaus siab rau hosting cov tsev qiv ntawv.

Kev nyab xeeb nco yog muab rau hauv Rust ntawm lub sijhawm sau los ntawm kev siv tshuaj xyuas, ua raws li cov tswv cuab ntawm cov khoom, khaws cov khoom siv lub neej (scopes), thiab ntsuas qhov tseeb ntawm kev nkag mus rau lub cim xeeb thaum lub sijhawm ua tiav cov lej. Rust kuj tseem muab kev tiv thaiv tus lej ntau dhau, yuav tsum muaj qhov sib txawv kom pib ua ntej siv, ua haujlwm yuam kev zoo dua hauv cov tsev qiv ntawv tus qauv, siv lub tswv yim ntawm cov ntaub ntawv tsis hloov pauv thiab hloov pauv los ntawm lub neej ntawd, thiab muaj kev ntaus ntawv zoo li qub kom txo qis qhov yuam kev.

Main innovations:

  • Cov lus txib "info" tau ntxiv rau tus thawj tswj hwm pob khoom thauj khoom los tso saib cov ntaub ntawv hais txog pob hauv qhov chaw cia khoom.
  • Ntxiv kev txhawb nqa rau "siv <..>" syntax hauv "impl Trait", uas qhia txog cov ntaub ntawv hais txog hom zais. Piv txwv li, "impl Trait + use<'x, T>" qhia tias tsuas yog cov tsis "x" thiab "T" raug tso cai siv rau hauv hom zais.
  • Ib qho kev sib cais rau kev tsim cov ntsiab lus nyoos tau raug npaj, hloov cov macros yav dhau los: "addr_of!(expr)" macro tau hloov los ntawm "&raw const expr" tus neeg teb xov tooj, thiab "addr_of_mut!(expr)" macro tau hloov los ntawm "&raw mut" tus neeg teb xov tooj expr". struct Packed { not_aligned_field: i32, } fn main() { let p = Packed { not_aligned_field: 1_82 }; // Txoj kev qub los tsim tus taw tes rawv cia ptr = std::ptr::addr_of!(p.not_aligned_field); // Txoj kev tshiab los tsim tus taw tes rawg cia ptr = &raw const p.not_aligned_field; cia val = unsafe { ptr.read_unaligned() }; }
  • Nws muaj peev xwm los txhais cov haujlwm muaj kev nyab xeeb thiab qhov tsis tu ncua nrog 'zoo li qub' lub neej nyob rau hauv extern blocks nrog "tsis zoo" tus cwj pwm (yav dhau los, tag nrho cov ntsiab lus hauv "tsis muaj kev nyab xeeb" tsuas yog muaj tus cwj pwm "tsis zoo"): tsis zoo extern { pub nyab xeeb static TAU: f64; pub safe fn sqrt(x:f64) -> f64; pub unsafe fn strlen(p: *const u8) -> usize; }
  • Cov no_mangle, link_section thiab export_name tus cwj pwm, uas tuaj yeem ua rau tus cwj pwm tsis zoo, tam sim no suav tias tsis muaj kev nyab xeeb thiab xav tau tus chij "tsis zoo", piv txwv li: #[unsafe(no_mangle)] pub fn my_global_function() { }
  • Cov qauv sib txuam tso cai rau hom khoob kom hla, xws li "enum Void {}" lossis cov qauv uas pom qhov khoob khoob. siv std::hloov::Infallible; pub fn unwrap_without_panic (x: Kev ) -> T { let Ok(x) = x; // "Err" tuaj yeem hla x }
  • Cov hom rau cov lej taw tes ntab (f32 thiab f64) muaj tus cwj pwm coj ua thaum ua cov lej tsis yog NaN qhov tseem ceeb (0.0/0.0), thiab tseem tso cai rau kev siv cov haujlwm ntab ntab hauv const fn.
  • Kev sib sau ua ke muab lub peev xwm los siv cov operands nrog "const" tus cwj pwm kom ncaj qha siv cov lej lej tsis tau ua ntej khaws cia rau hauv ib lub npe. const MSG: &str = "Nyob zoo, ntiaj teb!\n"; unsafe { core::arch::asm!( “mov rdx, {LEN} // the instruction 'mov rdx, 14′” will be generated, LEN = const MSG.len(), … ); }
  • Hais txog cov lus hais nrog "zoo li qub" tus cwj pwm raug tso cai nyob rau hauv cov ntsiab lus muaj kev nyab xeeb yam tsis tau txhais qhov tsis muaj kev nyab xeeb (tus "&raw mut" thiab "&raw const" tus neeg teb xov tooj tsis cuam tshuam rau tus nqi ntawm tus operand thiab tsuas yog tsim tus taw tes rau nws): static mut STATIC_MUT: Type = Type::new( ); extern "C" { zoo li qub EXTERN_STATIC: Hom; } fn main() { let static_mut_ptr = &raw mut STATIC_MUT; cia extern_static_ptr = &raw const EXTERN_STATIC; }
  • Ib feem tshiab ntawm API tau raug hloov mus rau qeb ntawm qhov ruaj khov, suav nrog cov txheej txheem thiab kev siv ntawm cov yam ntxwv tau ruaj khov:
    • std::xov::Builder::spawn_unchecked
    • std::str::CharIndices::offset
    • std::option::Option::is_none_or
    • [T]::is_sorted
    • [T]::is_sorted_by
    • [T]::is_sorted_by_key
    • Iterator::is_sorted
    • Iterator::is_sorted_by
    • Iterator::is_sorted_by_key
    • std::future::Ready::into_inner
    • std::iter::repeat_n
    • impl DoubleEndedIterator rau Take

      Tau qhov twg los: opennet.ru

Ntxiv ib saib