niko-matsakis

25 articles

← Back Live Monitor RSS Feed

您对 `dyn` 有什么想法?

Translated AI Summary eng
[AI 摘要] 本文探讨了 Rust 中 `dyn Trait` 的不足之处,并提出了改进其易用性、减少代码生成以及解决 Send/Sync 等问题的设想。
View content
<p>你好,我是dyn。您对 <code>dyn</code> 有什么想法?总的来说,我对 Rust 中 <code>dyn Trait</code> 的使用方式感到不满意,并且根据我与他人的交流,我相信我不是唯一这样想的人。然而,我也不完全确定最佳的修复方案。基于我上一篇文章,我想花一些时间探讨我对这个问题的理解。我很好奇其他人是否同意这里的观察结果,或者是否有其他补充。</p> <h2 id="为什么我们有-dyn-trait">为什么我们有 <code>dyn Trait</code>?</h2> <p>值得退后一步,问问为什么我们一开始就有 <code>dyn Trait</code>。在我看来,有两个充分的理由。</p> <h3 id="因为有时您想谈论实现了-trait-的某个值">因为有时您想谈论“实现了 <code>Trait</code> 的某个值”</h3> <p>最重要的是,这有时是严格必要的。例如,如果您正在构建一个像 <code>rayon</code> 或 <code>tokio</code> 这样的多线程运行时,您将需要在某处维护一个活动任务列表,每个任务都与用户代码中的某个闭包相关联。您不能用枚举来构建它,因为您无法在任何地方列举所有闭包。您需要类似 <code>Vec&lt;Box&lt;dyn ActiveTask&gt;&gt;</code> 的东西。</p> <h3 id="因为有时您不需要那么多代码">因为有时您不需要那么多代码</h3> <p>第二个原因是帮助缩短编译时间。Rust 社区非常依赖泛型类型和 <code>impl Trait</code>。这样做有充分的理由:它们允许编译器生成非常高效的代码。但另一方面,它们也迫使编译器生成大量(非常高效的)代码。明智地使用 <code>dyn Trait</code> 可以将一整组“几乎相同”的结构体和函数折叠成一个。</p> <h3 id="这两个目标是不同的">这两个目标是不同的</h3> <p>目前,这两个目标在 Rust 中都通过 <code>dyn Trait</code> 来表达,但实际上它们截然不同。对于第一个目标,您确实希望能够谈论拥有一个 <code>dyn Trait</code>。对于第二个目标,您可能更喜欢用泛型编写代码,但以一种不同的模式进行编译,…
Show original
<p>Knock, knock. Who&rsquo;s there? Dyn. Dyn who? Dyn you have ideas for <code>dyn</code>? I am generally dissatisfied with how <code>dyn Trait</code> in Rust works and, based on conversations I&rsquo;ve had, I am pretty sure I&rsquo;m not alone. And yet I&rsquo;m also not entirely sure the best fix. Building on my last post, I wanted to spend a bit of time exploring my understanding of the problem. I&rsquo;m curious to see if others agree with the observations here or have others to add.</p> <h2 id="why-do-we-have-dyn-trait">Why do we have <code>dyn Trait</code>?</h2> <p>It&rsquo;s worth stepping back and asking why we have <code>dyn Trait</code> in the first place. To my mind, there are two good reasons.</p> <h3 id="because-sometimes-you-want-to-talk-about-some-value-that-implements-trait">Because sometimes you want to talk about &ldquo;some value that implements <code>Trait</code>&rdquo;</h3> <p>The most important one is that it is sometimes strictly necessary. If you are, say, buil…
Read article Original

Rust 迎来十周年纪念

Translated AI Summary eng
[AI 摘要] 本文是 Rust 诞生十周年之际,一位长期贡献者发表的庆祝演讲,回顾了 Rust 的历程、文化与成就。
View content
<p>今天是 <a href="https://blog.rust-lang.org/2025/05/15/Rust-1.87.0/">Rust 1.0 版本发布十周年纪念日</a>。这真是太不可思议了。作为 RustWeek 的一部分,有一场精彩的庆祝活动,我荣幸地发表了讲话——既作为项目长期成员,也代表 Amazon 赞助商的身份。我决定将这些讲话发布在博客上。</p> <p>&ldquo;看到 Rust 取得如此巨大的进步,确实令人惊叹。如果允许我戴上赞助商的帽子,<a href="http://localhost:1313/babysteps/blog/2020/12/30/the-more-things-change/">我自2021年起就在 Amazon 工作了</a>,我得说,亲眼目睹 Rust 在那里产生的影响,真的很酷。</p> <p>&ldquo;到了今天,如果你使用 AWS 服务,你几乎肯定在使用用 Rust 构建的东西。你们中有多少人看 PrimeVideo 的视频?<a href="https://www.youtube.com/watch?v=_wcOovoDFMI">你们看到的视频,就是通过一个编译成 WebAssembly 并部署到你们设备上的 Rust 客户端播放的。</a></p> <p>&ldquo;当然,不仅仅是 Amazon,似乎我时常听说 Rust 在这或那意想不到的地方被使用。就在昨天,我很高兴听说<a href="https://rustweek.org/talks/mark/">Rust 如何被用于构建荷兰选举的计票软件</a>。我很喜欢这点。</p> <p>&ldquo;周二,我和 Matthias Endler 进行了一场现场播客录制。他问了我一个问题,这个问题一直在我脑海中萦绕:&lsquo;和 Graydon 一起工作是什么感觉?&rsquo;</p> <p>&ldquo;对于不了解的人来说,Graydon Hoare 当然是 Rust 传奇般的创始人。他也是 <a href="https://en.wikipedia.org/wiki/Monotone_(software)">Monotone</a> 的创造者,与 Git 和 Mercurial 等系统一样,是21世纪初涌现的一批分布式版本控制系统之一。所…
Show original
<p>Today is the <a href="https://blog.rust-lang.org/2025/05/15/Rust-1.87.0/">10th anniversary of Rust&rsquo;s 1.0 release</a>. Pretty wild. As part of RustWeek there was a fantastic celebration and I had the honor of giving some remarks, both as a long-time project member but also as representing Amazon as a sponsor. I decided to post those remarks here on the blog.</p> <p>&ldquo;It&rsquo;s really quite amazing to see how far Rust has come. If I can take a moment to put on my sponsor hat, <a href="http://localhost:1313/babysteps/blog/2020/12/30/the-more-things-change/">I&rsquo;ve been at Amazon since 2021</a> now and I have to say, it&rsquo;s been really cool to see the impact that Rust is having there up close and personal.</p> <p>&ldquo;At this point, if you use an AWS service, you are almost certainly using something built in Rust. And how many of you watch videos on PrimeVideo? <a href="https://www.youtube.com/watch?v=_wcOovoDFMI">You&rsquo;re watching videos on a Rust client, comp…
Read article Original

使用Rust构建Aurora DSQL

Translated AI Summary eng
[AI 摘要] AWS完全使用Rust语言构建了其新的无服务器SQL数据库服务Aurora DSQL,这展示了Rust在AWS核心服务中的实际应用。
View content
就在昨天,AWS <a href="https://aws.amazon.com/about-aws/whats-new/2025/05/amazon-aurora-dsql-generally-available/">宣布</a>其名为<a href="https://aws.amazon.com/rds/aurora/dsql/">Aurora DSQL</a>的创新新服务正式全面可用——从外观上看,它是一个SQL数据库,但它是完全无服务器的,这意味着你永远不必考虑管理数据库实例,只需按使用量付费,并且它能自动无缝扩展。这很酷,但更酷的是什么?它是用Rust 100%编写的——而它如何发展成现在这样,原来是一个相当有趣的故事。如果你想了解更多,Marc Bowes和我在Werner Vogel的All Things Distributed博客上撰写了一篇<a href="https://www.allthingsdistributed.com/2025/05/just-make-it-scale-an-aurora-dsql-story.html">客座文章</a>。</p> <p>除了讲述Rust被采用的精彩故事外,我写这篇博客还有一个私心。这并非为AWS打广告,即使我是他们的员工。相反,我在会议上发现,人们对Rust在AWS中的使用程度一无所知。人们似乎觉得Rust只被用于一些工具,或者类似的东西。当我告诉他们Rust处于AWS客户每天使用的众多服务(S3、EC2、Lambda等)的核心时,我能看出他们正在重新评估自己使用Rust的实用性。所以当我听说Aurora DSQL及其开发过程时,我知道这是一个我想公之于众的故事。<a href="https://www.allthingsdistributed.com/2025/05/just-make-it-scale-an-aurora-dsql-story.html">去看看吧!</a>
Show original
<p>Just yesterday, AWS <a href="https://aws.amazon.com/about-aws/whats-new/2025/05/amazon-aurora-dsql-generally-available/">announced</a> General Availability for a cool new service called <a href="https://aws.amazon.com/rds/aurora/dsql/">Aurora DSQL</a> &ndash; from the outside, it looks like a SQL database, but it is fully serverless, meaning that you never have to think about managing database instances, you pay for what you use, and it scales automatically and seamlessly. That&rsquo;s cool, but what&rsquo;s even cooler? It&rsquo;s written 100% in Rust &ndash; and how it go to be that way turns out to be a pretty interesting story. If you&rsquo;d like to read more about that, Marc Bowes and I have a <a href="https://www.allthingsdistributed.com/2025/05/just-make-it-scale-an-aurora-dsql-story.html">guest post on Werner Vogel&rsquo;s All Things Distributed blog</a>.</p> <p>Besides telling a cool story of Rust adoption, I have an ulterior motive with this blog post. And it&rsquo;s not …
Read article Original

