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%,讓編譯器得以編譯程式可以更快速。

热门文章
Dutch gambling regulator wanrs lottery over advertorial
Regulation
Crypto in gambling: Market overview 2024
Marketing
New Partnership: 1spin4win Integrates Classic Slots into Pokerdom’s Gaming Library
Online Casino
Vietnam's tightening online gaming policy creates new market opportunities
Southeast Asia
HUIDU is Ready at Booth 2250 to Meet You at SiGMA Asia 2025
HUIDU Focus
Spanish regulator warns of identity theft via online gambling platforms
Regulation
Bally’s job training program is a big deal at Community College of Rhode Island
Regulation
FDJ says it doesn’t foresee French gambling tax hike, as stock price hit
Sports Betting
The GAT Events 2025 Circuit Kicks Off in Cartagena de Indias
HUIDU Focus
British gambling levy rates confirmed for each vertical
Regulation
The ultimate gambler? How Bet365’s Denise Coates became Britain’s richest woman
Sports Betting
ESPN Bet collects $3M handle in New York mobile debut
Sports Betting
Indiana online casino bill stalls in House committee
Regulation
Pennsylvania: Valley Forge Casino opening new dining hall
Regulation
French Gambling Giant FDJ Completes €2.5bn Kindred Group Purchase
Regulation
首页
游戏
合作
发现
我的