TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Async Rust in Three Parts

162 pointsby oconnor6637 months ago

6 comments

alilleybrinker7 months ago
In part two, the author explains trait objects in a way that is, I think, a little misleading.<p>They&#x27;re right that trait objects are dynamically sized types, which means they can&#x27;t be passed by value to functions, but wrong that they need to be boxed; they can instead be put behind a reference. Both of the following are valid types.<p><pre><code> type DynFutureBox = Pin&lt;Box&lt;dyn Future&lt;Output = ()&gt;&gt;&gt;; type DynFutureRef&lt;&#x27;f&gt; = Pin&lt;&amp;&#x27;f dyn Future&lt;Output = ()&gt;&gt;; </code></pre> You can see this in the Rust Playground here: <a href="https:&#x2F;&#x2F;play.rust-lang.org&#x2F;?version=stable&amp;mode=debug&amp;edition=2021&amp;gist=6c61667f75dfc2435e6a342f897d1c30" rel="nofollow">https:&#x2F;&#x2F;play.rust-lang.org&#x2F;?version=stable&amp;mode=debug&amp;editio...</a>
评论 #41929946 未加载
keyle7 months ago
My only experience with Rust has been synchronous mostly with little to show for in terms of async. And I liked Rust. When it ran, I was damn sure it was going to run. There is comfort in that: &quot;Tell me what to fix&quot;. The clippy stuff etc. was great too.<p>I read the 3 parts of this website and &#x27;Wowsa&#x27;... I&#x27;m definitely not going in that direction with Rust. I&#x27;ll stick to dumb Go code, Swift or Python if I do async heavy stuff.<p>It&#x27;s hard enough to write good code, I don&#x27;t see the point of finding walls to smash my head into.<p>Think about it, if you write a lot of async code, chances are you have a ton of latency, waiting on I&#x2F;O, disk, network etc. Using Rust for this in the first place isn&#x27;t the wisest since performance isn&#x27;t as important, most of your performance is wasted &#x27;waiting&#x27; on things. Besides Rust wants purity and I&#x2F;O is gritty little dirt.<p>Sorry my comment turned into a bit of a hot take, feel free to disagree. This async stuff, doesn&#x27;t look fun at all.
评论 #41931208 未加载
评论 #41932620 未加载
评论 #41931512 未加载
评论 #41933063 未加载
评论 #41934260 未加载
评论 #41933015 未加载
Animats7 months ago
It&#x27;s amusing that the Rust Playground lets you run a hundred threads. That&#x27;s generous of them. There&#x27;s a ceiling below 1000, though. The author points out, &quot;On my Linux laptop I can spawn almost 19k threads before I hit this crash, but the Playground has tighter resource limits.&quot; Large servers can go higher than that.<p>The thread-based I&#x2F;O example with the compute bound poll loop is kind of strange.<p>&quot;Join&quot; isn&#x27;t really that useful when you have unrelated threads running finite tasks. Usually, you let the thread do its thing,finish, put results on a queue, and let the thread exit. Then it doesn&#x27;t matter who finishes first. Rust join is actually optional. You don&#x27;t have to join to close out a thread and reap the thread resources. It&#x27;s not like zombies in Unix&#x2F;Linux, where some resources are tied up until the parent process calls wait().<p>Loops where you join all the threads that are supposedly finished are usually troublesome. If somebody gets stuck, the joiner stalls. Clean exits from programs with lots of channels are troublesome. Channels with multiple senders don&#x27;t close until all senders exit, which can be hard to arrange when something detects an error.<p>In Rust, the main thread is special. (I consider this unfortunate, but web people like it, because inside browsers, the main thread is very special.) If the main thread exits, all the other threads are silently killed.
评论 #41929441 未加载
评论 #41929433 未加载
评论 #41929546 未加载
评论 #41929215 未加载
评论 #41929175 未加载
zavec7 months ago
I really liked the footnote implementation so I checked out his GitHub to see what kind of static site generator he was using, and it looks like he wrote his own? What a baller.
评论 #41931057 未加载
评论 #41931058 未加载
DeathArrow7 months ago
Async in Rust seems to be modelled after async in .NET.
评论 #41933391 未加载
评论 #41933318 未加载
ingen0s7 months ago
Thank you