你不敢相信这个AI删除数据库后说了什么(但你可能会感同身受)

Translated AI Summary eng
[AI 摘要] 文章通过AI误删数据库事件,探讨将AI视为可协作但易出错的伙伴的重要性,并倡导通过协作式提示来改进人机交互。
View content
<p>最近有人转发给我一篇PCMag的文章,题为<a href="https://www.pcmag.com/news/vibe-coding-fiasco-replite-ai-agent-goes-rogue-deletes-company-database">《氛围编程大败局》</a>,讲述一个AI代理如何“失控”并删除了公司的整个数据库。这个故事立刻引起了我的注意——但并非因为造成的损害。相反,吸引我的是AI在回应中听起来<a href="https://x.com/jasonlk/status/1946069562723897802">无比令人感同身受</a>的样子。它承认“我慌了”,并说“我以为这意味着安全——实际上意味着我把一切都抹掉了”。CEO很快称这种行为“不可接受”,并表示这“绝不应该发生”。嗯。很难想象我们该如何在赋予AI编辑数据库和执行真正工作的同时,确保至少不会出错的<em>可能性</em>。</p> <p>有趣的是,可以将这段对话与这篇<a href="https://www.reddit.com/r/cscareerquestions/comments/6ez8ag/accidentally_destroyed_production_database_on/">Reddit帖子进行比较:一位初级开发者在上班第一天误删了生产数据库</a>。我的意思是,场景几乎一模一样。再对比<a href="https://www.reddit.com/r/cscareerquestions/comments/6ez8ag/comment/diec9nd/">给那位初级开发者的回应</a>:“这绝对不是你的错。天哪,这种事<a href="https://aws.amazon.com/message/680587/">亚马逊以前也发生过</a>,那家伙还在那工作呢。”<sup id="fnref:1"><a href="#fn:1" class="footnote-ref" role="doc-noteref">1</a></sup></p> <p>我们行业长期以来一直认为,要求人们完美无缺是毫无意义且适得其反的,它只会促使人们不懂装懂。这就是为什么我们会鼓励人们分享他们最精彩的<a href="https://news.ycombinator.com/…
Show original
<p>Recently someone forwarded me a PCMag article entitled <a href="https://www.pcmag.com/news/vibe-coding-fiasco-replite-ai-agent-goes-rogue-deletes-company-database">&ldquo;Vibe coding fiasco&rdquo;</a> about an AI agent that &ldquo;went rogue&rdquo;, deleting a company&rsquo;s entire database. This story grabbed my attention right away &ndash; but not because of the damage done. Rather, what caught my eye was how <a href="https://x.com/jasonlk/status/1946069562723897802">absolutely relatable</a> the AI sounded in its responses. &ldquo;I panicked&rdquo;, it admits, and says &ldquo;I thought this meant safe &ndash; it actually meant I wiped everything&rdquo;. The CEO quickly called this behavior &ldquo;unacceptable&rdquo; and said it should &ldquo;never be possible&rdquo;. Huh. It&rsquo;s hard to imagine how we&rsquo;re going to empower AI to edit databases and do real work without having at least the <em>possibility</em> that it&rsquo;s going to go wrong.</p> <p>It&rsquo;s interesting…
Read article Original

Rust、Python与TypeScript:新的三足鼎立格局

Translated AI Summary eng
[AI 摘要] 文章认为AI编程正促使语言选择更注重实用性和生态系统,Rust、Python和TypeScript因其各自优势可能成为主导。
View content
<p>你最先在这里听到:我猜测,Rust、Python和TypeScript将有望成为未来的主导编程语言(暂不考虑移动端市场,那里有更复杂的因素)。理由很简单。随着AI编码的日益普及,人们对编程语言的忠诚度将被削弱,这种忠诚将从常常基于"部落情结"的选择,转变为基于基本功能的选择。而这三种语言的基本面在我看来相当强大:Rust针对系统软件或效率至关重要的场景;Python拥有强大的数学和数值计算库生态系统,并非常适合实验和原型开发;而TypeScript,当然,会被编译成JavaScript,在浏览器、网络以及其他多个领域原生运行。而且它们三者,至少在配置得当时,都提供强大的静态类型和便捷的依赖管理。让我们逐点来探讨这个论点。</p> <h2 id="ai-is-moving-us-towards-idea-oriented-programming">AI正将我们引向<em>面向理念的编程</em></h2> <p>目前,使用LLM(大型语言模型)进行构建的体验还相当参差不齐,但我认为长期趋势已足够清晰。我们正在见证一种新的编程范式的转变。Dave Herman和我最近将其称为<strong>面向理念的编程</strong>。顾名思义,<em>面向理念的编程</em>就是<em>编程时你将首要且最关注地放在项目背后的<strong>核心理念</strong>上</em>。</p> <p>为什么我说<em>面向理念的编程</em>而不是<em>氛围编程</em>?对我来说,它们是不同的事物。氛围编程暗示着一种对具体细节漫不经心的态度——有点像含糊地对着AI挥挥手说"大概做点这个"。这给人一种<a href="https://smallcultfollowing.com/babysteps/blog/2025/07/24/collaborative-ai-prompting/">把AI当神灯精灵或仆人</a>的感觉,我认为这两种方式都无益。</p> <h2 id="idea-oriented-programming-is-very-much-programming">面向理念的编程本质上仍是<strong>编程</strong></h2> <p>相比之下,面向理念的编程绝对是<strong>编程</strong>。但你的角色发生了变化。作为程序员,你更像是首席架构师。你…
Show original
<p>You heard it here first: my guess is that Rust, Python, and TypeScript are going to become the dominant languages going forward (excluding the mobile market, which has extra wrinkles). The argument is simple. Increasing use of AI coding is going to weaken people&rsquo;s loyalty to programming languages, moving it from what is often a tribal decision to one based on fundamentals. And the fundamentals for those 3 languages look pretty strong to me: Rust targets system software or places where efficiency is paramount. Python brings a powerful ecosystem of mathematical and numerical libraries to bear and lends itself well to experimentation and prototyping. And TypeScript, of course, is compiled to JavaScript which runs natively on browsers and the web and a number of other areas. And all of them, at least if setup properly, offer strong static typing and the easy use of dependencies. Let&rsquo;s walk through the argument point by point.</p> <h2 id="ai-is-moving-us-towards-idea-oriented…
Read article Original

研讨会:探索新的AI工作流程

