Rust 1.75改進特徵語言功能,簡化非同步程式設計
· 2024-01-05

Rust 1.75在特徵(Traits)中新增支援async fn與-> impl Trait,提升編寫非同步程式碼效率和泛型程式 設計靈活性

Rust團隊發布Rust新版本1.75,這個版本其中一個重要更新是在特徵(Traits)中支援使用async fn與-> impl Trait,不過,這項更新目前仍是初始版本,還存在一些限制。另外,開發團隊也持續更新編譯器,強化應用程式的效能。

Rust非同步工作組持續朝向在特徵中支援async fn的目標前進,而在Rust 1.75有了重大進展,包括在特徵中支援-> impl Trait表示法以及async fn。特徵在Rust中是一個核心語言功能,主要用於定義和共享行為,其功能類似其他語言的介面,但具有更多的功能和靈活性。

允許在特徵中使用非同步函式async fn的意義,代表著改善非同步程式碼的組織和可讀性,過去開發者要在特徵中定義非同步函式,需要採用間接迂迴的方法,這通常導致程式碼過於冗長和複雜,而透過在特徵中支援async fn,開發者可以直接定義非同步函式,使程式碼更加直覺易於理解和維護。

此外,透過使用回傳位置的impl Trait,開發者可以在特徵中定義回傳特定特徵型別的方法,這不僅提升了泛型程式設計的靈活性,還使得程式設計更具抽象性,有助於開發者編寫更加模組化的程式碼,簡化非同步操作管理。

簡單來說,Rust在特徵中支援async fn和回傳位置的-> impl Trait,主要目的是要提高非同步函式的支援,增加泛型程式設計的靈活性,解決之前直接在特徵定義中直接使用async fn,所出現的限制和警告問題。

這些改進讓開發者可以更有效地使用多執行緒和工作竊取執行器(Work-Stealing Executor),而Rust計畫未來還要進一步擴展其多態性和靈活性,透過提供工具支援動態分派(Dynamic Dispatch)。

Rust編譯器也在Rust 1.75獲得效能改進,首先,開發團隊在二進位發布版本應用BOLT工具,使得基準測試平均執行時間改善2%,官方提到,BOLT工具最佳化大部分包含rustc程式碼的librustc_driver.so函式庫布局,能夠改善快取利用效率。此外,開發團隊還使用-Ccodegen-units=1編譯器選項編譯rustc,進一步分析和最佳化編譯器程式碼,使得rustc平均執行時間改善1.5%,讓編譯器得以編譯程式可以更快速。

Popular articles
Indiana online casino bill stalls in House committee
Regulation
GGC Awards 2026 Shines in Colombo: Honoring Leaders and Innovators in the iGaming Industry
HUIDU Focus
UK MPs reopen 2025 gambling inquiry as reform stalls
Regulation
Vietnam's tightening online gaming policy creates new market opportunities
Southeast Asia
GAT CDMX 2025 Institutional Academy: Leaders and Experts Analyze the Present and Future of the Gaming Industry in Mexico and Lat
Sports Game
1spin4win grows its Latin American presence by partnering with Fortuna Juegos
Online Game
PropellerAds Shared a New iGaming Case Study: 97,674 Installs and 12,701 Deposits in 3 Months
Marketing
B2B Tech Infrastructure Gains Momentum in Philippine Gaming Sector
Southeast Asia
Institutional Academy that exceeded expectations marked the opening of GAT CDMX
Online Game
Super PAC Raises $48 Million: Sports Betting Forces Ramp Up Political Push
Regulation
JILI Partners with Cricket Legend AB de Villiers (ABD) to Launch Exclusive Branded Game Series 100% 11
Sports Game
1spin4win releases unique slot Don Catleone Hold and Win featuring gangster cats
Online Game
Kazakhstan plans to penalise online casino promotions
Regulation
British gambling levy rates confirmed for each vertical
Regulation
SBC Summit Canada to Make Player Safety a Key Pillar of 2026 Agenda
Marketing
Home
Game
Cooperation
Find
My