{"id":1214375,"date":"2023-12-21T11:02:37","date_gmt":"2023-12-21T16:02:37","guid":{"rendered":"https:\/\/www.prime-wow.com\/?p=1214375"},"modified":"2023-12-21T11:02:37","modified_gmt":"2023-12-21T16:02:37","slug":"announcing-async-fn-and-return-position-impl-trait-in-traits-rust-blog","status":"publish","type":"post","link":"https:\/\/www.prime-wow.com\/?p=1214375","title":{"rendered":"Announcing `async fn` and return-position `impl Trait` in traits (Rust Blog)"},"content":{"rendered":"<p>The Rust Blog <a href=\"https:\/\/blog.rust-lang.org\/2023\/12\/21\/async-fn-rpit-in-traits.html\">announces<\/a><br \/>\nthe stabilization of a couple of trait features aimed at improving support<br \/>\nfor <tt>async<\/tt> code:\n<\/p>\n<\/p>\n<blockquote class=\"bq\"><p>\n\tEver since the stabilization of RFC #1522 in Rust 1.26, Rust has<br \/>\n\tallowed users to write <tt>impl Trait<\/tt> as the return type of<br \/>\n\tfunctions (often called &#8220;RPIT&#8221;). This means that the function<br \/>\n\treturns &#8220;some type that implements <tt>Trait<\/tt>&#8220;. This is<br \/>\n\tcommonly used to return closures, iterators, and other types that<br \/>\n\tare complex or impossible to write explicitly. [&#8230;]<\/p>\n<p>\n\tStarting in Rust 1.75, you can use return-position <tt>impl<br \/>\n\tTrait<\/tt> in trait (RPITIT) definitions and in trait impls. For<br \/>\n\texample, you could use this to write a trait method that returns an<br \/>\n\titerator: [&#8230;]\n<\/p>\n<p>\n\tSo what does all of this have to do with async functions? Well,<br \/>\n\tasync functions are &#8220;just sugar&#8221; for functions that return<br \/>\n\t<tt>-&gt; impl Future<\/tt>. Since these are now permitted in<br \/>\n\ttraits, <b>we also permit you to write traits that use <tt>async fn<\/tt>.<\/b>\n<\/p>\n<\/blockquote>\n<p>&#013;<br \/>\n&#013;<br \/>\nSource: LWN.net &#8211; <a href=\"https:\/\/lwn.net\/Articles\/955925\/\" target=\"_blank\" rel=\"noopener\">Announcing `async fn` and return-position `impl Trait` in traits (Rust Blog)<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>The Rust Blog announces the stabilization of a couple of trait features aimed at improving support for async code: Ever since the stabilization of RFC #1522 in Rust 1.26, Rust has allowed users to write impl Trait as the return &hellip; <a href=\"https:\/\/www.prime-wow.com\/?p=1214375\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"ngg_post_thumbnail":0,"footnotes":""},"categories":[72],"tags":[75],"class_list":["post-1214375","post","type-post","status-publish","format-standard","hentry","category-linux","tag-linux"],"_links":{"self":[{"href":"https:\/\/www.prime-wow.com\/index.php?rest_route=\/wp\/v2\/posts\/1214375","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.prime-wow.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.prime-wow.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.prime-wow.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.prime-wow.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1214375"}],"version-history":[{"count":0,"href":"https:\/\/www.prime-wow.com\/index.php?rest_route=\/wp\/v2\/posts\/1214375\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.prime-wow.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1214375"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.prime-wow.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1214375"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.prime-wow.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1214375"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}