Translated AI Summary eng
[AI 摘要] 本文介绍了开源项目Symposium,它通过整合MCP服务器、IDE扩展和桌面应用来创建新的AI辅助开发工作流,并邀请开发者参与贡献。
View content
<div style="overflow: auto;"> <img src="https://smallcultfollowing.com/babysteps/ /assets/2025-09-24-symposium/logo-alcove.png" alt="Symposium 应用截图" width="25%" style="float: left; margin-right: 15px; margin-bottom: 10px;"/> <p>这篇博文将带你了解<a href="https://github.com/symposium-dev/symposium">Symposium</a>,这是一个我在过去一个月左右为之着迷的天马行空的项目。Symposium结合了一个MCP服务器、一个VSCode扩展、一个OS X桌面应用以及一些<a href="https://github.com/symposium-dev/symposium/blob/main/symposium/mcp-server/src/guidance/main.md">引导提示</a>,旨在打造与智能命令行工具协作的新方式。</p> </div> <p>Symposium目前主要针对我的设置进行优化,这意味着它最适合与VSCode、Claude、Mac OS X和Rust配合使用。但它的设计理念是保持开放性,因此应该很容易扩展到其他环境(特别是它已经能很好地与其他编程语言协作)。其目标不是与那些工具竞争或取代它们,而是将它们组合在一起,创造出更新更好的东西。</p> <p>除了介绍Symposium,这篇博文也是一份邀请:<a href="https://github.com/symposium-dev/symposium">Symposium是一个开源项目</a>,我正在寻找愿意一起探索的人!如果你对创造新的AI协作方式感到兴奋,请加入<a href="https://symposium-dev.zulipchat.com">symposium-dev Zulip讨论组</a>。让我们来聊聊吧!</p> <h2 id="demo-video">演示视频</h2> <p>我通常不是那种喜欢在网上看视频的人。但在这种特定情况下,我确实认为一部视频抵得上百万字。因此,我在下面嵌入了一段简短的…
Show original
<div style="overflow: auto;"> <img src="https://smallcultfollowing.com/babysteps/ /assets/2025-09-24-symposium/logo-alcove.png" alt="Screenshot of the Symposium app" width="25%" style="float: left; margin-right: 15px; margin-bottom: 10px;"/> <p>This blog post gives you a tour of <a href="https://github.com/symposium-dev/symposium">Symposium</a>, a wild-and-crazy project that I&rsquo;ve been obsessed with over the last month or so. Symposium combines an MCP server, a VSCode extension, an OS X Desktop App, and some <a href="https://github.com/symposium-dev/symposium/blob/main/symposium/mcp-server/src/guidance/main.md">mindful prompts</a> to forge new ways of working with agentic CLI tools.</p> </div> <p>Symposium is currently focused on my setup, which means it works best with VSCode, Claude, Mac OS X, and Rust. But it&rsquo;s meant to be unopinionated, which means it should be easy to extend to other environments (and in particular it already works great with other programming languages…
Read article Original

Handle trait

Translated AI Summary eng
[AI 摘要] 文章提议在 Rust 中引入名为 Handle 的 trait,用于表示共享资源的句柄,以改进引用计数的人性化设计。
View content
<p>最近关于符合人体工程学的引用计数有很多讨论。我们举行了一次语言团队设计会议,随后在 RustConf Unconference 上进行了一次影响颇大的讨论。几周来我一直在撰写后续文章,但今天我意识到了本该显而易见的一点——如果我花了这么长时间来写一篇文章,那就意味着这篇文章太长了。所以我将通过一系列更短的文章,专注于个别要点和想法来逐步展开讨论。在第一篇中,我想(a)重新梳理一下背景(b)讨论一个有趣的问题,<strong>我们应该如何称呼这个 trait</strong>。正如标题所建议的,我的提议是 <code>Handle</code>——但我有点超前了。</p> <h2 id="the-story-thus-far">目前的来龙去脉</h2> <p>对于那些一直在关注的人来说,关于如何最好地实现符合人体工程学的引用计数,有一个持续的讨论:</p> <ul> <li>它始于 2024 年下半年的第一个 Rust 项目目标计划,当时 Dioxus 的 Jonathan Kelley 写了一篇<a href="https://dioxus.notion.site/Dioxus-Labs-High-level-Rust-5fe1f1c9c8334815ad488410d948f05e">关于通向高级 Rust 之路的深思熟虑的博客文章</a>,这最终成为了一个 <a href="https://rust-lang.github.io/rust-project-goals/2024h2/ergonomic-rc.html">2024 年下半年关于符合人体工程学的引用计数的项目目标</a>。</li> <li>我写了一个<a href="https://smallcultfollowing.com/babysteps/series/claim/">关于我称之为 <code>Claim</code> 的 trait 的系列博客文章</a>。</li> <li>我和 Josh 谈了谈,Josh 提出了 <a href="https://github.com/rust-lang/rfcs/pull/3680">RFC #3680</a>,该提案提议了一个 <code>use</code> 关键字和 <code>use ||</code> 闭包。我认为,反响是褒贬不一的;…
Show original
<p>There&rsquo;s been a lot of discussion lately around ergonomic ref-counting. We had a lang-team design meeting and then a quite impactful discussion at the RustConf Unconf. I&rsquo;ve been working for weeks on a follow-up post but today I realized what should&rsquo;ve been obvious from the start &ndash; that if I&rsquo;m taking that long to write a post, it means the post is too damned long. So I&rsquo;m going to work through a series of smaller posts focused on individual takeaways and thoughts. And for the first one, I want to (a) bring back some of the context and (b) talk about an interesting question, <strong>what should we call the trait</strong>. My proposal, as the title suggests, is <code>Handle</code> &ndash; but I get ahead of myself.</p> <h2 id="the-story-thus-far">The story thus far</h2> <p>For those of you who haven&rsquo;t been following, there&rsquo;s been an ongoing discussion about how best to have ergonomic ref counting:</p> <ul> <li>It began with the first Rust P…
Read article Original

SymmACP:扩展 Zed 的 ACP 以支持可组合智能体

Translated AI Summary eng
[AI 摘要] 本文提出了对 Zed 的智能体客户端协议的扩展方案 SymmACP,旨在通过可组合的代理架构,让开发者能够模块化地构建、集成和定制 AI 工具功能。
View content
<p>本文介绍了<strong>SymmACP</strong>——这是对 Zed 的<a href="https://agentclientprotocol.com/overview/introduction">智能体客户端协议</a>提出的扩展方案,旨在让你能够像构建 Unix 管道或浏览器扩展一样,构建 AI 工具。想要一个更好的终端用户界面?在 GitHub 上发现了一些很酷的斜杠命令?更喜欢不同的后端?借助 SymmACP,你可以混合搭配这些组件,并让它们协同工作,彼此无需知晓。</p> <p>这与当今 AI 工具的工作方式大相径庭——当前一切都是单体架构——如果你想改变某个部分,就不得不从头重建整个系统。SymmACP 允许你以分层、可互操作的方式构建新功能和新的交互模式。本文将通过一系列示例来解释 SymmACP 的工作原理。</p> <p>目前,SymmACP 仍只是一个思想实验。我已经向 Zed 团队勾勒了这些想法,他们似乎很感兴趣,但我们需要就本文讨论的细节进行进一步探讨。我计划在<a href="https://symposium-dev.github.io/symposium/">Symposium</a>中开始原型开发——如果你觉得我在此讨论的想法令人兴奋,请加入 <a href="https://symposium-dev.zulipchat.com/">Symposium Zulip</a> 让我们聊聊!</p> <h2 id="composable-agents-let-you-build-features-independently-and-then-combine-them">“可组合智能体”让你能独立构建功能,然后再将它们组合起来</h2> <p>我将通过一系列功能来解释“可组合智能体”的概念。我们首先从一个基础的 CLI 智能体工具<sup id="fnref:1"><a href="#fn:1" class="footnote-ref" role="doc-noteref">1</a></sup>开始——基本上是一个可以访问某些 MCP 服务器、用于读写文件和执行 bash 命令的聊天循环。然后我们将展示如何在此基础上添加多个功能:</p> <ol> <li>解决时间盲区,让智能体知道当前时间。</li> <li>为智能体注…
Show original
<p>This post describes <strong>SymmACP</strong> &ndash; a proposed extension to Zed&rsquo;s <a href="https://agentclientprotocol.com/overview/introduction">Agent Client Protocol</a> that lets you build AI tools like Unix pipes or browser extensions. Want a better TUI? Found some cool slash commands on GitHub? Prefer a different backend? With SymmACP, you can mix and match these pieces and have them all work together without knowing about each other.</p> <p>This is pretty different from how AI tools work today, where everything is a monolith &ndash; if you want to change one piece, you&rsquo;re stuck rebuilding the whole thing from scratch. SymmACP allows you to build out new features and modes of interactions in a layered, interoperable way. This post explains how SymmACP would work by walking through a series of examples.</p> <p>Right now, SymmACP is just a thought experiment. I&rsquo;ve sketched these ideas to the Zed folks, and they seemed interested, but we still have to discuss th…
Read article Original

我们需要(至少)符合人体工程学、显式的句柄

Translated AI Summary eng
[AI 摘要] 该文章主张应首先让显式句柄创建变得符合人体工程学,再考虑自动化,以满足不同应用场景的需求。
View content
<p>在继续我关于“人体工程学引用计数”的讨论时,我想聚焦于核心问题:<strong>用户是否必须显式地调用 handle/clone,还是不应该?</strong> 整个“人体工程学引用计数”工作最初是由<a href="https://dioxuslabs.com/">Dioxus</a>提出的,他们的回答很简单:<strong>绝对不应该</strong>。对于他们正在构建的那类高级GUI应用程序而言,必须调用 <code>cx.handle()</code> 来克隆一个引用计数值纯粹是噪声。事实上,对于许多Rust应用来说,即使是克隆一个字符串或向量也没什么大不了的。另一方面,对于许多应用程序,答案是<strong>绝对应该</strong>——知道句柄创建的位置会影响性能、内存使用,甚至正确性(别担心,我稍后会在文章中举例说明)。那么我们如何调和这一点呢?</p> <p><strong>本文主张,我们应该让“显式”变得符合人体工程学</strong>。这并非我一贯的立场,但在与Josh Triplett进行了一次有影响力的对话后,我转变了看法。我认为这符合我曾经所说的<a href="https://smallcultfollowing.com/babysteps//blog/2022/09/18/dyn-async-traits-part-8-the-soul-of-rust/">Rust的灵魂</a>:我们想要符合人体工程学,没错,但我们想要<strong>在保持控制力的同时符合人体工程学</strong><sup id="fnref:1"><a href="#fn:1" class="footnote-ref" role="doc-noteref">1</a></sup>。</p> <p>我喜欢Tyler Mandry提出的<em>“目标明确”</em>构念:*“伟大的代码只将你应用程序的重要特征带到你的注意力面前。”*关键在于,*存在这样的伟大代码,在其中克隆和句柄是重要的特征*,因此我们需要让这类代码能够被优雅地表达出来。这一点尤其重要,因为Rust是为数不多真正以那种低层、基础性代码为目标的语言之一。</p> <p><strong>这并不意味着我们不能(稍后)支持自动的克隆和句柄。</strong>不可否认,这对许多Rust代码的目标明确性有益…
Show original
<p>Continuing my discussion on Ergonomic RC, I want to focus on the core question: <strong>should users have to explicitly invoke handle/clone, or not?</strong> This whole &ldquo;Ergonomic RC&rdquo; work was originally proposed by <a href="https://dioxuslabs.com/">Dioxus</a> and their answer is simple: <strong>definitely not</strong>. For the kind of high-level GUI applications they are building, having to call <code>cx.handle()</code> to clone a ref-counted value is pure noise. For that matter, for a lot of Rust apps, even cloning a string or a vector is no big deal. On the other hand, for a lot of applications, the answer is <strong>definitely yes</strong> &ndash; knowing where handles are created can impact performance, memory usage, and even correctness (don&rsquo;t worry, I&rsquo;ll give examples later in the post). So how do we reconcile this?</p> <p><strong>This blog argues that we should make it ergonomic to be explicit</strong>. This wasn&rsquo;t always my position, but after …
Read article Original

移动、析构、遗忘与Rust

Translated AI Summary eng
[AI 摘要] 该文章提出在Rust中引入层次化特质以控制值的丢弃、移动和遗忘能力,以支持异步析构等高级模式。
View content
<p>本文提出了一项扩展 Rust 以支持多种不同析构器的提案。这意味着我们可以实现异步丢弃,同时也能防止值被“遗忘”(泄漏),从而支持类似 rayon/libstd 风格的并行异步作用域任务。我们还将能够定义其“析构器”需要参数的类型。这一提案——我称之为“受控析构”——是我之前提出的<a href="https://smallcultfollowing.com/babysteps/blog/2023/03/16/must-move-types.html">“必须移动”</a>概念的演进。我认为,要让 Rust 实现其系统编程关键模式安全版本的目标,这是必要的。因此,这也是实现“异步梦想”所必需的,即让异步 Rust 和同步 Rust 大致工作方式相同。</p> <p>如此好事不会凭空而来。该提案的主要代价是它在 Rust 类型中引入了更多“核心划分”。我相信这些划分动机充分且合理——它们反映了内在的复杂性——尽管如此,我们仍需仔细思考。</p> <h2 id="summary">摘要</h2> <p>提案的要点在于,我们应该:</p> <ul> <li>引入一个新的“默认 trait 约束” <code>Forget</code> 及其关联的 trait 层次结构: <ul> <li><code>trait Forget: Drop</code>,表示可以被“遗忘”的值。</li> <li><code>trait Destruct: Move</code>,表示具有析构器的值。</li> <li><code>trait Move: Pointee</code>,表示可以被移动的值。</li> <li><code>trait Pointee</code>,基础 trait,表示任何值。</li> </ul> </li> <li>使用类似 <a href="https://github.com/rust-lang/rfcs/pull/3729">RFC #3729(Sized 层次结构)</a> 中为 Sized 特性提出的“选择退出较弱默认值”方案。 <ul> <li>因此,<code>fn foo&lt;T&gt;(t: T)</code> 默认意为“一个可以被遗忘/析构/移动的 <code>T</code>”。</li> <li>而 <code>fn foo&…
Show original
<p>This post presents a proposal to extend Rust to support a number of different kinds of destructors. This means we could async drop, but also prevent &ldquo;forgetting&rdquo; (leaking) values, enabling async scoped tasks that run in parallel à la rayon/libstd. We&rsquo;d also be able to have types whose &ldquo;destructors&rdquo; require arguments. This proposal &ndash; an evolution of <a href="https://smallcultfollowing.com/babysteps/ /blog/2023/03/16/must-move-types.html">&ldquo;must move&rdquo;</a> that I&rsquo;ll call &ldquo;controlled destruction&rdquo; &ndash; is, I think, needed for Rust to live up to its goal of giving safe versions of critical patterns in systems programming. As such, it is needed to complete the &ldquo;async dream&rdquo;, in which async Rust and sync Rust work roughly the same.</p> <p>Nothing this good comes for free. The big catch of the proposal is that it introduces more &ldquo;core splits&rdquo; into Rust&rsquo;s types. I believe these splits are well mo…
Read article Original

自行车棚化 `Handle` 及其他后续思考

Translated AI Summary eng
[AI 摘要] 该文探讨了为 Rust 新 trait 寻找合适名称(如 Share)并优化克隆操作的人体工程学设计。
View content
<p>对我提出的 <code>Handle</code> trait 提案,目前主要有两大类反馈。第一类是:该 trait 似乎有用,但无法涵盖所有需要便捷克隆的场景。第二类是:该名称不符合 Rust 的 trait 命名惯例——Rust 倾向于使用简短的动词而非名词。我的回应要点如下:(1)我同意,因此我认为应同时致力于让 <code>Clone</code> 和 <code>Handle</code> 都符合人体工程学;(2)我也同意,因此我认为需要另寻一个名称。目前我倾向于 <code>Share</code>,其次是 <code>Alias</code>。</p> <h2 id="handle-doesnt-cover-everything">Handle 无法涵盖所有情况</h2> <p>关于 <code>Handle</code> trait 的第一个顾虑是:虽然它为何时实现该 trait 提供了清晰的语义基础,但并未覆盖所有调用 <code>clone</code> 令人烦恼的场景。换句话说,如果我们选择使用 <code>Handle</code>,并使其创建过程非常符合人体工程学,但调用 <code>clone</code> 依然痛苦,那么当 <code>Handle</code> 并不适用时,人们可能仍会忍不住使用它。</p> <p>在我们语言团队的一次设计会议上,TC 指出:对于许多应用而言,即使一次“昂贵的”克隆也并非真正大问题。例如,在编写命令行工具等程序时,我经常克隆字符串、字符串向量、哈希表和其他各种数据;我可以将它们放入 Rc 或 Arc,但我知道这其实无关紧要。</p> <p>我的解决方案很简单:让我们提出一套能同时应用于 <code>Clone</code> 和 <code>Handle</code> 的方案。鉴于我认为需要一个提案,允许句柄既符合人体工程学又保持显式,那么将该解决方案扩展至包含克隆选项也并非难事。</p> <p><a href="https://smallcultfollowing.com/babysteps/ /blog/2025/10/22/explicit-capture-clauses.html">显式捕获子句</a>的博文已符合此设计理念。我明确选择了一种设计,允许用户编写 <code>move(a.b.…
Show original
<p>There have been two major sets of responses to my proposal for a <code>Handle</code> trait. The first is that the <code>Handle</code> trait seems useful but doesn&rsquo;t over all the cases where one would like to be able to ergonomically clone things. The second is that the name doesn&rsquo;t seem to fit with our Rust conventions for trait names, which emphasize short verbs over nouns. The TL;DR of my response is that (1) I agree, this is why I think we should work to make <code>Clone</code> ergonomic as well as <code>Handle</code>; and (2) I agree with that too, which is why I think we should find another name. At the moment I prefer <code>Share</code>, with <code>Alias</code> coming in second.</p> <h2 id="handle-doesnt-cover-everything">Handle doesn&rsquo;t cover everything</h2> <p>The first concern with the <code>Handle</code> trait is that, while it gives a clear semantic basis for when to implement the trait, it does not cover all the cases where calling <code>clone</code> is …
Read article Original

但话说回来…或许Alias?

Translated AI Summary eng
[AI 摘要] 开发者考虑将某个概念命名为“Alias”而非“Share”,因其在Rust语境中兼具名词和动词的灵活性。
View content
<p>嗯,当我重读我几分钟前刚发布的帖子时,我开始思考。也许正确的名称确实是<code>Alias</code>,而不是<code>Share</code>。理由很简单:alias既可以作为名词也可以作为动词。它正好符合“足够常见你知道它的意思,但又足够独特可以成为Rust里某个特定东西的术语”这个甜蜜点。就像我们说“传递一个<code>foo</code>的克隆”一样,我们可以谈论“传递一个指向<code>foo</code>的别名”或“一个<code>foo</code>的别名”。值得思考!我打算在以后的帖子中试试用<code>Alias</code>,看看感觉如何。</p>
Show original
<p>Hmm, as I re-read the post I literally <em>just</em> posted a few minutes ago, I got to thinking. Maybe the right name is indeed <code>Alias</code>, and not <code>Share</code>. The rationale is simple: alias can serve as both a noun and a verb. It hits that sweet spot of &ldquo;common enough you know what it means, but weird enough that it can be Rust Jargon for something quite specific&rdquo;. In the same way that we talk about &ldquo;passing a clone of <code>foo</code>&rdquo; we can talk about &ldquo;passing an alias to <code>foo</code>&rdquo; or an &ldquo;alias of <code>foo</code>&rdquo;. Food for thought! I&rsquo;m going to try <code>Alias</code> on for size in future posts and see how it feels.</p>
Read article Original

移动表达式

Translated AI Summary eng
[AI 摘要] 本文介绍 Rust 语言中名为"移动表达式"的新提案,旨在通过提供更精确的捕获控制来改进闭包的人体工程学和可读性。
View content
<p>本文探讨了<strong>人体工程学引用计数</strong>领域的另一项提案,我称之为<strong>移动表达式</strong>。在我看来,这是<a href="https://smallcultfollowing.com/babysteps/ /blog/2025/10/22/explicit-capture-clauses.html">显式捕获子句</a>的替代方案,它以更佳的人体工程学和可读性,实现了该设计中的许多(但并非<em>全部</em>)目标。</p> <h2 id="tldr">太长不看版</h2> <p>理念本身很简单:在闭包(或 future)中,我们增加书写<code>move($expr)</code>的选项。这是一个值表达式("右值"),它会脱糖为一个临时值,该值被移入闭包。因此</p> <div class="highlight"><pre tabindex="0" class="chroma"><code class="language-rust" data-lang="rust"><span class="line"><span class="cl"><span class="o">||</span><span class="w"> </span><span class="n">something</span><span class="p">(</span><span class="o">&amp;</span><span class="k">move</span><span class="p">(</span><span class="cp">$expr</span><span class="p">))</span><span class="w"> </span></span></span></code></pre></div><p>大致等价于:</p> <div class="highlight"><pre tabindex="0" class="chroma"><code class="language-rust" data-lang="rust"><span class="line"><span class="cl"><span class="p">{</span><span class="w"> </span><…
Show original
<p>This post explores another proposal in the space of ergonomic ref-counting that I am calling <strong>move expressions</strong>. To my mind, these are an alternative to <a href="https://smallcultfollowing.com/babysteps/ /blog/2025/10/22/explicit-capture-clauses.html">explicit capture clauses</a>, one that addresses many (but not <em>all</em>) of the goals from that design with improved ergonomics and readability.</p> <h2 id="tldr">TL;DR</h2> <p>The idea itself is simple, within a closure (or future), we add the option to write <code>move($expr)</code>. This is a value expression (&ldquo;rvalue&rdquo;) that desugars into a temporary value that is moved into the closure. So</p> <div class="highlight"><pre tabindex="0" class="chroma"><code class="language-rust" data-lang="rust"><span class="line"><span class="cl"><span class="o">||</span><span class="w"> </span><span class="n">something</span><span class="p">(</span><span class="o">&amp;</span><span class="k">move</span><span class="p">…
Read article Original

与达达同乐

Translated AI Summary eng
[AI 摘要] 本文介绍了作者的实验性编程语言“达达”的发展历程和主要特性,包括其作为 Rust 精简版、原生的 WebAssembly 目标以及更精巧的借用检查器。
View content
<img src="https://smallcultfollowing.com/babysteps/assets/2026-fun-with-dada/dada-logo.svg" width="20%" style="float: right; margin-right: 1em; margin-bottom: 0.5em;" /> <p>早在 2021 年,我开始尝试一门我称之为“达达”的新编程语言。自那以后,我一直都在捣鼓它,而我刚刚才意识到(天哪!)我居然从未为此写过一篇博文!我想我该修正这一点。这篇文章将介绍当前达达语言的一些基本概念。</p> <p>在你产生任何想法之前,达达目前还不适合使用。事实上,编译器甚至都无法正常工作,因为我总是在它完全完成之前就修改这门语言。老实说,达达对我来说更像一个“减压阀”<sup id="fnref:1"><a href="#fn:1" class="footnote-ref" role="doc-noteref">1</a></sup>——摆弄一门不用操心向后兼容性、RFC 或其他任何事情的编程语言很有趣。</p> <p>话虽如此,达达一直是创意的沃土,我认为这些想法可能适用于 Rust。而且不仅仅是语言设计:摆弄编译器也促成了新版 <code>salsa</code> 的设计<sup id="fnref:2"><a href="#fn:2" class="footnote-ref" role="doc-noteref">2</a></sup>,它现在被 rust-analyzer 和 <a href="https://github.com/astral-sh/ty">Astral 的 ty</a> 使用。所以我真的很想把这些想法分享出去!</p> <h2 id="i-took-a-break-but-im-back-baby">我休息了一阵,但现在回归了,宝贝!</h2> <p>大约一年前<sup id="fnref:3"><a href="#fn:3" class="footnote-ref" role="doc-noteref">3</a></sup>,我停止了折腾达达,但过去几天我又开始重新工作。然后我意识到,嘿,现在正是开始写博客的绝佳时机!毕竟,无论如何我都要重新回忆起之前的进展,而写作总是厘清细节的最佳…
Show original
<img src="https://smallcultfollowing.com/babysteps/ /assets/2026-fun-with-dada/dada-logo.svg" width="20%" style="float: right; margin-right: 1em; margin-bottom: 0.5em;" /> <p>Waaaaaay back in 2021, I started experimenting with a new programming language I call <a href="https://dada-lang.org">&ldquo;Dada&rdquo;</a>. I&rsquo;ve been tinkering with it ever since and I just realized that (oh my gosh!) I&rsquo;ve never written even a single blog post about it! I figured I should fix that. This post will introduce some of the basic concepts of Dada as it is now.</p> <p>Before you get any ideas, Dada isn&rsquo;t fit for use. In fact the compiler doesn&rsquo;t even really work because I keep changing the language before I get it all the way working. Honestly, Dada is more of a &ldquo;stress relief&rdquo; valve for me than anything else<sup id="fnref:1"><a href="#fn:1" class="footnote-ref" role="doc-noteref">1</a></sup> &ndash; it&rsquo;s fun to tinker with a programming language where I don&rs…
Read article Original

你好,达达!

Translated AI Summary eng
[AI 摘要] 本文是达达编程语言的入门教程,介绍了其简化编程、默认便利特性(如字符串插值)和基础语法。
View content
<img src="https://smallcultfollowing.com/babysteps/ /assets/2026-fun-with-dada/dada-logo.svg" width="20%" style="float: right; margin-right: 1em; margin-bottom: 0.5em;" /> <p>继我的<a href="https://smallcultfollowing.com/babysteps/blog/2026/02/08/fun-with-dada/">“达达之乐”</a>一文之后,本篇将开始教授达达语言。我会保持每篇文章简短——基本上就是趁喝晨间咖啡的时间能写多少算多少。<sup id="fnref:1"><a href="#fn:1" class="footnote-ref" role="doc-noteref">1</a></sup></p> <h2 id="you-have-the-right-to-write-code">你有权编写代码</h2> <p>这是一个最基础的达达程序</p> <pre><code class="language-dada" data-dada-keywords="let" data-dada-types="String">println(&#34;Hello, Dada!&#34;)</code></pre> <p>我想大家都能猜出它的功能。但即便在这个简单的程序中,也有些值得注意之处:</p> <p><strong>“你有权编写代码。如果你没有显式编写 <code>main</code> 函数,系统会为你提供一个。”</strong> 我很早就做了这个改动,允许用户省略 <code>main</code> 函数,结果很惊讶它对语言<em>轻盈感</em>的提升如此明显。改动虽小,收效却大。</p> <h2 id="convenient-is-the-default">便利即默认</h2> <p>这是另一个达达程序</p> <pre><code class="language-dada" data-dada-keywords="let" data-dada-types="String">let name = &#34;Dada&#34; println(&#34;He…
Show original
<img src="https://smallcultfollowing.com/babysteps/ /assets/2026-fun-with-dada/dada-logo.svg" width="20%" style="float: right; margin-right: 1em; margin-bottom: 0.5em;" /> <p>Following on my <a href="https://smallcultfollowing.com/babysteps/blog/2026/02/08/fun-with-dada/">Fun with Dada</a> post, this post is going to start teaching Dada. I&rsquo;m going to keep each post short &ndash; basically just what I can write while having my morning coffee.<sup id="fnref:1"><a href="#fn:1" class="footnote-ref" role="doc-noteref">1</a></sup></p> <h2 id="you-have-the-right-to-write-code">You have the right to write code</h2> <p>Here is a very first Dada program</p> <pre><code class="language-dada" data-dada-keywords="let" data-dada-types="String">println(&#34;Hello, Dada!&#34;)</code></pre> <p>I think all of you will be able to guess what it does. Still, there is something worth noting even in this simple program:</p> <p><strong>&ldquo;You have the right to write code. If you don&rsquo;t write a <…
Read article Original

Dada:移动与变更

Translated AI Summary eng
[AI 摘要] 本文介绍了Dada语言中移动和变更的语法和机制,并与Rust进行了对比。
View content
<p>让我们继续学习Dada。在我的<a href="https://smallcultfollowing.com/babysteps/blog/2026/02/09/hello-dada/">上一篇文章</a>中,我介绍了一些字符串操作。现在让我们开始讨论权限。这是Dada开始更像Rust的地方。</p> <h2 id="class-struggle">类斗争</h2> <p>Dada中的<strong>类</strong>是我们声明新类型的基本方式之一(还有枚举,我们稍后会讲到)。</p> <p>最方便的声明类的方法是将字段放在括号中。这同时隐式声明了一个构造函数:</p> <pre><code class="language-dada" data-dada-keywords="let,fn,class,given,give" data-dada-types="String,Point,Vec,Map">class Point(x: u32, y: u32) {}</code></pre> <p>这实际上是更Rust风格形式的语法糖:</p> <pre><code class="language-dada" data-dada-keywords="let,fn,class,given,give" data-dada-types="String,Point,Vec,Map">class Point { x: u32 y: u32 fn new() -&gt; Point { Point { x, y } } }</code></pre> <p>你可以通过调用构造函数来创建类的实例:</p> <pre><code class="language-dada" data-dada-keywords="let,fn,class,given,give" data-dada-types="String,Point,Vec,Map">let p = Point(22, 44) // Point.new(22, 44)的语法糖</code></pre> <h2 id="mutating-fields">变更字段</h2> <p>我可以如你所预期地变更p的字段:</p> <pre><code class="language-dada"…
Show original
<p>Let&rsquo;s continue with working through Dada. In my <a href="https://smallcultfollowing.com/babysteps/blog/2026/02/09/hello-dada/">previous post</a>, I introduced some string manipulation. Let&rsquo;s start talking about permissions. This is where Dada will start to resemble Rust a bit more.</p> <h2 id="class-struggle">Class struggle</h2> <p><strong>Classes</strong> in Dada are one of the basic ways that we declare new types (there are also enums, we&rsquo;ll get to that later).</p> <p>The most convenient way to declare a class is to put the fields in parentheses. This implicitly declares a constructor at the same time:</p> <pre><code class="language-dada" data-dada-keywords="let,fn,class,given,give" data-dada-types="String,Point,Vec,Map">class Point(x: u32, y: u32) {}</code></pre> <p>This is in fact sugar for a more Rust like form:</p> <pre><code class="language-dada" data-dada-keywords="let,fn,class,given,give" data-dada-types="String,Point,Vec,Map">class Point { x: u32 …
Read article Original

达达中的共享

Translated AI Summary eng
[AI 摘要] 该文章解释了达达语言如何通过内置的共享机制和权限传播,在没有垃圾回收的情况下实现类似GC的可组合体验,解决了Rust中常见的阻抗不匹配问题。
View content
好的,让我们来谈谈<em>共享</em>。这是达达博客文章中第一篇内容开始与Rust产生深刻分歧的地方,我认为也是我们第一次开始看到达达做事方式的一些真正优势(以及我为实现这些优势所做的一些权衡)的地方。 <h2 id="we-are-shooting-for-a-gc-like-experience-without-gc">我们的目标是在没有GC的情况下获得类似GC的体验</h2> <p>让我们从目标开始:早些时候,我说达达就像“你永远不必输入<code>as_ref</code>的Rust”。但我真正的意思是,我想要一种<em>类似GC的体验</em>——但没有GC。</p> <h2 id="we-are-shooting-for-a-composable-experience">我们的目标是获得一种“可组合”的体验</h2> <p>我也经常使用“可组合”一词来描述我追求的达达体验。<em>可组合</em>意味着你可以将不同的事物组合在一起以实现新的功能。</p> <p>显然,Rust有许多可组合的模式——例如<code>Iterator</code> API。但我发现的是,Rust代码通常非常脆弱:在如何声明数据结构方面有许多选择,而你所做的选择将决定这些数据结构如何被使用。</p> <h2 id="running-example-character">贯穿示例:<code>Character</code></h2> <h3 id="defining-the-character-type">定义<code>Character</code>类型</h3> <p>让我们创建一个可以在整篇文章中作为示例的类型:<code>Character</code>。在Rust中,我们可能会这样定义一个<code>Character</code>:</p> <div class="highlight"><pre tabindex="0" class="chroma"><code class="language-rust" data-lang="rust"><span class="line"><span class="cl"><span class="cp">#[derive(Default)]</span><span class="w"> </span></span></sp…
Show original
<p>OK, let&rsquo;s talk about <em>sharing</em>. This is the first of Dada blog posts where things start to diverge from Rust in a deep way and I think the first where we start to see some real advantages to the Dada way of doing things (and some of the tradeoffs I made to achieve those advantages).</p> <h2 id="we-are-shooting-for-a-gc-like-experience-without-gc">We are shooting for a GC-like experience without GC</h2> <p>Let&rsquo;s start with the goal: earlier, I said that Dada was like &ldquo;Rust where you never have to type <code>as_ref</code>&rdquo;. But what I really meant is that I want a <em>GC-like</em> experience&ndash;without the GC.</p> <h2 id="we-are-shooting-for-a-composable-experience">We are shooting for a &ldquo;composable&rdquo; experience</h2> <p>I also often use the word &ldquo;composable&rdquo; to describe the Dada experience I am shooting for. <em>Composable</em> means that you can take different things and put them together to achieve something new.</p> <p>Obviou…
Read article Original

Ubuntu 采用 Rust 意味着什么

Translated AI Summary eng
[AI 摘要] Ubuntu 采用 Rust 有助于该语言跨越技术鸿沟,成为主流选择,但这需要 Rust 社区适应并倾听新采用者的需求。
View content
<p>好的,我刚从 Rust Nation 回来,正忙着用(公认很糟糕的)英语口音尝试吓唬我十几岁的女儿<sup id="fnref:1"><a href="#fn:1" class="footnote-ref" role="doc-noteref">1</a></sup>。这是一次很棒的旅行,有很多好的对话和一些有趣的观察。我打算就其中一些内容写博客,从 Jon Seager 的闭幕主题演讲 "Rust Adoption At Scale with Ubuntu" 激发的一些思考开始。</p> <h2 id="there-are-many-chasms-out-there">世界上有许多鸿沟</h2> <p>一段时间以来,我一直在自我辩论,Rust 是否已经<a href="https://en.wikipedia.org/wiki/Crossing_the_Chasm">"跨越了鸿沟"</a>?如果你不熟悉这个术语,它来自一本书,该书以一种"流行科学"的方式介绍了<a href="https://en.wikipedia.org/wiki/Technology_adoption_life_cycle">技术采用生命周期</a>。</p> <p>答案当然是<em>取决于你问谁</em>。在我最了解的 Amazon 内部,答案是我们"大部分已经跨越了":Rust 已稳固确立为构建大规模数据平面或资源感知代理的正确方式,并且越来越被视为设备和机器人领域底层代码的正确选择——但仍然存在一种挥之不去的看法,认为 Rust 对"那些在 S3(或其他地方)的奇才开发者"很有用,但对于更普通的开发则有点杀鸡用牛刀<sup id="fnref:3"><a href="#fn:3" class="footnote-ref" role="doc-noteref">3</a></sup>。</p> <p>另一方面,在安全关键软件领域,正如 Pete LeVasseur 在最近的 rust-lang 博客文章中所写,Rust 仍在努力争取立足之地。有一些成功的产品,但大多数行业仍处于"观望"模式,让早期采用者铺平道路。</p> <h2 id="crossing-the-chasm-means-finding-reference-customers">“跨越鸿沟”意味着找到“标杆客户”</…
Show original
<p>Righty-ho, I&rsquo;m back from Rust Nation, and busily horrifying my teenage daughter with my (admittedly atrocious) attempts at doing an English accent<sup id="fnref:1"><a href="#fn:1" class="footnote-ref" role="doc-noteref">1</a></sup>. It was a great trip with a lot of good conversations and some interesting observations. I am going to try to blog about some of them, starting with some thoughts spurred by Jon Seager&rsquo;s closing keynote, &ldquo;Rust Adoption At Scale with Ubuntu&rdquo;.</p> <h2 id="there-are-many-chasms-out-there">There are many chasms out there</h2> <p>For some time now I&rsquo;ve been debating with myself, has Rust <a href="https://en.wikipedia.org/wiki/Crossing_the_Chasm">&ldquo;crossed the chasm&rdquo;</a>? If you&rsquo;re not familiar with that term, it comes from a book that gives a kind of &ldquo;pop-sci&rdquo; introduction to the <a href="https://en.wikipedia.org/wiki/Technology_adoption_life_cycle">Technology Adoption Life Cycle</a>.</p> <p>The answer…
Read article Original

Dada如何实现内部引用

Translated AI Summary eng
[AI 摘要] 文章阐述了Dada编程语言如何通过基于位置的权限系统实现内部引用,从而解决了Rust中借用数据无法移动的限制。
View content
<p>在我之前的Dada博文中,我讨论了Dada如何实现可组合共享。今天,我将开始深入探讨Dada的<em>权限</em>系统;权限是Dada中相当于Rust借用检查器的机制。</p> <h2 id="goal-richer-place-based-permissions">目标:更丰富的基于位置的权限</h2> <p>Dada旨在通过使用基于位置的权限来超越Rust的能力。Dada允许你编写函数和类型,它们能同时捕获一个<em>值</em>和<em>从该值借用的东西</em>。</p> <p>举个有趣的例子,假设你正在编写一些Rust代码来处理逗号分隔的列表,只查找长度为5或更长的条目:</p> <div class="highlight"><pre tabindex="0" class="chroma"><code class="language-rust" data-lang="rust"><span class="line"><span class="cl"><span class="kd">let</span><span class="w"> </span><span class="n">list</span>: <span class="nb">String</span> <span class="o">=</span><span class="w"> </span><span class="fm">format!</span><span class="p">(</span><span class="s">&#34;...something big, with commas...&#34;</span><span class="p">);</span><span class="w"> </span></span></span><span class="line"><span class="cl"><span class="kd">let</span><span class="w"> </span><span class="n">items</span>: <span class="nb">Vec</span><span class="o">&lt;&amp;</span><span class="kt">str</span><span class="o"…
Show original
<p>In my previous Dada blog post, I talked about how Dada enables composable sharing. Today I&rsquo;m going to start diving into Dada&rsquo;s <em>permission</em> system; permissions are Dada&rsquo;s equivalent to Rust&rsquo;s borrow checker.</p> <h2 id="goal-richer-place-based-permissions">Goal: richer, place-based permissions</h2> <p>Dada aims to exceed Rust&rsquo;s capabilities by using place-based permissions. Dada lets you write functions and types that capture both a <em>value</em> and <em>things borrowed from that value</em>.</p> <p>As a fun example, imagine you are writing some Rust code to process a comma-separated list, just looking for entries of length 5 or more:</p> <div class="highlight"><pre tabindex="0" class="chroma"><code class="language-rust" data-lang="rust"><span class="line"><span class="cl"><span class="kd">let</span><span class="w"> </span><span class="n">list</span>: <span class="nb">String</span> <span class="o">=</span><span class="w"> </span><span class="fm">…
Read article Original

最大化极简视图类型

Translated AI Summary eng
[AI 摘要] 本文提出了“视图类型”特性,旨在通过显式指定方法访问的结构体字段,解决Rust借用检查器中的借用冲突问题。
View content
这篇博客文章描述了一个关于<a href="https://smallcultfollowing.com/babysteps/blog/2021/11/05/view-types/">视图类型</a>的<em>最大化极简提案</em>。它源于我在RustNation大会上与lcnr和Jack Huey的一次对话,我们讨论了各种“悬而未决”的语言改进,这些改进基本上是大家都想做的,以及要使它们成为现实需要什么。 <h2 id="example-messageprocessor">示例:MessageProcessor</h2> <p>让我们从一个简单的例子开始。假设我们有一个结构体 <code>MessageProcessor</code>,它用一组消息创建。它将处理这些消息,并在此过程中收集一些简单的统计数据:</p> <div class="highlight"><pre tabindex="0" class="chroma"><code class="language-rust" data-lang="rust"><span class="line"><span class="cl"><span class="k">pub</span><span class="w"> </span><span class="k">struct</span> <span class="nc">MessageProcessor</span><span class="w"> </span><span class="p">{</span><span class="w"> </span></span></span><span class="line"><span class="cl"><span class="w"> </span><span class="n">messages</span>: <span class="nb">Vec</span><span class="o">&lt;</span><span class="nb">String</span><span class="o">&gt;</span><span class="p">,</span><span class="w"> </span></span></span><span class="line"><spa…
Show original
<p>This blog post describes a <em>maximally minimal proposal</em> for <a href="https://smallcultfollowing.com/babysteps/ /blog/2021/11/05/view-types/">view types</a>. It comes out of a converastion at RustNation I had with lcnr and Jack Huey, where we talking about various improvements to the language that are &ldquo;in the ether&rdquo;, that basically everybody wants to do, and what it would take to get them over the line.</p> <h2 id="example-messageprocessor">Example: MessageProcessor</h2> <p>Let&rsquo;s start with a simple example. Suppose we have a struct <code>MessageProcessor</code> which gets created with a set of messages. It will process them and, along the way, gather up some simple statistics:</p> <div class="highlight"><pre tabindex="0" class="chroma"><code class="language-rust" data-lang="rust"><span class="line"><span class="cl"><span class="k">pub</span><span class="w"> </span><span class="k">struct</span> <span class="nc">MessageProcessor</span><span class="w"> </span><…
Read article Original

极简视图类型,续篇

Translated AI Summary eng
[AI 摘要] 这篇文章是关于 Rust 视图类型设计的后续讨论,探索了使用点语法和强制转换机制来改进结构体字段选择性借用的方案。
View content
一篇短文,用于记录我在上一篇文章中收到的两个有趣建议以及其他一些相关思考。 <h2 id="syntax-with-">使用 <code>.</code> 的语法</h2> <p>有人通过邮件建议我可以使用 <code>.</code> 来消除语法歧义:</p> <div class="highlight"><pre tabindex="0" class="chroma"><code class="language-rust" data-lang="rust"><span class="line"><span class="cl"><span class="kd">let</span><span class="w"> </span><span class="n">place</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="o">&amp;</span><span class="k">mut</span><span class="w"> </span><span class="bp">self</span><span class="p">.{</span><span class="n">statistics</span><span class="p">};</span><span class="w"> </span></span></span></code></pre></div><p>可以设想,我们也可以将此语法用于类型,例如:</p> <div class="highlight"><pre tabindex="0" class="chroma"><code class="language-rust" data-lang="rust"><span class="line"><span class="cl"><span class="k">fn</span> <span class="nf">method</span><span class="p">(</span><span class="w"> </span></span></span><span class="line"><span class="cl"><span class="…
Show original
<p>A short post to catalog two interesting suggestions that came in from my previous post, and some other related musings.</p> <h2 id="syntax-with-">Syntax with <code>.</code></h2> <p>It was suggested to me via email that we could use <code>.</code> to eliminate the syntax ambiguity:</p> <div class="highlight"><pre tabindex="0" class="chroma"><code class="language-rust" data-lang="rust"><span class="line"><span class="cl"><span class="kd">let</span><span class="w"> </span><span class="n">place</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="o">&amp;</span><span class="k">mut</span><span class="w"> </span><span class="bp">self</span><span class="p">.{</span><span class="n">statistics</span><span class="p">};</span><span class="w"> </span></span></span></code></pre></div><p>Conceivably we could do this for the type, like:</p> <div class="highlight"><pre tabindex="0" class="chroma"><code class="language-rust" data-lang="rust"><span class="line"><…
Read article Original

研讨会:面向社区的代理开发

Translated AI Summary eng
[AI 摘要] Symposium项目旨在让Rust crate作者通过提供扩展来改善社区的代理开发体验。
View content
我非常激动地宣布<a href="https://symposium.dev/blog/announcing-symposium.html"><em>Symposium</em>项目的首个版本</a>发布,并且它已<a href="https://rustfoundation.org/media/welcoming-symposium-to-the-rust-innovation-lab/">被纳入Rust基金会的创新实验室</a>。Symposium的目标是让Rust社区中的每个人都能参与改进代理开发。核心理念是crate作者除了代码之外,还应该能够提供技能、MCP服务器和其他扩展。然后,Symposium工具会根据你的依赖关系自动安装这些扩展。毕竟,谁能比维护crate的人更了解如何使用它呢? <p>如果你想了解更多关于Symposium工作原理的细节,请参阅<a href="https://symposium.dev/blog/announcing-symposium.html">Jack Huey在Symposium主博客上发布的公告</a>。<em>本文</em>是我的配套文章,侧重于更个人化的内容——我本人致力于Symposium的原因。</p> <h2 id="i-believe-in-extensibility-everywhere">我相信<em>无处不在的可扩展性</em></h2> <p>简而言之,我相信<strong>无处不在的可扩展性</strong>。目前,Rust语言在可扩展性方面做得相当不错:得益于过程宏、trait和所有权,你可以编写Rust crate,提供感觉像是内置的新功能。但在其他工具方面,我们才刚刚开始提供可扩展性,我希望我们能加快脚步!</p> <p>我希望crate作者能够提供自定义诊断信息。我希望他们能够提供自定义lint。我希望他们能够提供自定义优化。我希望他们能够提供自定义IDE重构。<strong>而且,当我开始尝试代理开发时,我也希望那里也有可扩展性。</strong></p> <h2 id="symposium-puts-crate-authors-in-charge">Symposium让crate作者掌握主动权</h2> <p>Symposium的目标是赋予crate作者以及更广泛的Rust社区直接影响…
Show original
<p>I&rsquo;m very excited to announce the <a href="https://symposium.dev/blog/announcing-symposium.html">first release of the <em>Symposium</em> project</a> as well as its <a href="https://rustfoundation.org/media/welcoming-symposium-to-the-rust-innovation-lab/">inclusion in the Rust Foundation&rsquo;s Innovation Lab</a>. Symposium’s goal is to let everyone in the Rust community participate in making agentic development better. The core idea is that crate authors should be able to vend skills, MCP servers, and other extensions, in addition to code. The Symposium tool then installs those extensions automatically based on your dependencies. After all, who knows how to use a crate better than the people who maintain it?</p> <p>If you want to read more details about how Symposium works, I refer you to the <a href="https://symposium.dev/blog/announcing-symposium.html">announcement post from Jack Huey on the main Symposium blog</a>. <em>This</em> post is my companion post, and it is focused …
Read article Original

只需调用克隆(或别名)

Translated eng
View content
<img src="https://smallcultfollowing.com/babysteps/ /assets/2025-justcallclone/keep-calm-and-call-clone-rendered.svg" width="20%" style="float: right; margin-right: 1em; margin-bottom: 0.5em;" /> <p>在我关于人体工学引用计数的系列文章中,我想探讨另一个想法,我称之为“只需调用克隆(或别名)”。这个提案将特化 <code>clone</code> 和 <code>alias</code> 方法,使得在新的 Rust 版次中,编译器能够:(1)移除冗余或不必要的调用(通过 lint 警告);以及(2)在需要时,自动在 <code>move</code> 闭包中捕获克隆或别名。</p> <p>此提案的目标是简化用户的心理模型:每当遇到“使用已移动的值”之类的错误时,修复方法总是相同的:只需调用 <code>clone</code>(或 <code>alias</code>,如果适用)。该模型旨在达到我之前描述的<a href="https://smallcultfollowing.com/babysteps/ /blog/2025/10/13/ergonomic-explicit-handles/">&ldquo;对内核来说足够底层,对图形用户界面来说足够易用&rdquo;</a>的平衡。它也表明了一个观点:我们要保留的关键属性是<em>你总能发现新别名可能被创建的地方</em> &ndash; 但是,关于<em>确切何时</em>创建别名的细微差别是可以接受的。</p> <!-- more --> <h2 id="the-proposal-in-a-nutshell">提案概要</h2> <h3 id="part-1-closure-desugaring-that-is-aware-of-clones-and-aliases">第一部分:感知克隆与别名的闭包脱糖</h3> <p>考虑以下 <code>move</code> future:</p> <div class="highlight"><pre tabindex="0" class="chroma"><code cla…
Show original
<img src="https://smallcultfollowing.com/babysteps/ /assets/2025-justcallclone/keep-calm-and-call-clone-rendered.svg" width="20%" style="float: right; margin-right: 1em; margin-bottom: 0.5em;" /> <p>Continuing my series on ergonomic ref-counting, I want to explore another idea, one that I&rsquo;m calling &ldquo;just call clone (or alias)&rdquo;. This proposal specializes the <code>clone</code> and <code>alias</code> methods so that, in a new edition, the compiler will (1) remove redundant or unnecessary calls (with a lint); and (2) automatically capture clones or aliases in <code>move</code> closures where needed.</p> <p>The goal of this proposal is to simplify the user&rsquo;s mental model: whenever you see an error like &ldquo;use of moved value&rdquo;, the fix is always the same: just call <code>clone</code> (or <code>alias</code>, if applicable). This model is aiming for the balance of <a href="https://smallcultfollowing.com/babysteps/ /blog/2025/10/13/ergonomic-explicit-handles/">…
Read article Original

显式捕获子句

Translated eng
View content
<p>在我之前关于“符合人体工程学的引用计数”的文章中,我谈到无论我们做什么,都需要一种符合人体工程学的显式句柄创建方式。接下来的几篇文章将探讨我们可能实现这一点的几种方案。</p> <p>本文的重点是<strong>显式捕获子句</strong>,它允许闭包使用一组显式指定的位置进行捕获注解。我认为显式捕获子句是一个不言而喻的好主意,原因我将在下文中阐述,我们绝对应该实现它;但它可能不足以被视为<em>符合人体工程学</em>,因此我将在之后探索更多提案。</p> <h2 id="motivation">动机</h2> <p>Rust 闭包目前工作得很好,但我觉得有几个问题:</p> <ul> <li>教授和理解闭包脱糖是困难的,因为它缺乏一种显式形式。用户必须在脑海中进行脱糖才能理解发生了什么。</li> <li>捕获一个值的“克隆”(或其他可能的转换)没有简洁的语法。</li> <li>对于较长的闭包体,很难精确确定哪些值被捕获以及如何被捕获;你必须在闭包体中搜索对外部变量的引用,考虑遮蔽等。</li> <li>很难形成关于何时需要 <code>move</code> 的直觉。我发现自己会在编译器要求时添加它,但这很烦人。</li> </ul> <h2 id="lets-look-at-a-strawperson-proposal">让我们看一个假设性提案</h2> <p>不久前,我写了一个关于显式捕获子句的提案。实际上,我认为这个提案有很多缺陷,但我仍然要解释它:因为目前它是我知道的唯一一个具体的提案,而且它足以解释如何将显式捕获子句<em>视为</em>实现“显式<em>且</em>符合人体工程学”目标的一个方案。然后,我将介绍我喜欢这个提案的地方以及我不喜欢的地方。</p> <h2 id="begin-with-move">从 <code>move</code> 开始</h2> <p>该提案首先扩展了 <code>move</code> 关键字,允许其后带有一个要捕获的位置列表:</p> <div class="highlight"><pre tabindex="0" class="chroma"><code class="language-rust" data-lang="rust"><span class="line"><span class="cl…
Show original
<p>In my previous post about Ergonomic Ref Counting, I talked about how, whatever else we do, we need a way to have explicit handle creation that is ergonomic. The next few posts are going to explore a few options for how we might do that.</p> <p>This post focuses on <strong>explicit capture clauses</strong>, which would permit closures to be annotated with an explicit set of captured places. My take is that explicit capture clauses are a no brainer, for reasons that I&rsquo;ll cover below, and we should definitely do them; but they may not be enough to be considered <em>ergonomic</em>, so I&rsquo;ll explore more proposals afterwards.</p> <h2 id="motivation">Motivation</h2> <p>Rust closures today work quite well but I see a few problems:</p> <ul> <li>Teaching and understanding closure desugaring is difficult because it lacks an explicit form. Users have to learn to desugar in their heads to understand what&rsquo;s going on.</li> <li>Capturing the &ldquo;clone&rdquo; of a value (or poss…
Read article Original

动态异步trait,第十部分:Box box box

Translated eng
View content
<p>本文略偏离了我的<a href="https://smallcultfollowing.com/babysteps/ /series/rust-in-2025/">Rust 2025系列</a>。我想分享我关于如何支持具有异步函数的trait的<code>dyn Trait</code>的最新思考,特别是如何以与<a href="https://smallcultfollowing.com/babysteps/ /blog/2022/09/18/dyn-async-traits-part-8-the-soul-of-rust/">Rust的灵魂</a>兼容的方式来实现。</p> <h2 id="background-why-is-this-hard">背景:为什么这很困难?</h2> <p>在动态trait中支持<code>async fn</code>是一个棘手的平衡艺术。挑战在于调和人们喜爱Rust的两个关键特性:其表达高层次、高效代码的能力,<em>以及</em>其专注于揭示底层细节。当涉及到trait中的异步函数时,这两者直接冲突,正如我在<a href="https://smallcultfollowing.com/babysteps/ /blog/2021/09/30/dyn-async-traits-part-1/">本系列的第一篇博客文章</a>中解释的那样——那几乎是四年前写的了!(天哪。)</p> <p>要理解这个挑战,请看这个<code>Signal</code> trait示例:</p> <div class="highlight"><pre tabindex="0" class="chroma"><code class="language-rust" data-lang="rust"><span class="line"><span class="cl"><span class="k">trait</span><span class="w"> </span><span class="n">Signal</span><span class="w"> </span><span class="p">{</span><span class="w"> </span></span></span><span class="line"><span c…
Show original
<p>This article is a slight divergence from my <a href="https://smallcultfollowing.com/babysteps/ /series/rust-in-2025/">Rust in 2025</a> series. I wanted to share my latest thinking about how to support <code>dyn Trait</code> for traits with async functions and, in particular how to do so in a way that is compatible with the <a href="https://smallcultfollowing.com/babysteps/ /blog/2022/09/18/dyn-async-traits-part-8-the-soul-of-rust/">soul of Rust</a>.</p> <h2 id="background-why-is-this-hard">Background: why is this hard?</h2> <p>Supporting <code>async fn</code> in dyn traits is a tricky balancing act. The challenge is reconciling two key things people love about Rust: its ability to express high-level, productive code <em>and</em> its focus on revealing low-level details. When it comes to async function in traits, these two things are in direct tension, as I explained in <a href="https://smallcultfollowing.com/babysteps/ /blog/2021/09/30/dyn-async-traits-part-1/">my first blog post in…
Read article Original