<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:atom="http://www.w3.org/2005/Atom" version="2.0">
    <channel>
      <title>Corrode Rust Consulting</title>
      <link>https://corrode.dev</link>
      <description>Friendly, professional Rust consulting and training. Writing content about idiomatic Rust.</description>
      <generator>Zola</generator>
      <language>en</language>
      <atom:link href="https://corrode.dev/rss.xml" rel="self" type="application/rss+xml"/>
      <lastBuildDate>Sat, 14 Mar 2026 00:00:00 +0000</lastBuildDate>
      <item>
          <title>Memory-Unsafe Code Is a Liability</title>
          <pubDate>Fri, 27 Feb 2026 00:00:00 +0000</pubDate>
          <author>Matthias Endler</author>
          <link>https://corrode.dev/blog/memory-safety/</link>
          <guid>https://corrode.dev/blog/memory-safety/</guid>
          <description xml:base="https://corrode.dev/blog/memory-safety/">&lt;p&gt;If you are responsible for software that powers critical infrastructure, handles sensitive data, or ships to customers in regulated markets, you have to pay attention to the regulatory landscape around software security.&lt;&#x2F;p&gt;
&lt;p&gt;Governments around the world are converging on a single message: &lt;strong&gt;memory-unsafe code is a liability&lt;&#x2F;strong&gt;. New regulations, executive guidance, and procurement requirements are making it clear that organizations that don’t act now will face increasing legal, financial, and reputational risk.&lt;&#x2F;p&gt;
&lt;p&gt;Rust eliminates the most common class of security vulnerabilities at compile time. That’s not a marketing claim but a technical property of the language, &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;security.googleblog.com&#x2F;2022&#x2F;12&#x2F;memory-safe-languages-in-android-13.html&quot;&gt;confirmed by Google&lt;&#x2F;a&gt;, &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;msrc.microsoft.com&#x2F;blog&#x2F;2019&#x2F;07&#x2F;we-need-a-safer-systems-programming-language&#x2F;&quot;&gt;Microsoft&lt;&#x2F;a&gt;, and &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;bidenwhitehouse.archives.gov&#x2F;oncd&#x2F;briefing-room&#x2F;2024&#x2F;02&#x2F;26&#x2F;press-release-technical-report&#x2F;&quot;&gt;the White House&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;This article lays out the evidence: the regulatory landscape, the mounting pressure from every direction, and why acting now, with expert guidance, is the smartest insurance policy your organization can buy.&lt;&#x2F;p&gt;</description>
      </item>
      <item>
          <title>Gama Space</title>
          <pubDate>Thu, 22 Jan 2026 00:00:00 +0000</pubDate>
          <author>Matthias Endler</author>
          <link>https://corrode.dev/podcast/s05e09-gama-space/</link>
          <guid>https://corrode.dev/podcast/s05e09-gama-space/</guid>
          <description xml:base="https://corrode.dev/podcast/s05e09-gama-space/">&lt;div&gt;&lt;script id=&quot;letscast-player-0efbeff6&quot; src=&quot;https:&#x2F;&#x2F;letscast.fm&#x2F;podcasts&#x2F;rust-in-production-82281512&#x2F;episodes&#x2F;gama-space-with-sebastian-scholz&#x2F;player.js?size=s&quot;&gt;&lt;&#x2F;script&gt;&lt;&#x2F;div&gt;
&lt;p&gt;Space exploration demands software that is reliable, efficient, and able to operate in the harshest environments imaginable. When a spacecraft deploys a solar sail millions of kilometers from Earth, there’s no room for memory bugs, race conditions, or software failures. This is where Rust’s robustness guarantees become mission-critical.&lt;&#x2F;p&gt;
&lt;p&gt;In this episode, we speak with Sebastian Scholz, an engineer at Gama Space, a French company pioneering solar sail and drag sail technology for spacecraft propulsion and deorbiting. We explore how Rust is being used in aerospace applications, the unique challenges of developing software for space systems, and what it takes to build reliable embedded systems that operate beyond Earth’s atmosphere.&lt;&#x2F;p&gt;
&lt;div class=&quot;info dashed&quot;&gt;
  &lt;div class=&quot;info-header&quot;&gt;
    &lt;i class=&quot;icon icon-info&quot;&gt;&lt;&#x2F;i&gt;
    &lt;h4&gt;Proudly Supported by CodeCrafters&lt;&#x2F;h4&gt;
  &lt;&#x2F;div&gt;
  &lt;p&gt;
    CodeCrafters helps you become proficient in Rust by building real-world,
    production-grade projects. Learn hands-on by creating your own shell, HTTP
    server, Redis, Kafka, Git, SQLite, or DNS service from scratch.
  &lt;&#x2F;p&gt;
  &lt;p&gt;
    Start for free today and enjoy 40% off any paid plan by using
    &lt;a href=&quot;https:&#x2F;&#x2F;app.codecrafters.io&#x2F;join?via=mre&quot;&gt;this link&lt;&#x2F;a&gt;.
  &lt;&#x2F;p&gt;
&lt;&#x2F;div&gt;
&lt;h2 id=&quot;show-notes&quot;&gt;Show Notes&lt;&#x2F;h2&gt;
&lt;h3 id=&quot;about-gama-space&quot;&gt;About Gama Space&lt;&#x2F;h3&gt;
&lt;p&gt;Gama Space is a French aerospace company founded in 2020 and headquartered in Ivry-sur-Seine, France. The company develops space propulsion and orbital technologies with a mission to keep space accessible. Their two main product lines are solar sails for deep space exploration using the sun’s infinite energy, and drag sails—the most effective way to deorbit satellites and combat space debris. After just two years of R&amp;amp;D, Gama successfully launched their satellite on a SpaceX Falcon 9. The Gama Alpha mission is a 6U cubesat weighing just 11 kilograms that deploys a large 73.3m² sail. With 48 employees, Gama is at the forefront of making space exploration more sustainable and accessible.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;about-sebastian-scholz&quot;&gt;About Sebastian Scholz&lt;&#x2F;h3&gt;
&lt;p&gt;Sebastian Scholz is an engineer at Gama Space, where he works on developing software systems for spacecraft propulsion technology. His work involves building reliable, safety-critical embedded systems that must operate flawlessly in the extreme conditions of space. Sebastian brings expertise in systems programming and embedded development to one of the most demanding environments for software engineering.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;links-from-the-episode&quot;&gt;Links From The Episode&lt;&#x2F;h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.satcat.com&#x2F;sats&#x2F;55084&quot;&gt;GAMA-ALPHA&lt;&#x2F;a&gt; - The demonstration satellite launched in January 2023&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;ada-lang.io&#x2F;&quot;&gt;Ada&lt;&#x2F;a&gt; - Safety-focused programming language used in aerospace&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;probe.rs&#x2F;&quot;&gt;probe-rs&lt;&#x2F;a&gt; - Embedded debugging toolkit for Rust&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;hyper.rs&#x2F;&quot;&gt;hyper&lt;&#x2F;a&gt; - Fast and correct HTTP implementation for Rust&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;flutter.dev&#x2F;&quot;&gt;Flutter&lt;&#x2F;a&gt; - Google’s UI toolkit for cross-platform development&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Universal_asynchronous_receiver-transmitter&quot;&gt;UART&lt;&#x2F;a&gt; - Very common low level communication protocol&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Hamming_code&quot;&gt;Hamming Codes&lt;&#x2F;a&gt; - Error correction used to correct bit flips&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Rexus&#x2F;Bexus&quot;&gt;Rexus&#x2F;Bexus&lt;&#x2F;a&gt; - European project for sub-orbital experiments by students&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;embassy.dev&#x2F;&quot;&gt;Embassy&lt;&#x2F;a&gt; - The EMBedded ASsYnchronous framework&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;libcsp&#x2F;libcsp&quot;&gt;CSP&lt;&#x2F;a&gt; - The Cubesat Space Protocol&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;doc.rust-lang.org&#x2F;std&#x2F;num&#x2F;struct.NonZero.html&quot;&gt;std::num::NonZero&lt;&#x2F;a&gt; - A number in Rust that can’t be 0&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;doc.rust-lang.org&#x2F;std&#x2F;ffi&#x2F;struct.CString.html&quot;&gt;std::ffi::CString&lt;&#x2F;a&gt; - A null-byte terminated String&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;corrode.dev&#x2F;podcast&#x2F;s04e07-ksat&#x2F;&quot;&gt;Rust in Production: KSAT&lt;&#x2F;a&gt; - Our episode with Vegard about using Rust for Ground Station operations&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;corrode.dev&#x2F;podcast&#x2F;s03e03-oxide&#x2F;&quot;&gt;Rust in Production: Oxide&lt;&#x2F;a&gt; - Our episode with Steve, mentioning Hubris&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;oxidecomputer&#x2F;hubris&quot;&gt;Hubris&lt;&#x2F;a&gt; - Oxide’s embedded operating system&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;docs.rs&#x2F;zerocopy&#x2F;latest&#x2F;zerocopy&#x2F;&quot;&gt;ZeroCopy&lt;&#x2F;a&gt; - Transmute data in-place without allocations&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;doc.rust-lang.org&#x2F;std&#x2F;mem&#x2F;fn.transmute.html&quot;&gt;std::mem::transmute&lt;&#x2F;a&gt; - Unsafe function to treat a memory section as a different type than before&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h3 id=&quot;official-links&quot;&gt;Official Links&lt;&#x2F;h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.gamaspace.com&#x2F;&quot;&gt;Gama Space Website&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.linkedin.com&#x2F;company&#x2F;gamaspace&#x2F;&quot;&gt;Gama Space on LinkedIn&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.crunchbase.com&#x2F;organization&#x2F;gama-22d7&quot;&gt;Gama Space on Crunchbase&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
</description>
      </item>
      <item>
          <title>Radar</title>
          <pubDate>Thu, 08 Jan 2026 00:00:00 +0000</pubDate>
          <author>Matthias Endler</author>
          <link>https://corrode.dev/podcast/s05e08-radar/</link>
          <guid>https://corrode.dev/podcast/s05e08-radar/</guid>
          <description xml:base="https://corrode.dev/podcast/s05e08-radar/">&lt;div&gt;&lt;script id=&quot;letscast-player-7e84c99d&quot; src=&quot;https:&#x2F;&#x2F;letscast.fm&#x2F;podcasts&#x2F;rust-in-production-82281512&#x2F;episodes&#x2F;radar-with-jeff-kao&#x2F;player.js?size=s&quot;&gt;&lt;&#x2F;script&gt;&lt;&#x2F;div&gt;
&lt;p&gt;Radar processes billions of location events daily, powering geofencing and location APIs for companies like Uber, Lyft, and thousands of other apps.
When their existing infrastructure started hitting performance and cost limits, they built HorizonDB, a specialized database which replaced both Elasticsearch and MongoDB with a custom single binary written in Rust and backed by RocksDB.&lt;&#x2F;p&gt;
&lt;p&gt;In this episode, we dive deep into the technical journey from prototype to production. We talk about RocksDB internals, finite-state transducers, the intricacies of geospatial indexing with Hilbert curves, and why Rust’s type system and performance characteristics made it the perfect choice for rewriting critical infrastructure that processes location data at massive scale.&lt;&#x2F;p&gt;
&lt;div class=&quot;info dashed&quot;&gt;
  &lt;div class=&quot;info-header&quot;&gt;
    &lt;i class=&quot;icon icon-info&quot;&gt;&lt;&#x2F;i&gt;
    &lt;h4&gt;Proudly Supported by CodeCrafters&lt;&#x2F;h4&gt;
  &lt;&#x2F;div&gt;
  &lt;p&gt;
    CodeCrafters helps you become proficient in Rust by building real-world,
    production-grade projects. Learn hands-on by creating your own shell, HTTP
    server, Redis, Kafka, Git, SQLite, or DNS service from scratch.
  &lt;&#x2F;p&gt;
  &lt;p&gt;
    Start for free today and enjoy 40% off any paid plan by using
    &lt;a href=&quot;https:&#x2F;&#x2F;app.codecrafters.io&#x2F;join?via=mre&quot;&gt;this link&lt;&#x2F;a&gt;.
  &lt;&#x2F;p&gt;
&lt;&#x2F;div&gt;
&lt;h2 id=&quot;show-notes&quot;&gt;Show Notes&lt;&#x2F;h2&gt;
&lt;h3 id=&quot;about-radar&quot;&gt;About Radar&lt;&#x2F;h3&gt;
&lt;p&gt;Radar is the leading geofencing and location platform, trusted by companies like Uber, Lyft, and thousands of apps to power location-based experiences. Processing billions of location events daily, Radar provides geofencing APIs, geocoding, and location tracking that enables developers to build powerful location-aware applications. Their infrastructure handles massive scale with a focus on accuracy, performance, and reliability.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;about-jeff-kao&quot;&gt;About Jeff Kao&lt;&#x2F;h3&gt;
&lt;p&gt;Jeff Kao is a Staff Engineer at Radar, where he led the development of HorizonDB, Radar’s geospatial database written in Rust. His work replaced Elasticsearch and MongoDB with a custom Rust stack built on RocksDB, achieving dramatic improvements in performance and cost efficiency. Jeff has deep experience with geospatial systems and previously open-sourced Node.js TypeScript bindings for Google’s S2 library. He holds a degree from the University of Waterloo.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;links-from-the-episode&quot;&gt;Links From The Episode&lt;&#x2F;h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;radar.com&#x2F;blog&#x2F;high-performance-geocoding-in-rust&quot;&gt;Radar Blog: High-Performance Geocoding in Rust&lt;&#x2F;a&gt; - The blog post, which describes Radar’s migration from Elasticsearch and MongoDB to Rust and RocksDB&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;foursquare.com&#x2F;&quot;&gt;FourSquare&lt;&#x2F;a&gt; - The company Jeff worked at before&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.ruby-lang.org&#x2F;&quot;&gt;Ruby&lt;&#x2F;a&gt; - The basis for Rails&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.pagerduty.com&#x2F;&quot;&gt;PagerDuty)&lt;&#x2F;a&gt; - Another company Jeff worked at. Hes’ been around!&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;coffeescript.org&#x2F;&quot;&gt;CoffeeScript&lt;&#x2F;a&gt; - The first big JavaScript alternative before TypeScript&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.scala-lang.org&#x2F;&quot;&gt;Scala&lt;&#x2F;a&gt; - A functional JVM based language&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;MapReduce&quot;&gt;Wikipedia: MapReduce&lt;&#x2F;a&gt; - Distributed application of functional programming&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Algebraic_data_type&quot;&gt;Wikipedia: Algebraic Data Types&lt;&#x2F;a&gt; - The concept behind Rust’s Enums, also present in e.g. Scala&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;kotlinlang.org&#x2F;&quot;&gt;Kotlin&lt;&#x2F;a&gt; - Easier than Scala, better than Java&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;lucene.apache.org&#x2F;&quot;&gt;Apache Lucene&lt;&#x2F;a&gt; - The core of ElasticSearch&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;discord.com&#x2F;blog&#x2F;why-discord-is-switching-from-go-to-rust&quot;&gt;Discord Blog: Why Discord is switching from Go to Rust&lt;&#x2F;a&gt; - Always the #1 result in searches for Rust migrations&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;radar.com&#x2F;blog&#x2F;introducing-horizondb&quot;&gt;Radar Blog: Introducing HorizonDB&lt;&#x2F;a&gt; - A really nice write up of Horizon’s architecture&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;rocksdb.org&#x2F;&quot;&gt;RocksDB&lt;&#x2F;a&gt; - The primary storage layer used in HorizonDB&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;facebook&#x2F;mysql-5.6&quot;&gt;MyRocks&lt;&#x2F;a&gt; - A MySQL Storage Engine using RocksDB, written by Facebook&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;mongodb-partners&#x2F;mongo-rocks&quot;&gt;MongoRocks&lt;&#x2F;a&gt; - A MongoDB Storage Layer using RocksDB&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.cockroachlabs.com&#x2F;&quot;&gt;CockroachDB&lt;&#x2F;a&gt; - PostgreSQL compatible, distributed, SQL Database&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.influxdata.com&#x2F;&quot;&gt;InfluxDB&lt;&#x2F;a&gt; - A timeseries database that used RocksDB at one point, and our very first guest in this Podcast!&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;spacejam&#x2F;sled&quot;&gt;sled&lt;&#x2F;a&gt; - An embedded database written in Rust&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;rust-rocksdb&#x2F;rust-rocksdb&quot;&gt;rocksdb&lt;&#x2F;a&gt; - Rust bindings for RocksDB&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;h3geo.org&#x2F;&quot;&gt;H3&lt;&#x2F;a&gt; - Uber’s Geo Hashing using hexagons&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;s2geometry.io&#x2F;&quot;&gt;S2&lt;&#x2F;a&gt; - Google’s Geo Hashing library&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Hilbert_curve&quot;&gt;Wikipedia: Hilbert Curve&lt;&#x2F;a&gt; - A way to map 2 dimensions onto 1 while retaining proximity&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Finite-state_transducer&quot;&gt;Wikipedia: Finite-State Transducer&lt;&#x2F;a&gt; - A state machine used for efficiently looking up if a word exists in the data set&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a href=&quot;&#x2F;podcast&#x2F;s04e03-astral&#x2F;&quot;&gt;Rust in Production: Astral&lt;&#x2F;a&gt; - Our episode with Charlie Marsh about tooling for the Python ecosystem&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;BurntSushi&quot;&gt;burntsushi&lt;&#x2F;a&gt; - A very prolific Rust developer, now working at Astral&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;BurntSushi&#x2F;fst&quot;&gt;fst&lt;&#x2F;a&gt; - FST crate from burntsushi&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Trie&quot;&gt;Wikipedia: Trie&lt;&#x2F;a&gt; - A tree-structure using common prefixes&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Levenshtein_distance&quot;&gt;Wikipedia: Levenshtein Distance&lt;&#x2F;a&gt; - The number of letters you have to change, add, or remove to turn word a into word b&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;quickwit-oss&#x2F;tantivy&quot;&gt;tantivy&lt;&#x2F;a&gt; - A full-text search engine, written in Rust, inspired by Lucene&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;microsoft&#x2F;LightGBM&quot;&gt;LightGBM&lt;&#x2F;a&gt; - A gradient boosted tree, similar to a decision tree&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;fasttext.cc&#x2F;&quot;&gt;fastText&lt;&#x2F;a&gt; - A text classification library from Meta&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Inverted_index&quot;&gt;Wikipedia: Inverted Index&lt;&#x2F;a&gt; - An index used for e.g. full text search&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Okapi_BM25&quot;&gt;Wikipedia: Okapi BM25&lt;&#x2F;a&gt; - The ranking algorithm used in tantivy&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Tf%E2%80%93idf&quot;&gt;Wikipedia: tf-idf&lt;&#x2F;a&gt; - A classic and simple ranking algorithm&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;RoaringBitmap&#x2F;roaring-rs&quot;&gt;Roaring Bitmaps&lt;&#x2F;a&gt; - A very fast bitset library used in many places&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;corrode.dev&#x2F;blog&#x2F;simple&#x2F;&quot;&gt;corrode.dev: Be Simple&lt;&#x2F;a&gt; - A sentiment right down Matthias’ alley&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;loco.rs&#x2F;&quot;&gt;loco-rs&lt;&#x2F;a&gt; - Rust on Rails&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h3 id=&quot;official-links&quot;&gt;Official Links&lt;&#x2F;h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;radar.com&#x2F;&quot;&gt;Radar&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;radar.com&#x2F;blog&quot;&gt;Radar Blog&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;radar.com&#x2F;documentation&quot;&gt;Radar Documentation&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.linkedin.com&#x2F;in&#x2F;jeffreykao&#x2F;&quot;&gt;Jeff Kao on LinkedIn&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
</description>
      </item>
      <item>
          <title>2025 Holiday Special</title>
          <pubDate>Thu, 25 Dec 2025 00:00:00 +0000</pubDate>
          <author>Matthias Endler</author>
          <link>https://corrode.dev/podcast/s05e07-holiday/</link>
          <guid>https://corrode.dev/podcast/s05e07-holiday/</guid>
          <description xml:base="https://corrode.dev/podcast/s05e07-holiday/">&lt;div&gt;&lt;script id=&quot;letscast-player-43310bc9&quot; src=&quot;https:&#x2F;&#x2F;letscast.fm&#x2F;podcasts&#x2F;rust-in-production-82281512&#x2F;episodes&#x2F;holiday-episode&#x2F;player.js?size=s&quot;&gt;&lt;&#x2F;script&gt;&lt;&#x2F;div&gt;
&lt;p&gt;As we close the chapter on 2025 and celebrate our second year of ‘Rust in Production’, it’s time to reflect on the highlights of the 17 episodes since our last holiday special. We looked at Rust from all angles, from cloud infrastructure to embedded systems, and from robotics to satellite technology. One thing that all these stories have in common is the passion and dedication of the Rust community to build faster, safer, and more reliable software.&lt;&#x2F;p&gt;
&lt;p&gt;In this special episode, we look back at some of the memorable moments from the past year and celebrate Rust’s achievements. This goes beyond the case studies we’ve covered; it’s about the Rust community as a whole and the state of the Rust ecosystem at the end of 2025.&lt;&#x2F;p&gt;
&lt;div class=&quot;info dashed&quot;&gt;
  &lt;div class=&quot;info-header&quot;&gt;
    &lt;i class=&quot;icon icon-info&quot;&gt;&lt;&#x2F;i&gt;
    &lt;h4&gt;Proudly Supported by CodeCrafters&lt;&#x2F;h4&gt;
  &lt;&#x2F;div&gt;
  &lt;p&gt;
    CodeCrafters helps you become proficient in Rust by building real-world,
    production-grade projects. Learn hands-on by creating your own shell, HTTP
    server, Redis, Kafka, Git, SQLite, or DNS service from scratch.
  &lt;&#x2F;p&gt;
  &lt;p&gt;
    Start for free today and enjoy 40% off any paid plan by using
    &lt;a href=&quot;https:&#x2F;&#x2F;app.codecrafters.io&#x2F;join?via=mre&quot;&gt;this link&lt;&#x2F;a&gt;.
  &lt;&#x2F;p&gt;
&lt;&#x2F;div&gt;
&lt;h2 id=&quot;show-notes&quot;&gt;Show Notes&lt;&#x2F;h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.youtube.com&#x2F;watch?v=AkBnXrKmcvw&quot;&gt;Code.Talks Talk&lt;&#x2F;a&gt; - Matthias’ presentation on Rust case studies&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;survey.stackoverflow.co&#x2F;2025&#x2F;technology&#x2F;#admired-and-desired&quot;&gt;Stack Overflow Developer Survey 2025&lt;&#x2F;a&gt; - Rust as most admired language since 1.0 release&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a href=&quot;&#x2F;podcast&#x2F;s03e07-brave&#x2F;&quot;&gt;Brave with Anton Lazarev (S03E07)&lt;&#x2F;a&gt; - Rust as the go-to language&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a href=&quot;&#x2F;podcast&#x2F;s03e08-volvo&#x2F;&quot;&gt;Volvo with Julius Gustavsson (S03E08)&lt;&#x2F;a&gt; - Empowering engineers&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a href=&quot;&#x2F;podcast&#x2F;s04e03-astral&#x2F;&quot;&gt;Astral with Charlie Marsh (S04E03)&lt;&#x2F;a&gt; - Welcoming community leads to huge impact&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a href=&quot;&#x2F;podcast&#x2F;s05e02-scythe&#x2F;&quot;&gt;Scythe with Andrew Tinka (S05E02)&lt;&#x2F;a&gt; - Confidence in what you build&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;lore.kernel.org&#x2F;all&#x2F;2025121614-CVE-2025-68260-558d@gregkh&#x2F;&quot;&gt;Rust4Linux CVE&lt;&#x2F;a&gt; - The first CVE in Rust for Linux&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;social.kernel.org&#x2F;notice&#x2F;B1JLrtkxEBazCPQHDM&quot;&gt;Greg KH post&lt;&#x2F;a&gt; - Context on kernel CVE statistics&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a href=&quot;&#x2F;podcast&#x2F;s02e01-curl&#x2F;&quot;&gt;curl with Daniel Stenberg (S02E01)&lt;&#x2F;a&gt; - Bug reports every three hours, code constantly changes&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;mastodon.social&#x2F;@bagder&#x2F;115501681801742424&quot;&gt;curl statistics&lt;&#x2F;a&gt; - How old code gets rewritten all the time&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a href=&quot;&#x2F;podcast&#x2F;s04e05-tembo&#x2F;&quot;&gt;Tembo with Adam Hendel (S04E05)&lt;&#x2F;a&gt; - Software is never done&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;redis.io&#x2F;blog&#x2F;security-advisory-cve-2025-49844&#x2F;&quot;&gt;Redis CVE-2025-49844&lt;&#x2F;a&gt; - Remote code execution vulnerability from use-after-free&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a href=&quot;&#x2F;podcast&#x2F;s05e05-canonical&#x2F;&quot;&gt;Canonical with John Seager (S05E05)&lt;&#x2F;a&gt; - Ubuntu is optimistic about Rust&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;security.googleblog.com&#x2F;2025&#x2F;11&#x2F;rust-in-android-move-fast-fix-things.html&quot;&gt;Rust in Android&lt;&#x2F;a&gt; - Memory safety vulnerabilities below 20%&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.demandsage.com&#x2F;android-statistics&#x2F;&quot;&gt;Android statistics&lt;&#x2F;a&gt; - 3.9 billion active devices worldwide&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a href=&quot;&#x2F;podcast&#x2F;s05e04-roc&#x2F;&quot;&gt;Roc with Richard Feldman (S05E04)&lt;&#x2F;a&gt; - Focus on the end user&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a href=&quot;&#x2F;podcast&#x2F;s04e02-svix&#x2F;&quot;&gt;Svix with Tom Hacohen (S04E02)&lt;&#x2F;a&gt; - Love it, but compile times…&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a href=&quot;&#x2F;podcast&#x2F;s05e01-prime-video&#x2F;&quot;&gt;Prime Video with Alexandru Ene (S05E01)&lt;&#x2F;a&gt; - Build times need to improve&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;crates.io&#x2F;&quot;&gt;crates.io&lt;&#x2F;a&gt; - 200 billion crate downloads and 200k published crates&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a href=&quot;&#x2F;podcast&#x2F;s05e03-cloudflare&#x2F;&quot;&gt;Cloudflare with Kevin Guthrie and Edward Wang (S05E03)&lt;&#x2F;a&gt; - Ecosystem is fantastic; thanks to all maintainers&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a href=&quot;&#x2F;blog&#x2F;rust-conferences-2026&#x2F;&quot;&gt;Rust Conferences 2026&lt;&#x2F;a&gt; - Complete list of upcoming Rust conferences&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.youtube.com&#x2F;watch?v=aZ5sfhGmEVU&quot;&gt;CodeCrafters Course&lt;&#x2F;a&gt; - Build your own HTTP server in Rust&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;blog.rust-lang.org&#x2F;2025&#x2F;12&#x2F;16&#x2F;Project-Goals-2025-November-Update.md&#x2F;&quot;&gt;Rust Project Goals&lt;&#x2F;a&gt; - November update on 41 active project goals&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;rust-lang&#x2F;cargo&#x2F;issues&#x2F;12207&quot;&gt;cargo-script RFC&lt;&#x2F;a&gt; - Run Rust scripts without full Cargo projects&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;rust-lang&#x2F;rust-project-goals&#x2F;issues&#x2F;389&quot;&gt;Better pin ergonomics RFC&lt;&#x2F;a&gt; - Improving async Rust ergonomics&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a href=&quot;&#x2F;podcast&#x2F;s04e07-ksat&#x2F;&quot;&gt;KSAT with Vegard Sandengen (S04E07)&lt;&#x2F;a&gt; - Make async better&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a href=&quot;&#x2F;podcast&#x2F;s04e06-1password&#x2F;&quot;&gt;1Password with Andrew Burkhart (S04E06)&lt;&#x2F;a&gt; - Make it easier to learn Rust&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;rust-book.cs.brown.edu&#x2F;&quot;&gt;Rust Book by Brown University&lt;&#x2F;a&gt; - Interactive learning resource for Rust&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;rust-lang.github.io&#x2F;rust-clippy&#x2F;master&#x2F;index.html&quot;&gt;Clippy lints&lt;&#x2F;a&gt; - All available linter rules for Rust&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;rust-lang&#x2F;rust-project-goals&#x2F;blob&#x2F;main&#x2F;src&#x2F;2025h2&#x2F;interop-problem-map.md&quot;&gt;C++ and Rust interop&lt;&#x2F;a&gt; - Safer language interoperability initiative&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a href=&quot;&#x2F;podcast&#x2F;s04e01-microsoft&#x2F;&quot;&gt;Microsoft with Victor Ciura (S04E01)&lt;&#x2F;a&gt; - C++ doesn’t have to die for Rust to succeed&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;borrowsanitizer.com&#x2F;&quot;&gt;BorrowSanitizer initiative&lt;&#x2F;a&gt; - LLVM instrumentation for detecting aliasing violations&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;rust-lang&#x2F;rust-project-goals&#x2F;issues&#x2F;118&quot;&gt;Polonius&lt;&#x2F;a&gt; - Next-generation borrow checker&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a href=&quot;&#x2F;podcast&#x2F;s04e04-rust&#x2F;&quot;&gt;Rust with Niko Matsakis (S04E04)&lt;&#x2F;a&gt; - Be excellent to each other (Bill &amp;amp; Ted reference)&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
</description>
      </item>
      <item>
          <title>Rust for Linux</title>
          <pubDate>Thu, 11 Dec 2025 00:00:00 +0000</pubDate>
          <author>Matthias Endler</author>
          <link>https://corrode.dev/podcast/s05e06-rust4linux/</link>
          <guid>https://corrode.dev/podcast/s05e06-rust4linux/</guid>
          <description xml:base="https://corrode.dev/podcast/s05e06-rust4linux/">&lt;div&gt;&lt;script id=&quot;letscast-player-e15636c5&quot; src=&quot;https:&#x2F;&#x2F;letscast.fm&#x2F;podcasts&#x2F;rust-in-production-82281512&#x2F;episodes&#x2F;rust4linux-with-danilo-krummrich&#x2F;player.js?size=s&quot;&gt;&lt;&#x2F;script&gt;&lt;&#x2F;div&gt;
&lt;p&gt;Bringing Rust into the Linux kernel is one of the most ambitious modernization efforts in open source history. The Linux kernel, with its decades of C code and deeply ingrained development practices, is now opening its doors to a memory-safe language. It’s the first time in over 30 years that a new programming language has been officially adopted for kernel development. But the journey is far from straightforward.&lt;&#x2F;p&gt;
&lt;p&gt;In this episode, we speak with Danilo Krummrich, Linux kernel maintainer and Rust for Linux core team member, about the groundbreaking work of integrating Rust into the Linux kernel. Among other things, we talk about the Nova GPU driver, a Rust-based successor to Nouveau for NVIDIA graphics cards, and discuss the technical challenges and cultural shifts required for large-scale Rust adoption in the kernel as well as the future of the Rust4Linux project.&lt;&#x2F;p&gt;
&lt;div class=&quot;info dashed&quot;&gt;
  &lt;div class=&quot;info-header&quot;&gt;
    &lt;i class=&quot;icon icon-info&quot;&gt;&lt;&#x2F;i&gt;
    &lt;h4&gt;Proudly Supported by CodeCrafters&lt;&#x2F;h4&gt;
  &lt;&#x2F;div&gt;
  &lt;p&gt;
    CodeCrafters helps you become proficient in Rust by building real-world,
    production-grade projects. Learn hands-on by creating your own shell, HTTP
    server, Redis, Kafka, Git, SQLite, or DNS service from scratch.
  &lt;&#x2F;p&gt;
  &lt;p&gt;
    Start for free today and enjoy 40% off any paid plan by using
    &lt;a href=&quot;https:&#x2F;&#x2F;app.codecrafters.io&#x2F;join?via=mre&quot;&gt;this link&lt;&#x2F;a&gt;.
  &lt;&#x2F;p&gt;
&lt;&#x2F;div&gt;
&lt;h2 id=&quot;show-notes&quot;&gt;Show Notes&lt;&#x2F;h2&gt;
&lt;h3 id=&quot;about-rust-for-linux&quot;&gt;About Rust for Linux&lt;&#x2F;h3&gt;
&lt;p&gt;Rust for Linux is a project aimed at bringing the Rust programming language into the Linux kernel. Started to improve memory safety and reduce vulnerabilities in kernel code, the project has been gradually building the infrastructure, abstractions, and tooling necessary for Rust to coexist with the kernel’s existing C codebase.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;about-danilo-krummrich&quot;&gt;About Danilo Krummrich&lt;&#x2F;h3&gt;
&lt;p&gt;Danilo Krummrich is a software engineer at Red Hat and a core contributor to the Rust for Linux project. His fundamental contribution to Rust for Linux is the driver-core infrastructure, the foundational framework that makes it possible to write drivers in Rust at all. This includes both C and Rust code that provides the core abstractions for device drivers in the kernel. Danilo is a maintainer for multiple critical kernel subsystems, including Driver Core, DRM (GPUVM, Rust, GPU Scheduler), GPU drivers for NVIDIA GPUs (Nova, Nouveau), Firmware Loader API, as well as Rust bindings for PCI, DMA, and ALLOC. He is the primary developer of the Nova GPU driver, a fully Rust-based driver for modern NVIDIA GPUs.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;links-from-the-episode&quot;&gt;Links From The Episode&lt;&#x2F;h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;source.android.com&#x2F;&quot;&gt;AOSP&lt;&#x2F;a&gt; - The Android Open Source Project&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;lore.kernel.org&#x2F;&quot;&gt;Kernel Mailing Lists&lt;&#x2F;a&gt; - Where the Linux development happens&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;ojeda.dev&#x2F;&quot;&gt;Miguel Ojeda&lt;&#x2F;a&gt; - Rust4Linux maintainer&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;wedsonaf&quot;&gt;Wedson Almeida Filho&lt;&#x2F;a&gt; - Retired Rust4Linux maintainer&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;docs.kernel.org&#x2F;gpu&#x2F;nouveau.html&quot;&gt;nouveau driver&lt;&#x2F;a&gt; - The old driver for NVIDIA GPUs&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Vulkan&quot;&gt;Vulkan&lt;&#x2F;a&gt; - A low level graphics API&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.mesa3d.org&#x2F;&quot;&gt;Mesa&lt;&#x2F;a&gt; - Vulkan and OpenGL implementation for Linux&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Virtual_method_table&quot;&gt;vtable&lt;&#x2F;a&gt; - Indirect function call, a source of headaches in nouveau&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;docs.kernel.org&#x2F;gpu&#x2F;introduction.html&quot;&gt;DRM&lt;&#x2F;a&gt; - Direct Rendering Manager, Linux subsystem for all things graphics&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Monolithic_kernel&quot;&gt;Monolithic Kernel&lt;&#x2F;a&gt; - Linux’ kernel architecture&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;cliffle.com&#x2F;blog&#x2F;rust-typestate&#x2F;&quot;&gt;The Typestate Pattern in Rust&lt;&#x2F;a&gt; - A very nice way to model state machines in Rust&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;crates.io&#x2F;crates&#x2F;pinned-init&quot;&gt;pinned-init&lt;&#x2F;a&gt; - The userspace crate for pin-init&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;rust-lang&#x2F;rustfmt&quot;&gt;rustfmt&lt;&#x2F;a&gt; - Free up space in your brain by not thinking about formatting&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;docs.kernel.org&#x2F;dev-tools&#x2F;kunit&#x2F;index.html&quot;&gt;kunit&lt;&#x2F;a&gt; - Unit testing framework for the kernel&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;doc.rust-lang.org&#x2F;stable&#x2F;core&#x2F;index.html&quot;&gt;Rust core crate&lt;&#x2F;a&gt; - The only part of the Rust Standard Library used in the Linux kernel&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;Gnurou&quot;&gt;Alexandre Courbot&lt;&#x2F;a&gt; - NVIDIA employed co-maintainer of nova-core&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;http:&#x2F;&#x2F;www.kroah.com&#x2F;linux&#x2F;&quot;&gt;Greg Kroah-Hartman&lt;&#x2F;a&gt; - Linux Foundation fellow and major Linux contributor&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;airlied&quot;&gt;Dave Airlie&lt;&#x2F;a&gt; - Maintainer of the DRM tree&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.vim.org&#x2F;&quot;&gt;vim&lt;&#x2F;a&gt; - not even neovim&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;http:&#x2F;&#x2F;www.mutt.org&#x2F;&quot;&gt;mutt&lt;&#x2F;a&gt; - classic terminal e-mail client&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;aerc-mail.org&#x2F;&quot;&gt;aerc&lt;&#x2F;a&gt; - a pretty good terminal e-mail client&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;rust-for-linux.com&#x2F;contact#zulip-chat&quot;&gt;Rust4Linux Zulip&lt;&#x2F;a&gt; - The best entry point for the Rust4Linux community&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h3 id=&quot;official-links&quot;&gt;Official Links&lt;&#x2F;h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;Rust-for-Linux&quot;&gt;Rust for Linux GitHub&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;dakr&quot;&gt;Danilo Krummrich on GitHub&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.linkedin.com&#x2F;in&#x2F;danilo-krummrich-796885153&#x2F;&quot;&gt;Danilo Krummrich on LinkedIn&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
</description>
      </item>
      <item>
          <title>Canonical</title>
          <pubDate>Thu, 27 Nov 2025 00:00:00 +0000</pubDate>
          <author>Matthias Endler</author>
          <link>https://corrode.dev/podcast/s05e05-canonical/</link>
          <guid>https://corrode.dev/podcast/s05e05-canonical/</guid>
          <description xml:base="https://corrode.dev/podcast/s05e05-canonical/">&lt;div&gt;&lt;script id=&quot;letscast-player-84d68eec&quot; src=&quot;https:&#x2F;&#x2F;letscast.fm&#x2F;podcasts&#x2F;rust-in-production-82281512&#x2F;episodes&#x2F;canonical-with-jon-seager-ea273862-48ff-40d8-b3d6-bc85c680a3a6&#x2F;player.js?size=s&quot;&gt;&lt;&#x2F;script&gt;&lt;&#x2F;div&gt;
&lt;p&gt;What does it take to rewrite the foundational components of one of the world’s most popular Linux distributions? Ubuntu serves over 12 million daily desktop users alone, and the systems that power it, from sudo to core utilities, have been running for decades with what Jon Seager, VP of Engineering for Ubuntu at Canonical, calls “shaky underpinnings.”&lt;&#x2F;p&gt;
&lt;p&gt;In this episode, we talk to Jon about the bold decision to “oxidize” Ubuntu’s foundation. We explore why they’re rewriting critical components like sudo in Rust, how they’re managing the immense risk of changing software that millions depend on daily, and what it means to modernize a 20-year-old operating system without breaking the internet.&lt;&#x2F;p&gt;
&lt;div class=&quot;info dashed&quot;&gt;
  &lt;div class=&quot;info-header&quot;&gt;
    &lt;i class=&quot;icon icon-info&quot;&gt;&lt;&#x2F;i&gt;
    &lt;h4&gt;Proudly Supported by CodeCrafters&lt;&#x2F;h4&gt;
  &lt;&#x2F;div&gt;
  &lt;p&gt;
    CodeCrafters helps you become proficient in Rust by building real-world,
    production-grade projects. Learn hands-on by creating your own shell, HTTP
    server, Redis, Kafka, Git, SQLite, or DNS service from scratch.
  &lt;&#x2F;p&gt;
  &lt;p&gt;
    Start for free today and enjoy 40% off any paid plan by using
    &lt;a href=&quot;https:&#x2F;&#x2F;app.codecrafters.io&#x2F;join?via=mre&quot;&gt;this link&lt;&#x2F;a&gt;.
  &lt;&#x2F;p&gt;
&lt;&#x2F;div&gt;
&lt;h2 id=&quot;show-notes&quot;&gt;Show Notes&lt;&#x2F;h2&gt;
&lt;h3 id=&quot;about-canonical&quot;&gt;About Canonical&lt;&#x2F;h3&gt;
&lt;p&gt;Canonical is the company behind Ubuntu, one of the most widely-used Linux distributions in the world. From personal desktops to cloud infrastructure, Ubuntu powers millions of systems globally. Canonical’s mission is to make open source software available to people everywhere, and they’re now pioneering the adoption of Rust in foundational system components to improve security and reliability for the next generation of computing.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;about-jon-seager&quot;&gt;About Jon Seager&lt;&#x2F;h3&gt;
&lt;p&gt;Jon Seager is VP Engineering for Ubuntu at Canonical, where he oversees the Ubuntu Desktop, Server, and Foundations teams. Appointed to this role in January 2025, Jon is driving Ubuntu’s modernization strategy with a focus on Communication, Automation, Process, and Modernisation. His vision includes adopting memory-safe languages like Rust for critical infrastructure components. Before this role, Jon spent three years as VP Engineering building Juju and Canonical’s catalog of charms. He’s passionate about making Ubuntu ready for the next 20 years of computing.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;links-from-the-episode&quot;&gt;Links From The Episode&lt;&#x2F;h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;juju.is&#x2F;&quot;&gt;Juju&lt;&#x2F;a&gt; - Jon’s previous focus, a cloud orchestration tool&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.gnu.org&#x2F;software&#x2F;coreutils&#x2F;&quot;&gt;GNU coretuils&lt;&#x2F;a&gt; - The widest used implementation of commands like ls, rm, cp, and more&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;uutils&#x2F;coreutils&quot;&gt;uutils coreutils&lt;&#x2F;a&gt; - coreutils implementation in Rust&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;trifectatechfoundation&#x2F;sudo-rs&quot;&gt;sudo-rs&lt;&#x2F;a&gt; -  For your Rust based sandwiches needs&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Long-term_support&quot;&gt;LTS&lt;&#x2F;a&gt; - Long Term Support, a release model popularized by Ubuntu&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;git.launchpad.net&#x2F;~juliank&#x2F;+git&#x2F;coreutils-from&#x2F;tree&#x2F;debian&#x2F;coreutils-from-uutils.links?h=main&quot;&gt;coreutils-from-uutils&lt;&#x2F;a&gt; - List of symbolic links used for coreutils on Ubuntu, some still point to the GNU implementation&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;manpages.ubuntu.com&#x2F;manpages&#x2F;noble&#x2F;en&#x2F;man8&#x2F;sudo.8.html#:~:text=%2DE%2C%20%2D%2Dpreserve%2Denv&quot;&gt;man: sudo -E&lt;&#x2F;a&gt; - Example of a feature that sudo-rs does not support&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Single_instruction%2C_multiple_data&quot;&gt;SIMD&lt;&#x2F;a&gt; - Single instruction, multiple data&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;packages.ubuntu.com&#x2F;noble&#x2F;rust-coreutils&quot;&gt;rust-coreutils&lt;&#x2F;a&gt; - The Ubuntu package with all it’s supported CPU platforms listed&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;endler.dev&#x2F;2018&#x2F;fastcat&#x2F;&quot;&gt;fastcat&lt;&#x2F;a&gt; - Matthias’ blogpost about his faster version of &lt;code&gt;cat&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.freedesktop.org&#x2F;software&#x2F;systemd&#x2F;man&#x2F;devel&#x2F;run0.html&quot;&gt;systemd-run0&lt;&#x2F;a&gt; - Alternative approach to sudo from the systemd project&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;apparmor.net&#x2F;&quot;&gt;AppArmor&lt;&#x2F;a&gt; - The Linux Security Module used in Ubuntu&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;linux-pam&#x2F;linux-pam&quot;&gt;PAM&lt;&#x2F;a&gt; - The Pluggable Authentication Modules, which handles all system authentication in Linux&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;sssd.io&#x2F;&quot;&gt;SSSD&lt;&#x2F;a&gt; - Enables LDAP user profiles on Linux machines&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;pendulum-project&#x2F;ntpd-rs&quot;&gt;ntpd-rs&lt;&#x2F;a&gt; - Timesynchronization daemon written in Rust which may land in Ubuntu 26.04&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;trifectatech.org&#x2F;&quot;&gt;Trifecta Tech Foundation&lt;&#x2F;a&gt; - Foundation supporting sudo-rs development&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;sequoia-pgp.org&#x2F;&quot;&gt;Sequioa PGP&lt;&#x2F;a&gt; - OpenPGP tools written in Rust&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;mir-server.io&#x2F;&quot;&gt;Mir&lt;&#x2F;a&gt; - Canonicals wayland compositor library, uses some Rust&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;canonical.com&#x2F;anbox-cloud&quot;&gt;Anbox Cloud&lt;&#x2F;a&gt; - Canonical’s Android streaming platform, includes Rust components&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;morphis&quot;&gt;Simon Fels&lt;&#x2F;a&gt; - Original creator of Anbox and Anbox Cloud team lead at Canonical&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;canonical.com&#x2F;lxd&quot;&gt;LXD&lt;&#x2F;a&gt; - Container and VM hypervisor&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;canonical.com&#x2F;dqlite&quot;&gt;dqlite&lt;&#x2F;a&gt; - SQLite with a replication layer for distributed use cases, potentially being rewritten in Rust&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;rust-for-linux.com&#x2F;&quot;&gt;Rust for Linux&lt;&#x2F;a&gt; - Project to add Rust support to the Linux kernel&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;rust-for-linux.com&#x2F;nova-gpu-driver&quot;&gt;Nova GPU Driver&lt;&#x2F;a&gt; - New Linux OSS driver for NVIDIA GPUs written in Rust&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;ubuntuasahi.org&#x2F;&quot;&gt;Ubuntu Asahi&lt;&#x2F;a&gt; - Community project for Ubuntu on Apple Silicon&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;lists.debian.org&#x2F;debian-devel&#x2F;2025&#x2F;10&#x2F;msg00285.html&quot;&gt;debian-devel: Hard Rust requirements from May onward&lt;&#x2F;a&gt; - Parts of apt are being rewritten in Rust (announced a month after the recording of this episode)&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;pkg.go.dev&#x2F;std&quot;&gt;Go Standard Library&lt;&#x2F;a&gt; - Providing things like network protocols, cryptographic algorithms, and even tools to handle image formats&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;docs.python.org&#x2F;3&#x2F;library&#x2F;&quot;&gt;Python Standard Library&lt;&#x2F;a&gt; - The origin of “batteries included”&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;doc.rust-lang.org&#x2F;stable&#x2F;std&#x2F;index.html#what-is-in-the-standard-library-documentation&quot;&gt;The Rust Standard Library&lt;&#x2F;a&gt; - Basic types, collections, filesystem access, threads, processes, synchronisation, and not much more&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;clap-rs&#x2F;clap&quot;&gt;clap&lt;&#x2F;a&gt; - Superstar library for CLI option parsing&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;serde.rs&#x2F;&quot;&gt;serde&lt;&#x2F;a&gt; - Famous high-level serilization and deserialization interface crate&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h3 id=&quot;official-links&quot;&gt;Official Links&lt;&#x2F;h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;canonical.com&#x2F;&quot;&gt;Canonical&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;ubuntu.com&#x2F;&quot;&gt;Ubuntu&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;jnsgr.uk&#x2F;&quot;&gt;Jon Seager’s Website&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;jnsgr.uk&#x2F;2025&#x2F;02&#x2F;engineering-ubuntu-for-the-next-20-years&#x2F;&quot;&gt;Jon’s Blog: Engineering Ubuntu For The Next 20 Years&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;canonical.com&#x2F;blog&quot;&gt;Canonical Blog&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;ubuntu.com&#x2F;blog&quot;&gt;Ubuntu Blog&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;canonical.com&#x2F;careers&#x2F;engineering&quot;&gt;Canonical Careers: Engineering&lt;&#x2F;a&gt; - Apply your Rust skills in the Linux ecosystem&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
</description>
      </item>
      <item>
          <title>Roc</title>
          <pubDate>Thu, 13 Nov 2025 00:00:00 +0000</pubDate>
          <author>Matthias Endler</author>
          <link>https://corrode.dev/podcast/s05e04-roc/</link>
          <guid>https://corrode.dev/podcast/s05e04-roc/</guid>
          <description xml:base="https://corrode.dev/podcast/s05e04-roc/">&lt;div&gt;&lt;script id=&quot;letscast-player-080f1fca&quot; src=&quot;https:&#x2F;&#x2F;letscast.fm&#x2F;podcasts&#x2F;rust-in-production-82281512&#x2F;episodes&#x2F;roc-with-richard-feldman&#x2F;player.js?size=s&quot;&gt;&lt;&#x2F;script&gt;&lt;&#x2F;div&gt;
&lt;p&gt;Building a new programming language from scratch is a monumental undertaking. In this episode, we talk to Richard Feldman, creator of the Roc programming language, about building a functional language that is fast, friendly, and functional. We discuss why the Roc team moved away from using Rust as a host language and instead is in the process of migrating to Zig. What was the decision-making process like? What can Rust learn from this decision? And how does Zig compare to Rust for this kind of systems programming work?&lt;&#x2F;p&gt;
&lt;div class=&quot;info dashed&quot;&gt;
  &lt;div class=&quot;info-header&quot;&gt;
    &lt;i class=&quot;icon icon-info&quot;&gt;&lt;&#x2F;i&gt;
    &lt;h4&gt;Proudly Supported by CodeCrafters&lt;&#x2F;h4&gt;
  &lt;&#x2F;div&gt;
  &lt;p&gt;
    CodeCrafters helps you become proficient in Rust by building real-world,
    production-grade projects. Learn hands-on by creating your own shell, HTTP
    server, Redis, Kafka, Git, SQLite, or DNS service from scratch.
  &lt;&#x2F;p&gt;
  &lt;p&gt;
    Start for free today and enjoy 40% off any paid plan by using
    &lt;a href=&quot;https:&#x2F;&#x2F;app.codecrafters.io&#x2F;join?via=mre&quot;&gt;this link&lt;&#x2F;a&gt;.
  &lt;&#x2F;p&gt;
&lt;&#x2F;div&gt;
&lt;h2 id=&quot;show-notes&quot;&gt;Show Notes&lt;&#x2F;h2&gt;
&lt;h3 id=&quot;about-roc&quot;&gt;About Roc&lt;&#x2F;h3&gt;
&lt;p&gt;Roc is a fast, friendly, functional programming language currently in alpha development. It’s a single-paradigm functional language with 100% type inference that compiles to machine code or WebAssembly. Roc takes inspiration from Elm but extends those ideas beyond the frontend, introducing innovations like platforms vs applications, opportunistic mutation, and purity inference. The language features static dispatch, a small set of simple primitives that work well together, and excellent compiler error messages. Roc is already being used in production by companies like Vendr, and is supported by a nonprofit foundation with corporate and individual sponsors.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;about-richard-feldman&quot;&gt;About Richard Feldman&lt;&#x2F;h3&gt;
&lt;p&gt;Richard Feldman is the creator of the Roc programming language and author of “Elm in Action.” He works at Zed Industries and has extensive experience with functional programming, particularly Elm. Richard is also the host of Software Unscripted, a weekly podcast featuring casual conversations about code with programming language creators and industry experts. He’s a frequent conference speaker and teacher, with courses available on Frontend Masters. Richard has been a longtime contributor to the functional programming community and previously worked at NoRedInk building large-scale Elm applications.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;links-from-the-episode&quot;&gt;Links From The Episode&lt;&#x2F;h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;ziglang.org&#x2F;&quot;&gt;Zig&lt;&#x2F;a&gt; - Better than Rust?&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;corrode.dev&#x2F;podcast&#x2F;s03e01-zed&#x2F;&quot;&gt;Rust in Production: Zed&lt;&#x2F;a&gt; - Our interview with Richard’s colleague with more details about Zed&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;gist.github.com&#x2F;rtfeldman&#x2F;77fb430ee57b42f5f2ca973a3992532f&quot;&gt;Richards blogpost about migrating from Rust to Zig&lt;&#x2F;a&gt; - Sent in by many listeners&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;elm-lang.org&#x2F;&quot;&gt;Elm&lt;&#x2F;a&gt; - Initial inspiration for Roc&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.noredink.com&#x2F;&quot;&gt;NoRedInk&lt;&#x2F;a&gt; - Richard’s first experience with Elm&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.haskell.org&#x2F;&quot;&gt;Haskell&lt;&#x2F;a&gt; - A workable Elm on the backend substitute&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;ocaml.org&#x2F;&quot;&gt;OCaml&lt;&#x2F;a&gt; - Functional language, but pure functions only encouraged&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;fsharp.org&#x2F;&quot;&gt;F#&lt;&#x2F;a&gt; - Similar shortcomings as OCaml&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;evancz&quot;&gt;Evan Czaplicki&lt;&#x2F;a&gt; - Creator of Elm&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;ghostty.org&#x2F;&quot;&gt;Ghostty&lt;&#x2F;a&gt; - Terminal emulator from Mitchel Hashimoto with lots of code contributions in Zig&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;corrode&#x2F;bumpref&quot;&gt;bumpref&lt;&#x2F;a&gt; - A tiny Rust crate that came out of this discussion, providing &lt;code&gt;Arc::bump()&lt;&#x2F;code&gt;, which is an alias for &lt;code&gt;clone()&lt;&#x2F;code&gt;.&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Resource_acquisition_is_initialization&quot;&gt;RAII&lt;&#x2F;a&gt; - Resource acquisition is initialization, developed for C++, now a core part of Rust&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;frontendmasters.com&#x2F;courses&#x2F;rust&#x2F;&quot;&gt;Frontend Masters: The Rust Programming Language&lt;&#x2F;a&gt; - Richard’s course teaching Rust&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;doc.rust-lang.org&#x2F;rust-by-example&#x2F;conversion&#x2F;from_into.html&quot;&gt;Rust by Example: From and Into&lt;&#x2F;a&gt; - Traits for ergonomic initialising of objects in Rust&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;doc.rust-lang.org&#x2F;stable&#x2F;book&#x2F;ch10-03-lifetime-syntax.html#lifetime-annotations-in-struct-definitions&quot;&gt;The Rust Programming Language: Lifetime Annotations on Struct Definitions&lt;&#x2F;a&gt; - Learn from Roc: try to avoid having lifetime type parameters&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;doc.rust-lang.org&#x2F;rust-by-example&#x2F;std&#x2F;box.html#box-stack-and-heap&quot;&gt;Rust By Example: Box, stack and heap&lt;&#x2F;a&gt; - Putting objects on the heap can slow down your application&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Design_Patterns&quot;&gt;Design Patterns: Elements of Reusable Object-Oriented Software&lt;&#x2F;a&gt; - Seminal book popularising many common patterns in use today, written by the so-called “Gang of Four”&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.youtube.com&#x2F;watch?v=wo84LFzx5nI&quot;&gt;Casey Muratori: The Big OOPs&lt;&#x2F;a&gt; - Game developer explaining why OOP was an obvious mistake for high performance code&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Alan_Kay&quot;&gt;Alan Kay&lt;&#x2F;a&gt; - Coined the term “object-oriented” while developing the Smalltalk language in the 70s&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Niklaus_Wirth&quot;&gt;Niklaus Wirth&lt;&#x2F;a&gt; - Working on Modula, a modular programming language, at the same time&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;kotlinlang.org&#x2F;&quot;&gt;Kotlin&lt;&#x2F;a&gt; - A new and popular language, basically Java++&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;go.dev&#x2F;&quot;&gt;Go&lt;&#x2F;a&gt; - Popular “greenfield” language, i.e. not coupled to an existing language, not using the object oriented paradigm&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;rust-lang&#x2F;rustc_codegen_cranelift&quot;&gt;Cranelift backend for Rust&lt;&#x2F;a&gt; - A faster backend than LLVM, but still not released&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;andrewkelley.me&#x2F;&quot;&gt;Andrew Kelly&lt;&#x2F;a&gt; - Creator of Zig&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;pod.link&#x2F;1602572955&quot;&gt;Software Unscripted&lt;&#x2F;a&gt; - Richard’s Podcast&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.gpui.rs&#x2F;&quot;&gt;GPUI&lt;&#x2F;a&gt; - Zed’s own UI crate&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;AoS_and_SoA&quot;&gt;Structure of Arrays vs Array of structures&lt;&#x2F;a&gt; - A big source of unsafe code in the Rust implementation of Roc&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;ziglang.org&#x2F;documentation&#x2F;0.15.2&#x2F;#comptime&quot;&gt;The Zig Programming Language: comptime&lt;&#x2F;a&gt; - Zig’s replacement for Rust’s proc-macros, with much broader utility&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;docs.rs&#x2F;crabtime&#x2F;latest&#x2F;crabtime&#x2F;&quot;&gt;crabtime&lt;&#x2F;a&gt; - Comptime crate for Rust&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Roc_(mythology)&quot;&gt;Roc&lt;&#x2F;a&gt; - Roc’s namesake, the mythical bird&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;corrode.dev&#x2F;podcast&#x2F;s01e05-tweede-golf&#x2F;&quot;&gt;Rust in Production: Tweede Golf&lt;&#x2F;a&gt; - Podcast episode with Volkert de Vries, one of the first contributors to Roc&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h3 id=&quot;official-links&quot;&gt;Official Links&lt;&#x2F;h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.roc-lang.org&#x2F;&quot;&gt;Roc Programming Language&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;roc-lang&#x2F;roc&quot;&gt;Roc on GitHub&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;rtfeldman&quot;&gt;Richard Feldman on GitHub&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.linkedin.com&#x2F;in&#x2F;rtfeldman&#x2F;&quot;&gt;Richard Feldman on LinkedIn&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;x.com&#x2F;rtfeldman&quot;&gt;Richard Feldman on X&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;pod.link&#x2F;1602572955&quot;&gt;Software Unscripted Podcast&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
</description>
      </item>
      <item>
          <title>Patterns for Defensive Programming in Rust</title>
          <pubDate>Sat, 08 Nov 2025 00:00:00 +0000</pubDate>
          <author>Matthias Endler</author>
          <link>https://corrode.dev/blog/defensive-programming/</link>
          <guid>https://corrode.dev/blog/defensive-programming/</guid>
          <description xml:base="https://corrode.dev/blog/defensive-programming/">&lt;p&gt;I have a hobby.&lt;&#x2F;p&gt;
&lt;p&gt;Whenever I see the comment &lt;code&gt;&#x2F;&#x2F; this should never happen&lt;&#x2F;code&gt; in code, I try to find out the exact conditions under which &lt;em&gt;it could&lt;&#x2F;em&gt; happen.
And in 90% of cases, I find a way to do just that.
More often than not, the developer just hasn’t considered all edge cases or future code changes.&lt;&#x2F;p&gt;
&lt;p&gt;In fact, the reason why I like this comment so much is that it often &lt;strong&gt;marks the exact spot&lt;&#x2F;strong&gt; where strong guarantees fall apart.
Often, violating implicit invariants that aren’t enforced by the compiler are the root cause.&lt;&#x2F;p&gt;
&lt;p&gt;Yes, the compiler prevents memory safety issues, and the standard library is best-in-class.
But even the standard library &lt;a href=&quot;&#x2F;blog&#x2F;pitfalls-of-safe-rust&quot;&gt;has its warts&lt;&#x2F;a&gt; and bugs in business logic can still happen.&lt;&#x2F;p&gt;
&lt;p&gt;All we can work with are hard-learned patterns to write more defensive Rust code, learned throughout years of shipping Rust code to production.
I’m not talking about design patterns here, but rather small idioms, which are rarely documented, but make a big difference in the overall code quality.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;code-smell-indexing-into-a-vector&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#code-smell-indexing-into-a-vector&quot; aria-label=&quot;Anchor link for: code-smell-indexing-into-a-vector&quot;&gt;Code Smell: Indexing Into a Vector&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;p&gt;Here’s some innocent-looking code:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;if !&lt;&#x2F;span&gt;&lt;span&gt;matching_users&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;is_empty&lt;&#x2F;span&gt;&lt;span&gt;() {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    let&lt;&#x2F;span&gt;&lt;span&gt; existing_user&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; = &amp;amp;&lt;&#x2F;span&gt;&lt;span&gt;matching_users[&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt;0&lt;&#x2F;span&gt;&lt;span&gt;];&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;    &#x2F;&#x2F; ...&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;What if you refactor it and forget to keep the &lt;code&gt;is_empty()&lt;&#x2F;code&gt; check?
The problem is that the vector indexing is decoupled from checking the length.
So &lt;code&gt;matching_users[0]&lt;&#x2F;code&gt; can panic at runtime if the vector is empty.&lt;&#x2F;p&gt;
&lt;p&gt;Checking the length and indexing are two separate operations, which can be changed independently.
That’s our first implicit invariant that’s not enforced by the compiler.&lt;&#x2F;p&gt;
&lt;p&gt;If we use slice pattern matching instead, we’ll only get access to the element if the correct &lt;code&gt;match&lt;&#x2F;code&gt; arm is executed.&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;match&lt;&#x2F;span&gt;&lt;span&gt; matching_users&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;as_slice&lt;&#x2F;span&gt;&lt;span&gt;() {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    []&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; todo!&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt;&amp;quot;What to do if no users found!?&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;),&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    [existing_user]&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&amp;gt;&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;  &#x2F;&#x2F; Safe! Compiler guarantees exactly one element&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;        &#x2F;&#x2F; No need to index into the vector,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;        &#x2F;&#x2F; we can directly use `existing_user` here &lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    _&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Err&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;RepositoryError&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;DuplicateUsers&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Note how this automatically uncovered one more edge case: what if the list is empty?
We hadn’t explicitly considered this case before.
The compiler-enforced pattern matching requires us to think about all possible states!
This is a common pattern in all robust Rust code: putting the compiler in charge of enforcing invariants.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;code-smell-lazy-use-of-default&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#code-smell-lazy-use-of-default&quot; aria-label=&quot;Anchor link for: code-smell-lazy-use-of-default&quot;&gt;Code Smell: Lazy use of &lt;code&gt;Default&lt;&#x2F;code&gt;&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;p&gt;When initializing an object with many fields, it’s tempting to use &lt;code&gt;..Default::default()&lt;&#x2F;code&gt; to fill in the rest.
In practice, this is a common source of bugs.
You might forget to explicitly set a new field later when you add it to the struct (thus using the default value instead, which might not be what you want), or you might not be aware of all the fields that are being set to default values.&lt;&#x2F;p&gt;
&lt;p&gt;Instead of this:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;let&lt;&#x2F;span&gt;&lt;span&gt; foo&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Foo&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    field1&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span&gt; value1,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    field2&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span&gt; value2,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    ..&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;Default&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;default&lt;&#x2F;span&gt;&lt;span&gt;()&lt;&#x2F;span&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;  &#x2F;&#x2F; Implicitly sets all other fields&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;};&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Do this:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;let&lt;&#x2F;span&gt;&lt;span&gt; foo&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Foo&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    field1&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span&gt; value1,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    field2&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span&gt; value2,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    field3&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span&gt; value3,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt; &#x2F;&#x2F; Explicitly set all fields&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    field4&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span&gt; value4,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;    &#x2F;&#x2F; ...&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;};&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Yes, it’s slightly more verbose, but what you gain is that the compiler will force you to handle all fields explicitly.
Now when you add a new field to &lt;code&gt;Foo&lt;&#x2F;code&gt;, the compiler will remind you to set it here as well and reflect on which value makes sense.&lt;&#x2F;p&gt;
&lt;p&gt;If you still prefer to use &lt;code&gt;Default&lt;&#x2F;code&gt; but don’t want to lose compiler checks, you can also destructure the default instance:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;let&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Foo&lt;&#x2F;span&gt;&lt;span&gt; { field1, field2, field3, field4 }&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Foo&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;default&lt;&#x2F;span&gt;&lt;span&gt;();&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;This way, you get all the default values assigned to local variables and you can still override what you need:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;let&lt;&#x2F;span&gt;&lt;span&gt; foo&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Foo&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    field1&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span&gt; value1,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;    &#x2F;&#x2F; Override what you need&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    field2&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span&gt; value2,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;    &#x2F;&#x2F; Override what you need&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    field3,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;            &#x2F;&#x2F; Use default value&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    field4,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;            &#x2F;&#x2F; Use default value&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;};&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;This pattern gives you the best of both worlds:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;You get default values without duplicating default logic&lt;&#x2F;li&gt;
&lt;li&gt;The compiler will complain when new fields are added to the struct&lt;&#x2F;li&gt;
&lt;li&gt;Your code automatically adapts when default values change&lt;&#x2F;li&gt;
&lt;li&gt;It’s clear which fields use defaults and which have custom values&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h2 id=&quot;code-smell-fragile-trait-implementations&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#code-smell-fragile-trait-implementations&quot; aria-label=&quot;Anchor link for: code-smell-fragile-trait-implementations&quot;&gt;Code Smell: Fragile Trait Implementations&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;p&gt;Completely destructuring a struct into its components can also be a defensive strategy for API adherence.
For example, let’s say you’re building a pizza ordering system and have an order type like this:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;struct&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; PizzaOrder&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    size&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; PizzaSize&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    toppings&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Vec&lt;&#x2F;span&gt;&lt;span&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;Topping&lt;&#x2F;span&gt;&lt;span&gt;&amp;gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    crust_type&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; CrustType&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    ordered_at&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; SystemTime&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;For your order tracking system, you want to compare orders based on what’s actually on the pizza - the &lt;code&gt;size&lt;&#x2F;code&gt;, &lt;code&gt;toppings&lt;&#x2F;code&gt;, and &lt;code&gt;crust_type&lt;&#x2F;code&gt;. The &lt;code&gt;ordered_at&lt;&#x2F;code&gt; timestamp shouldn’t affect whether two orders are considered the same.&lt;&#x2F;p&gt;
&lt;p&gt;Here’s the problem with the obvious approach:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;impl&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; PartialEq&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; for&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; PizzaOrder&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    fn&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; eq&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;&amp;amp;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;font-style: italic;&quot;&gt;self&lt;&#x2F;span&gt;&lt;span&gt;, other&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;: &amp;amp;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;font-style: italic;&quot;&gt;Self&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; -&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; bool&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #BD93F9;font-style: italic;&quot;&gt;        self&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span&gt;size &lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;==&lt;&#x2F;span&gt;&lt;span&gt; other&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span&gt;size &lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;            &amp;amp;&amp;amp;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;font-style: italic;&quot;&gt; self&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span&gt;toppings &lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;==&lt;&#x2F;span&gt;&lt;span&gt; other&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span&gt;toppings &lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;            &amp;amp;&amp;amp;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;font-style: italic;&quot;&gt; self&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span&gt;crust_type &lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;==&lt;&#x2F;span&gt;&lt;span&gt; other&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span&gt;crust_type&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;            &#x2F;&#x2F; Oops! What happens when we add extra_cheese or delivery_address later?&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Now imagine your team adds a field for customization options:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;struct&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; PizzaOrder&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    size&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; PizzaSize&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    toppings&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Vec&lt;&#x2F;span&gt;&lt;span&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;Topping&lt;&#x2F;span&gt;&lt;span&gt;&amp;gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    crust_type&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; CrustType&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    ordered_at&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; SystemTime&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    extra_cheese&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; bool&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt; &#x2F;&#x2F; New field added&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Your &lt;code&gt;PartialEq&lt;&#x2F;code&gt; implementation still compiles, but is it correct?
Should &lt;code&gt;extra_cheese&lt;&#x2F;code&gt; be part of the equality check?
Probably yes - a pizza with extra cheese is a different order!
But you’ll never know because the compiler won’t remind you to think about it.&lt;&#x2F;p&gt;
&lt;p&gt;Here’s the defensive approach using destructuring:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;impl&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; PartialEq&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; for&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; PizzaOrder&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    fn&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; eq&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;&amp;amp;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;font-style: italic;&quot;&gt;self&lt;&#x2F;span&gt;&lt;span&gt;, other&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;: &amp;amp;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;font-style: italic;&quot;&gt;Self&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; -&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; bool&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;        let&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;font-style: italic;&quot;&gt; Self&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            size,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            toppings,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            crust_type,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            ordered_at&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span&gt; _,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        }&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;font-style: italic;&quot;&gt; self&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;        let&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;font-style: italic;&quot;&gt; Self&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            size&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span&gt; other_size,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            toppings&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span&gt; other_toppings,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            crust_type&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span&gt; other_crust,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            ordered_at&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span&gt; _,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        }&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; other;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        size&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; ==&lt;&#x2F;span&gt;&lt;span&gt; other_size&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; &amp;amp;&amp;amp;&lt;&#x2F;span&gt;&lt;span&gt; toppings&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; ==&lt;&#x2F;span&gt;&lt;span&gt; other_toppings&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; &amp;amp;&amp;amp;&lt;&#x2F;span&gt;&lt;span&gt; crust_type&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; ==&lt;&#x2F;span&gt;&lt;span&gt; other_crust&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Now when someone adds the &lt;code&gt;extra_cheese&lt;&#x2F;code&gt; field, this code won’t compile anymore.
The compiler forces you to decide: should &lt;code&gt;extra_cheese&lt;&#x2F;code&gt; be included in the comparison or explicitly ignored with &lt;code&gt;extra_cheese: _&lt;&#x2F;code&gt;?&lt;&#x2F;p&gt;
&lt;p&gt;This pattern works for any trait implementation where you need to handle struct fields: &lt;code&gt;Hash&lt;&#x2F;code&gt;, &lt;code&gt;Debug&lt;&#x2F;code&gt;, &lt;code&gt;Clone&lt;&#x2F;code&gt;, etc.
It’s especially valuable in codebases where structs evolve frequently as requirements change.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;code-smell-from-impls-that-are-really-tryfrom&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#code-smell-from-impls-that-are-really-tryfrom&quot; aria-label=&quot;Anchor link for: code-smell-from-impls-that-are-really-tryfrom&quot;&gt;Code Smell: &lt;code&gt;From&lt;&#x2F;code&gt; Impls That Are Really &lt;code&gt;TryFrom&lt;&#x2F;code&gt;&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;p&gt;Sometimes there’s no conversion that will work 100% of the time.
That’s fine.
When that’s the case, resist the temptation to offer a &lt;code&gt;From&lt;&#x2F;code&gt; implementation out of habit; use &lt;code&gt;TryFrom&lt;&#x2F;code&gt; instead.&lt;&#x2F;p&gt;
&lt;p&gt;Here’s an example of &lt;code&gt;TryFrom&lt;&#x2F;code&gt; in disguise:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;impl&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; From&lt;&#x2F;span&gt;&lt;span&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;&amp;amp;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;DetectorStartupErrorReport&lt;&#x2F;span&gt;&lt;span&gt;&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; for&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; DetectorStartupErrorSubject&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    fn&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; from&lt;&#x2F;span&gt;&lt;span&gt;(report&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;: &amp;amp;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;DetectorStartupErrorReport&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; -&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;font-style: italic;&quot;&gt; Self&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;        let&lt;&#x2F;span&gt;&lt;span&gt; postfix&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; report&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;            .&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;get_identifier&lt;&#x2F;span&gt;&lt;span&gt;()&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;            .&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;or_else&lt;&#x2F;span&gt;&lt;span&gt;(get_binary_name)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;            .&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;unwrap_or_else&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;||&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt; UNKNOWN_DETECTOR_SUBJECT&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;to_string&lt;&#x2F;span&gt;&lt;span&gt;());&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #BD93F9;font-style: italic;&quot;&gt;        Self&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;StreamSubject&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;from&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;            format!&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt;&amp;quot;apps.errors.detectors.startup.{postfix}&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;as_str&lt;&#x2F;span&gt;&lt;span&gt;(),&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        ))&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;The &lt;code&gt;unwrap_or_else&lt;&#x2F;code&gt; is a hint that this conversion can fail in some way.
We set a default value instead, but is it really the right thing to do for all callers?
This should be a &lt;code&gt;TryFrom&lt;&#x2F;code&gt; implementation instead, making the fallible nature explicit.
We fail fast instead of continuing with a potentially flawed business logic.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;code-smell-non-exhaustive-matches&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#code-smell-non-exhaustive-matches&quot; aria-label=&quot;Anchor link for: code-smell-non-exhaustive-matches&quot;&gt;Code Smell: Non-Exhaustive Matches&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;p&gt;It’s tempting to use &lt;code&gt;match&lt;&#x2F;code&gt; in combination with a catch-all pattern like &lt;code&gt;_ =&amp;gt; {}&lt;&#x2F;code&gt;, but this can haunt you later.
The problem is that you might forget to handle a new case that was added later.&lt;&#x2F;p&gt;
&lt;p&gt;Instead of:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;match&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;font-style: italic;&quot;&gt; self&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #BD93F9;font-style: italic;&quot;&gt;    Self&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;Variant1&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&amp;gt;&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt; &#x2F;* ... *&#x2F;&lt;&#x2F;span&gt;&lt;span&gt; }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #BD93F9;font-style: italic;&quot;&gt;    Self&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;Variant2&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&amp;gt;&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt; &#x2F;* ... *&#x2F;&lt;&#x2F;span&gt;&lt;span&gt; }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    _&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&amp;gt;&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt; &#x2F;* catch-all *&#x2F;&lt;&#x2F;span&gt;&lt;span&gt; }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Use:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;match&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;font-style: italic;&quot;&gt; self&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #BD93F9;font-style: italic;&quot;&gt;    Self&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;Variant1&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&amp;gt;&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt; &#x2F;* ... *&#x2F;&lt;&#x2F;span&gt;&lt;span&gt; }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #BD93F9;font-style: italic;&quot;&gt;    Self&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;Variant2&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&amp;gt;&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt; &#x2F;* ... *&#x2F;&lt;&#x2F;span&gt;&lt;span&gt; }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #BD93F9;font-style: italic;&quot;&gt;    Self&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;Variant3&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&amp;gt;&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt; &#x2F;* ... *&#x2F;&lt;&#x2F;span&gt;&lt;span&gt; }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #BD93F9;font-style: italic;&quot;&gt;    Self&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;Variant4&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&amp;gt;&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt; &#x2F;* ... *&#x2F;&lt;&#x2F;span&gt;&lt;span&gt; }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;By spelling out all variants explicitly, the compiler will warn you when a new variant is added, forcing you to handle it.
Another case of putting the compiler to work.&lt;&#x2F;p&gt;
&lt;p&gt;If the code for two variants is the same, you can group them:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;match&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;font-style: italic;&quot;&gt; self&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #BD93F9;font-style: italic;&quot;&gt;    Self&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;Variant1&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&amp;gt;&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt; &#x2F;* ... *&#x2F;&lt;&#x2F;span&gt;&lt;span&gt; }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #BD93F9;font-style: italic;&quot;&gt;    Self&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;Variant2&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&amp;gt;&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt; &#x2F;* ... *&#x2F;&lt;&#x2F;span&gt;&lt;span&gt; }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #BD93F9;font-style: italic;&quot;&gt;    Self&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;Variant3&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; |&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;font-style: italic;&quot;&gt; Self&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;Variant4&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&amp;gt;&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt; &#x2F;* shared logic *&#x2F;&lt;&#x2F;span&gt;&lt;span&gt; }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;&lt;h2 id=&quot;code-smell-placeholders-for-unused-variables&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#code-smell-placeholders-for-unused-variables&quot; aria-label=&quot;Anchor link for: code-smell-placeholders-for-unused-variables&quot;&gt;Code Smell: &lt;code&gt;_&lt;&#x2F;code&gt; Placeholders for Unused Variables&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;p&gt;Using &lt;code&gt;_&lt;&#x2F;code&gt; as a placeholder for unused variables can lead to confusion.
For example, you might get confused about which variable was skipped.
That’s especially true for boolean flags:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;match&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;font-style: italic;&quot;&gt; self&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #BD93F9;font-style: italic;&quot;&gt;    Self&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;Rocket&lt;&#x2F;span&gt;&lt;span&gt; { _, _,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; ..&lt;&#x2F;span&gt;&lt;span&gt; }&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&amp;gt;&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt; &#x2F;* ... *&#x2F;&lt;&#x2F;span&gt;&lt;span&gt; }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;In the above example, it’s not clear which variables were skipped and why.
Better to use descriptive names for the variables that are not used:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;match&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;font-style: italic;&quot;&gt; self&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #BD93F9;font-style: italic;&quot;&gt;    Self&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;Rocket&lt;&#x2F;span&gt;&lt;span&gt; { has_fuel&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span&gt; _, has_crew&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span&gt; _,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; ..&lt;&#x2F;span&gt;&lt;span&gt; }&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&amp;gt;&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt; &#x2F;* ... *&#x2F;&lt;&#x2F;span&gt;&lt;span&gt; }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Even if you don’t use the variables, it’s clear what they represent and the code becomes more readable and easier to review without inline type hints.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;pattern-temporary-mutability&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#pattern-temporary-mutability&quot; aria-label=&quot;Anchor link for: pattern-temporary-mutability&quot;&gt;Pattern: Temporary Mutability&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;p&gt;If you only want your data to be mutable temporarily, make that explicit.&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;let mut&lt;&#x2F;span&gt;&lt;span&gt; data&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; get_vec&lt;&#x2F;span&gt;&lt;span&gt;();&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;data&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;sort&lt;&#x2F;span&gt;&lt;span&gt;();&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;let&lt;&#x2F;span&gt;&lt;span&gt; data&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; data;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;  &#x2F;&#x2F; Shadow to make immutable&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;&#x2F;&#x2F; Here `data` is immutable.&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;This pattern is often called “temporary mutability” and helps prevent accidental modifications after initialization.
See the &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;rust-unofficial.github.io&#x2F;patterns&#x2F;idioms&#x2F;temporary-mutability.html&quot;&gt;Rust unofficial patterns book&lt;&#x2F;a&gt; for more details.&lt;&#x2F;p&gt;
&lt;p&gt;You can go one step further and do the initialization part in a scope block:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;let&lt;&#x2F;span&gt;&lt;span&gt; data&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    let mut&lt;&#x2F;span&gt;&lt;span&gt; data&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; get_vec&lt;&#x2F;span&gt;&lt;span&gt;();&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    data&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;sort&lt;&#x2F;span&gt;&lt;span&gt;();&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    data&lt;&#x2F;span&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;  &#x2F;&#x2F; Return the final value&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;};&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;&#x2F;&#x2F; Here `data` is immutable&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;This way, the mutable variable is confined to the inner scope, making it clear that it’s only used for initialization.
In case you use any temporary variables during initialization, they won’t leak into the outer scope.
In our case above, there were none, but imagine if we had a temporary vector to hold intermediate results:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;let&lt;&#x2F;span&gt;&lt;span&gt; data&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    let mut&lt;&#x2F;span&gt;&lt;span&gt; data&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; get_vec&lt;&#x2F;span&gt;&lt;span&gt;();&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    let&lt;&#x2F;span&gt;&lt;span&gt; temp&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; compute_something&lt;&#x2F;span&gt;&lt;span&gt;();&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    data&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;extend&lt;&#x2F;span&gt;&lt;span&gt;(temp);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    data&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;sort&lt;&#x2F;span&gt;&lt;span&gt;();&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    data&lt;&#x2F;span&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;  &#x2F;&#x2F; Return the final value&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;};&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Here, &lt;code&gt;temp&lt;&#x2F;code&gt; is only accessible within the inner scope, which prevents it from accidental use later on.&lt;&#x2F;p&gt;
&lt;p&gt;This is especially useful when you have multiple temporary variables during initialization that you don’t want accessible in the rest of the function.
The scope makes it crystal clear that these variables are only meant for initialization.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;pattern-defensively-handle-constructors&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#pattern-defensively-handle-constructors&quot; aria-label=&quot;Anchor link for: pattern-defensively-handle-constructors&quot;&gt;Pattern: Defensively Handle Constructors&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;div class=&quot;info&quot;&gt;
  
  &lt;div class=&quot;info-header&quot;&gt;
    
      &lt;span class=&quot;icon icon-crab&quot;&gt;&lt;&#x2F;span&gt;
    
    &lt;h4&gt;&lt;p&gt;Tip for libraries&lt;&#x2F;p&gt;
&lt;&#x2F;h4&gt;
  &lt;&#x2F;div&gt;
  
  &lt;p&gt;The following pattern is only truly helpful for libraries and APIs that need to be robust against future changes.
In such a case, you want to ensure that all instances of a type are created through a constructor function that enforces validation logic.
Because without that, future refactorings can easily lead to invalid states.&lt;&#x2F;p&gt;
&lt;p&gt;For application code, it’s probably best to keep things simple.
You typically have all the call sites under control and can ensure that validation logic is always called.&lt;&#x2F;p&gt;

&lt;&#x2F;div&gt;
&lt;p&gt;Let’s say you have a simple type like the following:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;pub struct&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; S&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    pub&lt;&#x2F;span&gt;&lt;span&gt; field1&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; String&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    pub&lt;&#x2F;span&gt;&lt;span&gt; field2&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; u32&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Now you want to add validation logic to ensure invalid states are never created.
One pattern is to return a &lt;code&gt;Result&lt;&#x2F;code&gt; from the constructor:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;impl&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; S&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    pub fn&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; new&lt;&#x2F;span&gt;&lt;span&gt;(field1&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; String&lt;&#x2F;span&gt;&lt;span&gt;, field2&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; u32&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; -&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Result&lt;&#x2F;span&gt;&lt;span&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;font-style: italic;&quot;&gt;Self&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; String&lt;&#x2F;span&gt;&lt;span&gt;&amp;gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;        if&lt;&#x2F;span&gt;&lt;span&gt; field1&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;is_empty&lt;&#x2F;span&gt;&lt;span&gt;() {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;            return&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Err&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt;&amp;quot;field1 cannot be empty&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;to_string&lt;&#x2F;span&gt;&lt;span&gt;());&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;        if&lt;&#x2F;span&gt;&lt;span&gt; field2&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; ==&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt; 0&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;            return&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Err&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt;&amp;quot;field2 cannot be zero&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;to_string&lt;&#x2F;span&gt;&lt;span&gt;());&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;        Ok&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;font-style: italic;&quot;&gt;Self&lt;&#x2F;span&gt;&lt;span&gt; { field1, field2 })&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;But nothing stops someone from bypassing your validation by creating an instance directly:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;let&lt;&#x2F;span&gt;&lt;span&gt; s&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; S&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    field1&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt; &amp;quot;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;to_string&lt;&#x2F;span&gt;&lt;span&gt;(),&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    field2&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt; 0&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;};&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;This should not be possible!
It is our implicit invariant that’s not enforced by the compiler: the validation logic is decoupled from struct construction.
These are two separate operations, which can be changed independently and the compiler won’t complain.&lt;&#x2F;p&gt;
&lt;p&gt;To force &lt;strong&gt;external code&lt;&#x2F;strong&gt; to go through your constructor, add a private field:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;pub struct&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; S&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    pub&lt;&#x2F;span&gt;&lt;span&gt; field1&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; String&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    pub&lt;&#x2F;span&gt;&lt;span&gt; field2&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; u32&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    _private&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span&gt; (),&lt;&#x2F;span&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt; &#x2F;&#x2F; This prevents external construction &lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;impl&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; S&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    pub fn&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; new&lt;&#x2F;span&gt;&lt;span&gt;(field1&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; String&lt;&#x2F;span&gt;&lt;span&gt;, field2&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; u32&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; -&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Result&lt;&#x2F;span&gt;&lt;span&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;font-style: italic;&quot;&gt;Self&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; String&lt;&#x2F;span&gt;&lt;span&gt;&amp;gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;        if&lt;&#x2F;span&gt;&lt;span&gt; field1&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;is_empty&lt;&#x2F;span&gt;&lt;span&gt;() {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;            return&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Err&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt;&amp;quot;field1 cannot be empty&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;to_string&lt;&#x2F;span&gt;&lt;span&gt;());&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;        if&lt;&#x2F;span&gt;&lt;span&gt; field2&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; ==&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt; 0&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;            return&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Err&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt;&amp;quot;field2 cannot be zero&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;to_string&lt;&#x2F;span&gt;&lt;span&gt;());&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;        Ok&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;font-style: italic;&quot;&gt;Self&lt;&#x2F;span&gt;&lt;span&gt; { field1, field2, _private&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span&gt; () })&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Now code outside your module cannot construct &lt;code&gt;S&lt;&#x2F;code&gt; directly because it cannot access the &lt;code&gt;_private&lt;&#x2F;code&gt; field.
The compiler enforces that all construction must go through your &lt;code&gt;new()&lt;&#x2F;code&gt; method, which includes your validation logic!&lt;&#x2F;p&gt;
&lt;div class=&quot;info&quot;&gt;
  
  &lt;div class=&quot;info-header&quot;&gt;
    
      &lt;span class=&quot;icon icon-info&quot;&gt;&lt;&#x2F;span&gt;
    
    &lt;h4&gt;&lt;p&gt;Why the underscore in &lt;code&gt;_private&lt;&#x2F;code&gt;?&lt;&#x2F;p&gt;
&lt;&#x2F;h4&gt;
  &lt;&#x2F;div&gt;
  
  &lt;p&gt;Note that the underscore prefix is just a &lt;strong&gt;naming convention&lt;&#x2F;strong&gt; to indicate the field is intentionally unused; it’s the lack of &lt;code&gt;pub&lt;&#x2F;code&gt; that makes it private and prevents external construction.&lt;&#x2F;p&gt;

&lt;&#x2F;div&gt;
&lt;p&gt;For libraries that need to evolve over time, you can also use the &lt;code&gt;#[non_exhaustive]&lt;&#x2F;code&gt; attribute instead:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;#[non_exhaustive]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;pub struct&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; S&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    pub&lt;&#x2F;span&gt;&lt;span&gt; field1&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; String&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    pub&lt;&#x2F;span&gt;&lt;span&gt; field2&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; u32&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;This has the same effect of preventing construction outside your crate, but also signals to users that you might add more fields in the future.
The compiler will prevent them from using struct literal syntax, forcing them to use your constructor.&lt;&#x2F;p&gt;
&lt;div class=&quot;info&quot;&gt;
  
  &lt;div class=&quot;info-header&quot;&gt;
    
      &lt;span class=&quot;icon icon-info&quot;&gt;&lt;&#x2F;span&gt;
    
    &lt;h4&gt;&lt;p&gt;&lt;code&gt;Should you use #[non_exhaustive]&lt;&#x2F;code&gt; or &lt;code&gt;_private&lt;&#x2F;code&gt;?&lt;&#x2F;p&gt;
&lt;&#x2F;h4&gt;
  &lt;&#x2F;div&gt;
  
  &lt;p&gt;There’s a big difference between these two approaches:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;#[non_exhaustive]&lt;&#x2F;code&gt; only works across crate boundaries. &lt;strong&gt;It prevents construction outside your crate.&lt;&#x2F;strong&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;code&gt;_private&lt;&#x2F;code&gt; works at the module boundary. &lt;strong&gt;It prevents construction outside the module&lt;&#x2F;strong&gt;, but within the same crate.&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;On top of that, some developers find &lt;code&gt;_private: ()&lt;&#x2F;code&gt; more explicit about intent: “this struct has a private field that prevents construction.”&lt;&#x2F;p&gt;
&lt;p&gt;With &lt;code&gt;#[non_exhaustive]&lt;&#x2F;code&gt;, the primary intent is signaling that fields might be added in the future, and preventing construction is more of a side effect.&lt;&#x2F;p&gt;

&lt;&#x2F;div&gt;
&lt;p&gt;But what about code within the &lt;strong&gt;same module&lt;&#x2F;strong&gt;?
With the patterns above, code in the same module can still bypass your validation:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;&#x2F;&#x2F; Still compiles in the same module!&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;let&lt;&#x2F;span&gt;&lt;span&gt; s&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; S&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    field1&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt; &amp;quot;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;to_string&lt;&#x2F;span&gt;&lt;span&gt;(),&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    field2&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt; 0&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    _private&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span&gt; (),&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;};&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Rust’s privacy works at the module level, not the type level.
Anything in the same module can access private items.&lt;&#x2F;p&gt;
&lt;p&gt;If you need to enforce constructor usage even within your own module, you need a more defensive approach using nested private modules:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;mod&lt;&#x2F;span&gt;&lt;span&gt; inner {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    pub struct&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; S&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;        pub&lt;&#x2F;span&gt;&lt;span&gt; field1&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; String&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;        pub&lt;&#x2F;span&gt;&lt;span&gt; field2&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; u32&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        _seal&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Seal&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;    &#x2F;&#x2F; This type is private to the inner module&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    struct&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Seal&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    impl&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; S&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;        pub fn&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; new&lt;&#x2F;span&gt;&lt;span&gt;(field1&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; String&lt;&#x2F;span&gt;&lt;span&gt;, field2&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; u32&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; -&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Result&lt;&#x2F;span&gt;&lt;span&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;font-style: italic;&quot;&gt;Self&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; String&lt;&#x2F;span&gt;&lt;span&gt;&amp;gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;            if&lt;&#x2F;span&gt;&lt;span&gt; field1&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;is_empty&lt;&#x2F;span&gt;&lt;span&gt;() {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;                return&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Err&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt;&amp;quot;field1 cannot be empty&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;to_string&lt;&#x2F;span&gt;&lt;span&gt;());&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;            if&lt;&#x2F;span&gt;&lt;span&gt; field2&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; ==&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt; 0&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;                return&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Err&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt;&amp;quot;field2 cannot be zero&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;to_string&lt;&#x2F;span&gt;&lt;span&gt;());&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;            Ok&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;font-style: italic;&quot;&gt;Self&lt;&#x2F;span&gt;&lt;span&gt; { field1, field2, _seal&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Seal&lt;&#x2F;span&gt;&lt;span&gt; })&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;&#x2F;&#x2F; Re-export for public use&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;pub use&lt;&#x2F;span&gt;&lt;span&gt; inner&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;S&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Now even code in your outer module cannot construct &lt;code&gt;S&lt;&#x2F;code&gt; directly because &lt;code&gt;Seal&lt;&#x2F;code&gt; is trapped in the private &lt;code&gt;inner&lt;&#x2F;code&gt; module.
Only the &lt;code&gt;new()&lt;&#x2F;code&gt; method, which lives in the same module as &lt;code&gt;Seal&lt;&#x2F;code&gt;, can construct it.
The compiler guarantees that all construction, even internal construction, goes through your validation logic.&lt;&#x2F;p&gt;
&lt;p&gt;You could still access the public fields directly, though.&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;let&lt;&#x2F;span&gt;&lt;span&gt; s&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; S&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;new&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt;&amp;quot;valid&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;to_string&lt;&#x2F;span&gt;&lt;span&gt;(),&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt; 42&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;unwrap&lt;&#x2F;span&gt;&lt;span&gt;();&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;s&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span&gt;field1 &lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;=&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt; &amp;quot;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;to_string&lt;&#x2F;span&gt;&lt;span&gt;();&lt;&#x2F;span&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt; &#x2F;&#x2F; Still possible to mutate fields directly&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;To prevent that, you can make the fields private and provide getter methods instead:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;mod&lt;&#x2F;span&gt;&lt;span&gt; inner {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    pub struct&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; S&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        field1&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; String&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        field2&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; u32&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        _seal&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Seal&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    struct&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Seal&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    impl&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; S&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;        pub fn&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; new&lt;&#x2F;span&gt;&lt;span&gt;(field1&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; String&lt;&#x2F;span&gt;&lt;span&gt;, field2&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; u32&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; -&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Result&lt;&#x2F;span&gt;&lt;span&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;font-style: italic;&quot;&gt;Self&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; String&lt;&#x2F;span&gt;&lt;span&gt;&amp;gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;            if&lt;&#x2F;span&gt;&lt;span&gt; field1&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;is_empty&lt;&#x2F;span&gt;&lt;span&gt;() {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;                return&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Err&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt;&amp;quot;field1 cannot be empty&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;to_string&lt;&#x2F;span&gt;&lt;span&gt;());&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;            if&lt;&#x2F;span&gt;&lt;span&gt; field2&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; ==&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt; 0&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;                return&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Err&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt;&amp;quot;field2 cannot be zero&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;to_string&lt;&#x2F;span&gt;&lt;span&gt;());&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;            Ok&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;font-style: italic;&quot;&gt;Self&lt;&#x2F;span&gt;&lt;span&gt; { field1, field2, _seal&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Seal&lt;&#x2F;span&gt;&lt;span&gt; })&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;        pub fn&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; field1&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;&amp;amp;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;font-style: italic;&quot;&gt;self&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; -&amp;gt; &amp;amp;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;str&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;            &amp;amp;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;font-style: italic;&quot;&gt;self&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span&gt;field1&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;        pub fn&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; field2&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;&amp;amp;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;font-style: italic;&quot;&gt;self&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; -&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; u32&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #BD93F9;font-style: italic;&quot;&gt;            self&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span&gt;field2&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Now the only way to create an instance of &lt;code&gt;S&lt;&#x2F;code&gt; is through the &lt;code&gt;new()&lt;&#x2F;code&gt; method, and the only way to access its fields is through the getter methods.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;when-to-use-each&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#when-to-use-each&quot; aria-label=&quot;Anchor link for: when-to-use-each&quot;&gt;When to Use Each&lt;&#x2F;a&gt;&lt;&#x2F;h3&gt;
&lt;p&gt;To enforce validation through constructors:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;For external code&lt;&#x2F;strong&gt;: Add a private field like &lt;code&gt;_private: ()&lt;&#x2F;code&gt; or use &lt;code&gt;#[non_exhaustive]&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;For internal code&lt;&#x2F;strong&gt;: Use nested private modules with a private “seal” type&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Choose based on your needs&lt;&#x2F;strong&gt;: Most code only needs to prevent external construction; forcing internal construction is more defensive but also more complex&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;The key insight is that by making construction impossible without access to a private type, you turn your validation logic from a convention into a guarantee enforced by the compiler.
So let’s put that compiler to work!&lt;&#x2F;p&gt;
&lt;h2 id=&quot;pattern-use-must-use-on-important-types&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#pattern-use-must-use-on-important-types&quot; aria-label=&quot;Anchor link for: pattern-use-must-use-on-important-types&quot;&gt;Pattern: Use &lt;code&gt;#[must_use]&lt;&#x2F;code&gt; on Important Types&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;p&gt;The &lt;code&gt;#[must_use]&lt;&#x2F;code&gt; attribute is often neglected.
That’s sad, because it’s such a simple yet powerful mechanism to prevent callers from accidentally ignoring important return values.&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;#[must_use &lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;=&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt; &amp;quot;Configuration must be applied to take effect&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;pub struct&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Config&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;    &#x2F;&#x2F; ...&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;impl&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Config&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    pub fn&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; new&lt;&#x2F;span&gt;&lt;span&gt;()&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; -&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;font-style: italic;&quot;&gt; Self&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;        &#x2F;&#x2F; ...&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    pub fn&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; with_timeout&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;mut&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;font-style: italic;&quot;&gt; self&lt;&#x2F;span&gt;&lt;span&gt;, timeout&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Duration&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; -&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;font-style: italic;&quot;&gt; Self&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #BD93F9;font-style: italic;&quot;&gt;        self&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span&gt;timeout &lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;=&lt;&#x2F;span&gt;&lt;span&gt; timeout;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #BD93F9;font-style: italic;&quot;&gt;        self&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Now if someone creates a &lt;code&gt;Config&lt;&#x2F;code&gt; but forgets to use it, the compiler will warn them
(even with a custom message!):&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;let&lt;&#x2F;span&gt;&lt;span&gt; config&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Config&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;new&lt;&#x2F;span&gt;&lt;span&gt;();&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;&#x2F;&#x2F; Warning: Configuration must be applied to take effect&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;config&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;with_timeout&lt;&#x2F;span&gt;&lt;span&gt;(Duration&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;from_secs&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt;30&lt;&#x2F;span&gt;&lt;span&gt;)); &lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;&#x2F;&#x2F; Correct usage:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;let&lt;&#x2F;span&gt;&lt;span&gt; config&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Config&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;new&lt;&#x2F;span&gt;&lt;span&gt;()&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    .&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;with_timeout&lt;&#x2F;span&gt;&lt;span&gt;(Duration&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;from_secs&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt;30&lt;&#x2F;span&gt;&lt;span&gt;));&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;apply_config&lt;&#x2F;span&gt;&lt;span&gt;(config);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;This is especially useful for guard types that need to be held for their lifetime and results from operations that must be checked.
The standard library uses this extensively.
For example, &lt;code&gt;Result&lt;&#x2F;code&gt; is marked with &lt;code&gt;#[must_use]&lt;&#x2F;code&gt;, which is why you get warnings if you don’t handle errors.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;code-smell-boolean-parameters&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#code-smell-boolean-parameters&quot; aria-label=&quot;Anchor link for: code-smell-boolean-parameters&quot;&gt;Code Smell: Boolean Parameters&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;p&gt;Boolean parameters make code hard to read at the call site and are error-prone.
We all know the scenario where we’re sure this will be the last boolean parameter we’ll ever add to a function.&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;&#x2F;&#x2F; Too many boolean parameters&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;fn&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; process_data&lt;&#x2F;span&gt;&lt;span&gt;(data&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;: &amp;amp;&lt;&#x2F;span&gt;&lt;span&gt;[&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;u8&lt;&#x2F;span&gt;&lt;span&gt;], compress&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; bool&lt;&#x2F;span&gt;&lt;span&gt;, encrypt&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; bool&lt;&#x2F;span&gt;&lt;span&gt;, validate&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; bool&lt;&#x2F;span&gt;&lt;span&gt;) {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;    &#x2F;&#x2F; ...&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;&#x2F;&#x2F; At the call site, what do these booleans mean?&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;process_data&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;&amp;amp;&lt;&#x2F;span&gt;&lt;span&gt;data,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt; true&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt; false&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt; true&lt;&#x2F;span&gt;&lt;span&gt;);&lt;&#x2F;span&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;  &#x2F;&#x2F; What does this do?&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;It’s impossible to understand what this code does without looking at the function signature.
Even worse, it’s easy to accidentally swap the boolean values.&lt;&#x2F;p&gt;
&lt;p&gt;Instead, use enums to make the intent explicit:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;enum&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Compression&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;    Strong&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;    Medium&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;    None&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;enum&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Encryption&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt;    AES&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;    ChaCha20&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;    None&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;enum&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Validation&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;    Enabled&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;    Disabled&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;fn&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; process_data&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    data&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;: &amp;amp;&lt;&#x2F;span&gt;&lt;span&gt;[&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;u8&lt;&#x2F;span&gt;&lt;span&gt;],&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    compression&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Compression&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    encryption&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Encryption&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    validation&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Validation&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;) {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;    &#x2F;&#x2F; ...&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;&#x2F;&#x2F; Now the call site is self-documenting&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;process_data&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    &amp;amp;&lt;&#x2F;span&gt;&lt;span&gt;data,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    Compression&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;Strong&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    Encryption&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;None&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    Validation&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;Enabled&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;This is much more readable and the compiler will catch mistakes if you pass the wrong enum type.
You will notice that the enum variants can be more descriptive than just &lt;code&gt;true&lt;&#x2F;code&gt; or &lt;code&gt;false&lt;&#x2F;code&gt;.
And more often than not, there are more than two meaningful options; especially for programs which grow over time.&lt;&#x2F;p&gt;
&lt;p&gt;For functions with many options, you can configure them using a parameter struct:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;struct&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; ProcessDataParams&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    compression&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Compression&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    encryption&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Encryption&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    validation&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Validation&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;impl&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; ProcessDataParams&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;    &#x2F;&#x2F; Common configurations as constructor methods&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    pub fn&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; production&lt;&#x2F;span&gt;&lt;span&gt;()&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; -&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;font-style: italic;&quot;&gt; Self&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #BD93F9;font-style: italic;&quot;&gt;        Self&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            compression&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Compression&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;Strong&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            encryption&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Encryption&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt;AES&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            validation&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Validation&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;Enabled&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    pub fn&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; development&lt;&#x2F;span&gt;&lt;span&gt;()&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; -&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;font-style: italic;&quot;&gt; Self&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #BD93F9;font-style: italic;&quot;&gt;        Self&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            compression&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Compression&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;None&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            encryption&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Encryption&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;None&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            validation&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Validation&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;Enabled&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;fn&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; process_data&lt;&#x2F;span&gt;&lt;span&gt;(data&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;: &amp;amp;&lt;&#x2F;span&gt;&lt;span&gt;[&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;u8&lt;&#x2F;span&gt;&lt;span&gt;], params&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; ProcessDataParams&lt;&#x2F;span&gt;&lt;span&gt;) {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;    &#x2F;&#x2F; ...&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;&#x2F;&#x2F; Usage with preset configurations&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;process_data&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;&amp;amp;&lt;&#x2F;span&gt;&lt;span&gt;data, ProcessDataParams&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;production&lt;&#x2F;span&gt;&lt;span&gt;());&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;&#x2F;&#x2F; Or customize for specific needs&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;process_data&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;&amp;amp;&lt;&#x2F;span&gt;&lt;span&gt;data,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; ProcessDataParams&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    compression&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span&gt; Compression&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;Medium&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    encryption&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span&gt; Encryption&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;ChaCha20&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    validation&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span&gt; Validation&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;Enabled&lt;&#x2F;span&gt;&lt;span&gt;, &lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;});&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;This approach scales much better as your function evolves.
Adding new parameters doesn’t break existing call sites, and you can easily add defaults or make certain fields optional.
The preset methods also document common use cases and make it easy to use the right configuration for different scenarios.&lt;&#x2F;p&gt;
&lt;p&gt;Rust is often criticized for not having named parameters, but using a parameter struct is arguably even better for larger functions with many options.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;clippy-lints-for-defensive-programming&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#clippy-lints-for-defensive-programming&quot; aria-label=&quot;Anchor link for: clippy-lints-for-defensive-programming&quot;&gt;Clippy Lints for Defensive Programming&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;p&gt;Many of these patterns can be enforced automatically using Clippy lints.
Here are the most relevant ones:&lt;&#x2F;p&gt;
&lt;table&gt;&lt;thead&gt;&lt;tr&gt;&lt;th&gt;Lint&lt;&#x2F;th&gt;&lt;th&gt;Description&lt;&#x2F;th&gt;&lt;&#x2F;tr&gt;&lt;&#x2F;thead&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;rust-lang.github.io&#x2F;rust-clippy&#x2F;master&#x2F;index.html#indexing_slicing&quot;&gt;&lt;code&gt;clippy::indexing_slicing&lt;&#x2F;code&gt;&lt;&#x2F;a&gt;&lt;&#x2F;td&gt;&lt;td&gt;Prevents direct indexing into slices and vectors&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;rust-lang.github.io&#x2F;rust-clippy&#x2F;master&#x2F;index.html#fallible_impl_from&quot;&gt;&lt;code&gt;clippy::fallible_impl_from&lt;&#x2F;code&gt;&lt;&#x2F;a&gt;&lt;&#x2F;td&gt;&lt;td&gt;Warns about &lt;code&gt;From&lt;&#x2F;code&gt; implementations that can panic and should be &lt;code&gt;TryFrom&lt;&#x2F;code&gt; instead.&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;rust-lang.github.io&#x2F;rust-clippy&#x2F;master&#x2F;index.html#wildcard_enum_match_arm&quot;&gt;&lt;code&gt;clippy::wildcard_enum_match_arm&lt;&#x2F;code&gt;&lt;&#x2F;a&gt;&lt;&#x2F;td&gt;&lt;td&gt;Disallows wildcard &lt;code&gt;_&lt;&#x2F;code&gt; patterns.&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;rust-lang.github.io&#x2F;rust-clippy&#x2F;master&#x2F;index.html#unneeded_field_pattern&quot;&gt;&lt;code&gt;clippy::unneeded_field_pattern&lt;&#x2F;code&gt;&lt;&#x2F;a&gt;&lt;&#x2F;td&gt;&lt;td&gt;Identifies when you’re ignoring too many struct fields with &lt;code&gt;..&lt;&#x2F;code&gt; unnecessarily.&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;rust-lang.github.io&#x2F;rust-clippy&#x2F;master&#x2F;index.html#fn_params_excessive_bools&quot;&gt;&lt;code&gt;clippy::fn_params_excessive_bools&lt;&#x2F;code&gt;&lt;&#x2F;a&gt;&lt;&#x2F;td&gt;&lt;td&gt;Warns when a function has too many boolean parameters (4 or more by default).&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;rust-lang.github.io&#x2F;rust-clippy&#x2F;master&#x2F;index.html#must_use_candidate&quot;&gt;&lt;code&gt;clippy::must_use_candidate&lt;&#x2F;code&gt;&lt;&#x2F;a&gt;&lt;&#x2F;td&gt;&lt;td&gt;Suggests adding &lt;code&gt;#[must_use]&lt;&#x2F;code&gt; to types that are good candidates for it.&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;&#x2F;tbody&gt;&lt;&#x2F;table&gt;
&lt;p&gt;You can enable these in your project by adding them at the top of your crate, e.g.&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;#![deny(clippy&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span&gt;indexing_slicing)]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;#![deny(clippy&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span&gt;fallible_impl_from)]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;#![deny(clippy&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span&gt;wildcard_enum_match_arm)]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;#![deny(clippy&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span&gt;unneeded_field_pattern)]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;#![deny(clippy&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span&gt;fn_params_excessive_bools)]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;#![deny(clippy&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span&gt;must_use_candidate)]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Or in your &lt;code&gt;Cargo.toml&lt;&#x2F;code&gt;:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;toml&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;[&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;&quot;&gt;lints&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;&quot;&gt;clippy&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #8BE9FD;&quot;&gt;indexing_slicing&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E9F284;&quot;&gt; &amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt;deny&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E9F284;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #8BE9FD;&quot;&gt;fallible_impl_from&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E9F284;&quot;&gt; &amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt;deny&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E9F284;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #8BE9FD;&quot;&gt;wildcard_enum_match_arm&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E9F284;&quot;&gt; &amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt;deny&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E9F284;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #8BE9FD;&quot;&gt;unneeded_field_pattern&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E9F284;&quot;&gt; &amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt;deny&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E9F284;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #8BE9FD;&quot;&gt;fn_params_excessive_bools&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E9F284;&quot;&gt; &amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt;deny&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E9F284;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #8BE9FD;&quot;&gt;must_use_candidate&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E9F284;&quot;&gt; &amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt;deny&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E9F284;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;&lt;h2 id=&quot;conclusion&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#conclusion&quot; aria-label=&quot;Anchor link for: conclusion&quot;&gt;Conclusion&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;p&gt;Defensive programming in Rust is about leveraging the type system and compiler to catch bugs before they happen.
By following these patterns, you can:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;Make implicit invariants explicit and compiler-checked&lt;&#x2F;li&gt;
&lt;li&gt;Future-proof your code against refactoring mistakes&lt;&#x2F;li&gt;
&lt;li&gt;Reduce the surface area for bugs&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;It’s a skill that doesn’t come naturally and it’s not covered in most Rust books, but knowing these patterns can make the difference between code that works but is brittle, and code that is robust and maintainable for years to come.&lt;&#x2F;p&gt;
&lt;p&gt;Remember: if you find yourself writing &lt;code&gt;&#x2F;&#x2F; this should never happen&lt;&#x2F;code&gt;, take a step back and ask how the compiler could enforce that invariant for you instead.
The best bug is the one that never compiles in the first place.&lt;&#x2F;p&gt;
</description>
      </item>
      <item>
          <title>Cloudflare</title>
          <pubDate>Thu, 30 Oct 2025 00:00:00 +0000</pubDate>
          <author>Matthias Endler</author>
          <link>https://corrode.dev/podcast/s05e03-cloudflare/</link>
          <guid>https://corrode.dev/podcast/s05e03-cloudflare/</guid>
          <description xml:base="https://corrode.dev/podcast/s05e03-cloudflare/">&lt;div&gt;&lt;script id=&quot;letscast-player-1126fbc7&quot; src=&quot;https:&#x2F;&#x2F;letscast.fm&#x2F;podcasts&#x2F;rust-in-production-82281512&#x2F;episodes&#x2F;cloudflare-with-edward-wang-kevin-guthrie&#x2F;player.js?size=s&quot;&gt;&lt;&#x2F;script&gt;&lt;&#x2F;div&gt;
&lt;p&gt;How do you build a system that handles 90 million requests per second? That’s the scale that Cloudflare operates at, processing roughly 25% of all internet traffic through their global network of 330+ edge locations.&lt;&#x2F;p&gt;
&lt;p&gt;In this episode, we talk to Kevin Guthrie and Edward Wang from Cloudflare about Pingora, their open-source Rust-based proxy that replaced nginx across their entire infrastructure. We’ll find out why they chose Rust for mission-critical systems handling such massive scale, the technical challenges of replacing battle-tested infrastructure, and the lessons learned from “oxidizing” one of the internet’s largest networks.&lt;&#x2F;p&gt;
&lt;div class=&quot;info dashed&quot;&gt;
  &lt;div class=&quot;info-header&quot;&gt;
    &lt;i class=&quot;icon icon-info&quot;&gt;&lt;&#x2F;i&gt;
    &lt;h4&gt;Proudly Supported by CodeCrafters&lt;&#x2F;h4&gt;
  &lt;&#x2F;div&gt;
  &lt;p&gt;
    CodeCrafters helps you become proficient in Rust by building real-world,
    production-grade projects. Learn hands-on by creating your own shell, HTTP
    server, Redis, Kafka, Git, SQLite, or DNS service from scratch.
  &lt;&#x2F;p&gt;
  &lt;p&gt;
    Start for free today and enjoy 40% off any paid plan by using
    &lt;a href=&quot;https:&#x2F;&#x2F;app.codecrafters.io&#x2F;join?via=mre&quot;&gt;this link&lt;&#x2F;a&gt;.
  &lt;&#x2F;p&gt;
&lt;&#x2F;div&gt;
&lt;h2 id=&quot;show-notes&quot;&gt;Show Notes&lt;&#x2F;h2&gt;
&lt;h3 id=&quot;about-cloudflare&quot;&gt;About Cloudflare&lt;&#x2F;h3&gt;
&lt;p&gt;Cloudflare is a global network designed to make everything you connect to the Internet secure, private, fast, and reliable. Their network spans 330+ cities worldwide and handles approximately 25% of all internet traffic. Cloudflare provides a range of services including DDoS protection, CDN, DNS, and serverless computing—all built on infrastructure that processes billions of requests every day.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;about-kevin-guthrie&quot;&gt;About Kevin Guthrie&lt;&#x2F;h3&gt;
&lt;p&gt;Kevin Guthrie is a Software Architect and Principal Distributed Systems Engineer at Cloudflare working on Pingora and the production services built upon it. He specializes in performance optimization at scale. Kevin has deep expertise in building high-performance systems and has contributed to open-source projects that power critical internet infrastructure.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;about-edward-wang&quot;&gt;About Edward Wang&lt;&#x2F;h3&gt;
&lt;p&gt;Edward Wang is a Systems Engineer at Cloudflare who has been instrumental in developing Pingora, Cloudflare’s Rust-based HTTP proxy framework. He co-authored the announcement of Pingora’s open source release. Edward’s work focuses on performance optimization, security, and building developer-friendly APIs for network programming.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;links-from-the-episode&quot;&gt;Links From The Episode&lt;&#x2F;h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;cloudflare&#x2F;pingora&quot;&gt;Pingora&lt;&#x2F;a&gt; - Serving 90+ million requests per second (7e12 per day) at Cloudflare&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;blog.cloudflare.com&#x2F;how-we-built-pingora-the-proxy-that-connects-cloudflare-to-the-internet&#x2F;&quot;&gt;How we built Pingora&lt;&#x2F;a&gt; - Cloudflare blog post on Pingora’s architecture&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;blog.cloudflare.com&#x2F;pingora-open-source&#x2F;&quot;&gt;Open sourcing Pingora&lt;&#x2F;a&gt; - Announcement of Pingora’s open source release&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a href=&quot;&#x2F;podcast&#x2F;s03e03-oxide&#x2F;&quot;&gt;Rust in Production: Oxide&lt;&#x2F;a&gt; - Interview with Steve Klabnik&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.cloudflare.com&#x2F;learning&#x2F;cdn&#x2F;glossary&#x2F;anycast-network&#x2F;&quot;&gt;Anycast&lt;&#x2F;a&gt; - Routing traffic to the closest point of presence&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.lua.org&#x2F;&quot;&gt;Lua&lt;&#x2F;a&gt; - A small, embeddable scripting language&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;nginx.org&#x2F;&quot;&gt;nginx&lt;&#x2F;a&gt; - The HTTP server and reverse proxy that Pingora replaced&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Core_dump&quot;&gt;coredump&lt;&#x2F;a&gt; - File capturing the memory of a running process for debugging&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;openresty.org&#x2F;en&#x2F;nginx.html&quot;&gt;OpenResty&lt;&#x2F;a&gt; - Extending nginx with Lua&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;blog.cloudflare.com&#x2F;introducing-oxy&#x2F;&quot;&gt;Oxy&lt;&#x2F;a&gt; - Another proxy developed at Cloudflare in Rust&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;ashleygwilliams&quot;&gt;Ashley Williams&lt;&#x2F;a&gt; - Famous Rust developer who worked at Cloudflare at one point&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;eaufavor&quot;&gt;Yuchen Wu&lt;&#x2F;a&gt; - One of the first drivers of Pingora development&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;andrewhavck&#x2F;&quot;&gt;Andrew Hauck&lt;&#x2F;a&gt; - Early driver of Pingora development&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Pingora_Peak&quot;&gt;Pingora Peak&lt;&#x2F;a&gt; - The actual mountain in Wyoming where a Cloudflare product manager almost fell off&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;cloudflare&#x2F;shellflip&quot;&gt;shellflip&lt;&#x2F;a&gt; - Graceful process restarter in Rust, used by Pingora&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;cloudflare&#x2F;tableflip&quot;&gt;tableflip&lt;&#x2F;a&gt; - Go library that inspired shellflip&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;tokio-rs&#x2F;bytes&quot;&gt;bytes&lt;&#x2F;a&gt; - Reference-counted byte buffers for Rust&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;doc.rust-lang.org&#x2F;cargo&#x2F;reference&#x2F;specifying-dependencies.html#specifying-dependencies-from-git-repositories&quot;&gt;The Cargo Book: Specifying dependencies from git repositories&lt;&#x2F;a&gt; - Who needs a registry anyway?&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;rustsec&#x2F;rustsec&quot;&gt;cargo audit&lt;&#x2F;a&gt; - Security vulnerability scanner for Rust dependencies&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Epoll&quot;&gt;epoll&lt;&#x2F;a&gt; - Async I&#x2F;O API in Linux&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;tokio.rs&#x2F;&quot;&gt;Tokio&lt;&#x2F;a&gt; - The async runtime powering Pingora&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;tokio-rs&#x2F;mio&quot;&gt;mio&lt;&#x2F;a&gt; - Tokio’s abstraction over epoll and other async I&#x2F;O OS interfaces&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;Noah-Kennedy&quot;&gt;Noah Kennedy&lt;&#x2F;a&gt; - An actual Tokio expert on the Pingora team&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;youtu.be&#x2F;zrv5Cy1R7r4&quot;&gt;Rain: Cancelling Async Rust&lt;&#x2F;a&gt; - RustConf 2025 talk with many examples of pitfalls&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;cloudflare&#x2F;foundations&quot;&gt;foundations&lt;&#x2F;a&gt; - Cloudflare’s foundational crate for Rust project that exposes Tokio internal metrics&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Io_uring&quot;&gt;io_uring&lt;&#x2F;a&gt; - Shiny new kernel toy for async I&#x2F;O&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.youtube.com&#x2F;watch?v=xV4rLfpidIk&amp;amp;t=111s&quot;&gt;ThePrimeTime: Cloudflare - Trie Hard - Big Savings On Cloud&lt;&#x2F;a&gt; - “It’s not a millie, it’s not a billie, it’s a trillie”&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;tokio-rs&#x2F;valuable&quot;&gt;valuable&lt;&#x2F;a&gt; - Invaluable crate for introspection of objects for logging and tracing&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;tokio-rs&#x2F;bytes&quot;&gt;bytes&lt;&#x2F;a&gt; - Very foundational crate for reference counted byte buffers&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;xacrimon&#x2F;dashmap&quot;&gt;DashMap&lt;&#x2F;a&gt; - Concurrent HashMap with as little lock contention as possible&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.memorysafety.org&#x2F;about&#x2F;&quot;&gt;Prossimo&lt;&#x2F;a&gt; - Initiative for memory safety in critical internet infrastructure&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.memorysafety.org&#x2F;initiative&#x2F;reverse-proxy&#x2F;&quot;&gt;River&lt;&#x2F;a&gt; - Prossimo-funded reverse proxy based on Pingora&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;rustls&#x2F;rustls&quot;&gt;Rustls&lt;&#x2F;a&gt; - Memory-safe TLS implementation in Rust, also funded by Prossimo&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;docs.rs&#x2F;http&#x2F;latest&#x2F;http&#x2F;&quot;&gt;http crate&lt;&#x2F;a&gt; - HTTP types for Rust&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;hyperium&#x2F;h2&quot;&gt;h2&lt;&#x2F;a&gt; - HTTP&#x2F;2 implementation in Rust&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;hyper.rs&#x2F;&quot;&gt;hyper&lt;&#x2F;a&gt; - Fast HTTP implementation for Rust&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;clickhouse.com&#x2F;docs&#x2F;integrations&#x2F;rust&quot;&gt;ClickHouse Rust client&lt;&#x2F;a&gt; - Official Rust client by Paul Loyd&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;crates.io&#x2F;crates&#x2F;pingap&quot;&gt;Pingap&lt;&#x2F;a&gt; - Reverse proxy built on Pingora&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;cloudflare&#x2F;pingora&#x2F;pull&#x2F;336&quot;&gt;PR: Add Rustls to Pingora&lt;&#x2F;a&gt; - by Harald Gutmann&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;cloudflare&#x2F;pingora&#x2F;pull&#x2F;675&quot;&gt;PR: Add s2n-tls to Pingora&lt;&#x2F;a&gt; - by Bryan Gilbert&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h3 id=&quot;official-links&quot;&gt;Official Links&lt;&#x2F;h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.cloudflare.com&#x2F;&quot;&gt;Cloudflare&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;blog.cloudflare.com&#x2F;&quot;&gt;Cloudflare Blog&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;cloudflare&#x2F;pingora&quot;&gt;Pingora on GitHub&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;blog.cloudflare.com&#x2F;author&#x2F;edward-h-wang&#x2F;&quot;&gt;Edward Wang’s Blog Posts&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;blog.cloudflare.com&#x2F;author&#x2F;kevin-guthrie&#x2F;&quot;&gt;Kevin Guthrie’s Blog Posts&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
</description>
      </item>
      <item>
          <title>Scythe Robotics</title>
          <pubDate>Thu, 16 Oct 2025 00:00:00 +0000</pubDate>
          <author>Matthias Endler</author>
          <link>https://corrode.dev/podcast/s05e02-scythe/</link>
          <guid>https://corrode.dev/podcast/s05e02-scythe/</guid>
          <description xml:base="https://corrode.dev/podcast/s05e02-scythe/">&lt;div&gt;&lt;script id=&quot;letscast-player-ae39496a&quot; src=&quot;https:&#x2F;&#x2F;letscast.fm&#x2F;podcasts&#x2F;rust-in-production-82281512&#x2F;episodes&#x2F;scythe-with-andrew-tinka&#x2F;player.js?size=s&quot;&gt;&lt;&#x2F;script&gt;&lt;&#x2F;div&gt;
&lt;p&gt;Building autonomous robots that operate safely in the real world is one of the most challenging engineering problems today. When those robots carry sharp blades and work around people, the margin for error is razor-thin.&lt;&#x2F;p&gt;
&lt;p&gt;In this episode, we talk to Andrew Tinka from Scythe Robotics about how they use Rust to build autonomous electric mowers for commercial landscaping. We discuss the unique challenges of robotics software, why Rust is an ideal choice for cutting-edge safety-critical systems, and what it takes to keep autonomous machines running smoothly in the field.&lt;&#x2F;p&gt;
&lt;div class=&quot;info dashed&quot;&gt;
  &lt;div class=&quot;info-header&quot;&gt;
    &lt;i class=&quot;icon icon-info&quot;&gt;&lt;&#x2F;i&gt;
    &lt;h4&gt;Proudly Supported by CodeCrafters&lt;&#x2F;h4&gt;
  &lt;&#x2F;div&gt;
  &lt;p&gt;
    CodeCrafters helps you become proficient in Rust by building real-world,
    production-grade projects. Learn hands-on by creating your own shell, HTTP
    server, Redis, Kafka, Git, SQLite, or DNS service from scratch.
  &lt;&#x2F;p&gt;
  &lt;p&gt;
    Start for free today and enjoy 40% off any paid plan by using
    &lt;a href=&quot;https:&#x2F;&#x2F;app.codecrafters.io&#x2F;join?via=mre&quot;&gt;this link&lt;&#x2F;a&gt;.
  &lt;&#x2F;p&gt;
&lt;&#x2F;div&gt;
&lt;h2 id=&quot;show-notes&quot;&gt;Show Notes&lt;&#x2F;h2&gt;
&lt;h3 id=&quot;about-scythe-robotics&quot;&gt;About Scythe Robotics&lt;&#x2F;h3&gt;
&lt;p&gt;Scythe Robotics is building autonomous electric mowers for commercial landscaping. Their machines combine advanced sensors, computer vision, and sophisticated path planning to autonomously trim large outdoor spaces while ensuring safety around people and obstacles. By leveraging Rust throughout their software stack, Scythe achieves the reliability and safety guarantees required for autonomous systems breaking new ground in uncontrolled environments. The company is headquartered in Colorado and is reshaping how commercial properties are maintained.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;about-andrew-tinka&quot;&gt;About Andrew Tinka&lt;&#x2F;h3&gt;
&lt;p&gt;Andrew is the Director of Software Engineering at Scythe Robotics, where he drives the development of autonomous systems that power their robotic mowers. He specializes in planning and control for large fleets of mobile robots, with over a decade of experience in multi-agent planning technologies that helped pave the way at Amazon Robotics. Andrew has cultivated deep expertise in building safety-critical software for real-world robotics applications and is passionate about using Rust to create reliable, performant systems. His work covers everything from low-level embedded systems to high-level planning algorithms.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;links-from-the-episode&quot;&gt;Links From The Episode&lt;&#x2F;h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Piste#North_America,_Australia_and_New_Zealand&quot;&gt;Ski trails rating&lt;&#x2F;a&gt; - A difficulty rating system common in Colorado&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;developer.nvidia.com&#x2F;embedded&#x2F;jetson-modules&quot;&gt;NVIDIA Jetson&lt;&#x2F;a&gt; - Combined ARM CPU with a GPU for AI workloads at the heart of every Scythe robot&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;doc.rust-lang.org&#x2F;stable&#x2F;book&#x2F;ch03-01-variables-and-mutability.html#variables-and-mutability&quot;&gt;The Rust Book: Variables and Mutability&lt;&#x2F;a&gt; - Immutability is the default in Rust&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.youtube.com&#x2F;watch?v=kESBAiTYMoQ&quot;&gt;Jon Gjengset: Sguaba&lt;&#x2F;a&gt; - A type safe spatial maths library&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;doc.rust-lang.org&#x2F;stable&#x2F;book&#x2F;ch18-01-what-is-oo.html#inheritance-as-a-type-system-and-as-code-sharing&quot;&gt;The Rust Book: Inheritance as a Type System and as Code Sharing&lt;&#x2F;a&gt; - Unlike Java, Rust doesn’t have inheritance&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;rust-unofficial.github.io&#x2F;patterns&#x2F;idioms&#x2F;default.html&quot;&gt;Using &lt;code&gt;{..Default::default}&lt;&#x2F;code&gt; when creating structs&lt;&#x2F;a&gt; - The alternative is to initialize each field explicitly&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;doc.rust-lang.org&#x2F;stable&#x2F;book&#x2F;ch19-02-refutability.html&quot;&gt;The Rust Book: Refutability&lt;&#x2F;a&gt; - Rust tells you when you forgot something&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;rust-lang&#x2F;rust-clippy&quot;&gt;Clippy&lt;&#x2F;a&gt; - Rust’s official linter&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.youtube.com&#x2F;watch?v=ao-CLgci-e8&quot;&gt;Deterministic fleet management for autonomous mobile robots using Rust - Andy Brinkmeyer from Arculus&lt;&#x2F;a&gt; - 2024 Oxidize warehouse robot talk with deterministic testing&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.ros.org&#x2F;&quot;&gt;ROS&lt;&#x2F;a&gt; - The Robot Operating System&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;slawlor.github.io&#x2F;ractor&#x2F;&quot;&gt;Ractor&lt;&#x2F;a&gt; - A good modern actor framework&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;youtu.be&#x2F;zrv5Cy1R7r4&quot;&gt;Rain: Cancelling Async Rust&lt;&#x2F;a&gt; - RustConf 2025 talk with many examples of pitfalls&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h3 id=&quot;official-links&quot;&gt;Official Links&lt;&#x2F;h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;scytherobotics.com&#x2F;&quot;&gt;Scythe Robotics&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.linkedin.com&#x2F;company&#x2F;scythe-robotics&#x2F;&quot;&gt;Scythe on LinkedIn&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;scythe-robotics&quot;&gt;Scythe on GitHub&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.linkedin.com&#x2F;in&#x2F;andrewtinka&#x2F;&quot;&gt;Andrew Tinka on LinkedIn&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
</description>
      </item>
      <item>
          <title>Rust Conferences 2026</title>
          <pubDate>Wed, 15 Oct 2025 00:00:00 +0000</pubDate>
          <author>Matthias Endler</author>
          <link>https://corrode.dev/blog/rust-conferences-2026/</link>
          <guid>https://corrode.dev/blog/rust-conferences-2026/</guid>
          <description xml:base="https://corrode.dev/blog/rust-conferences-2026/">&lt;p&gt;The Rust community continues to grow, and with it, the number of conferences around the world.
While some 2026 conferences haven’t announced their dates yet, we’re tracking what’s confirmed so far.
Come say hi if you see us at any of these events! (We’ll bring &lt;a href=&quot;&#x2F;podcast&quot;&gt;Rust in Production&lt;&#x2F;a&gt; stickers.)&lt;&#x2F;p&gt;
&lt;p&gt;Oh, and in case the call for proposals (CFP) is still open, why not submit a
talk or workshop proposal?&lt;&#x2F;p&gt;
&lt;!-- Interactive Map --&gt;
&lt;div id=&quot;conference-map&quot;&gt;&lt;&#x2F;div&gt;
&lt;div class=&quot;map-attribution&quot;&gt;
  Map powered by &lt;a href=&quot;https:&#x2F;&#x2F;leafletjs.com&#x2F;&quot; target=&quot;_blank&quot;&gt;Leaflet&lt;&#x2F;a&gt; |
  © &lt;a href=&quot;https:&#x2F;&#x2F;stadiamaps.com&#x2F;&quot; target=&quot;_blank&quot;&gt;Stadia Maps&lt;&#x2F;a&gt;
  © &lt;a href=&quot;https:&#x2F;&#x2F;stamen.com&#x2F;&quot; target=&quot;_blank&quot;&gt;Stamen Design&lt;&#x2F;a&gt;
  © &lt;a href=&quot;https:&#x2F;&#x2F;openmaptiles.org&#x2F;&quot; target=&quot;_blank&quot;&gt;OpenMapTiles&lt;&#x2F;a&gt;
  © &lt;a href=&quot;https:&#x2F;&#x2F;www.openstreetmap.org&#x2F;copyright&quot; target=&quot;_blank&quot;&gt;OpenStreetMap&lt;&#x2F;a&gt; contributors
&lt;&#x2F;div&gt;
&lt;div class=&quot;conference-filters&quot;&gt;
  &lt;button class=&quot;button filter-btn active&quot; data-filter=&quot;all&quot;&gt;All Conferences&lt;&#x2F;button&gt;
  &lt;button class=&quot;button filter-btn&quot; data-filter=&quot;cfp-open&quot;&gt;CFP Open&lt;&#x2F;button&gt;
  &lt;button class=&quot;button filter-btn&quot; data-filter=&quot;announced&quot;&gt;Dates Announced&lt;&#x2F;button&gt;
&lt;&#x2F;div&gt;
&lt;h2 id=&quot;q1-2026&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#q1-2026&quot; aria-label=&quot;Anchor link for: q1-2026&quot;&gt;Q1 2026&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;h3 id=&quot;rust-nation-london-uk&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#rust-nation-london-uk&quot; aria-label=&quot;Anchor link for: rust-nation-london-uk&quot;&gt;Rust Nation (London, UK)&lt;&#x2F;a&gt;&lt;&#x2F;h3&gt;
&lt;a href=&quot;https:&#x2F;&#x2F;www.rustnationuk.com&#x2F;&quot; target=&quot;_blank&quot;&gt;
  &lt;img src=&quot;rustnation.jpg&quot; alt=&quot;Rust Nation&quot; &#x2F;&gt;
&lt;&#x2F;a&gt;
&lt;p&gt;Rust Nation has evolved into a staple event in the Rust community.
The organization, speaker lineup, and recordings are always top-notch.
As per tradition, they kick off the year of Rust conferences.&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;When&lt;&#x2F;strong&gt;: February 18-19, 2026&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Where&lt;&#x2F;strong&gt;: &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.rustnationuk.com&#x2F;&quot;&gt;1 America Square (Workshops) &amp;amp; The Brewery (Main Conference), London, UK&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Format&lt;&#x2F;strong&gt;: 2 days (workshops + conference)&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Focus&lt;&#x2F;strong&gt;: Rust ecosystem and community&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Pricing&lt;&#x2F;strong&gt;: &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.rustnationuk.com&#x2F;tickets&quot;&gt;£220.00 + £44.00 VAT&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;CFP&lt;&#x2F;strong&gt;: Closed&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Links&lt;&#x2F;strong&gt;: &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.rustnationuk.com&#x2F;&quot;&gt;Website&lt;&#x2F;a&gt; | &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.rustnationuk.com&#x2F;tickets&quot;&gt;Tickets&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Social&lt;&#x2F;strong&gt;: &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;x.com&#x2F;rustnationuk&quot;&gt;Twitter&lt;&#x2F;a&gt; | &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;hachyderm.io&#x2F;@Rustnationuk&quot;&gt;Mastodon&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h3 id=&quot;rust-in-paris-france&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#rust-in-paris-france&quot; aria-label=&quot;Anchor link for: rust-in-paris-france&quot;&gt;Rust in Paris (France)&lt;&#x2F;a&gt;&lt;&#x2F;h3&gt;
&lt;a href=&quot;https:&#x2F;&#x2F;rustinparis.com&#x2F;&quot; target=&quot;_blank&quot;&gt;
  &lt;img src=&quot;rustinparis.jpg&quot; alt=&quot;Rust in Paris&quot; &#x2F;&gt;
&lt;&#x2F;a&gt;
&lt;p&gt;“When Safety Meets Elegance” is the tagline for Rust in Paris.&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;When&lt;&#x2F;strong&gt;: March 27, 2026&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Where&lt;&#x2F;strong&gt;: &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.google.com&#x2F;maps&#x2F;place&#x2F;Apollo+Th%C3%A9%C3%A2tre&#x2F;@48.8682435,2.3637481,17z&#x2F;data=!3m2!4b1!5s0x47e66e084be9ac71:0x5452be83db948318!4m6!3m5!1s0x47e66e0852167e43:0xa259bf31ee319054!8m2!3d48.86824!4d2.366323!16s%2Fg%2F120z_cmr?entry=ttu&quot;&gt;L’Apollo Théâtre 18, Rue du Faubourg du Temple, 75011 Paris – France&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Format&lt;&#x2F;strong&gt;: 1 day conference&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Focus&lt;&#x2F;strong&gt;: Crafting safe &amp;amp; efficient futures&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Pricing&lt;&#x2F;strong&gt;: &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;ti.to&#x2F;xperhub&#x2F;rust-in-paris-2026&quot;&gt;€120&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;CFP&lt;&#x2F;strong&gt;: Closed&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Links&lt;&#x2F;strong&gt;: &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;rustinparis.com&#x2F;&quot;&gt;Website&lt;&#x2F;a&gt; | &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.youtube.com&#x2F;@rustinparis&quot;&gt;Past Talks&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h3 id=&quot;rustikon-warsaw-poland&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#rustikon-warsaw-poland&quot; aria-label=&quot;Anchor link for: rustikon-warsaw-poland&quot;&gt;Rustikon (Warsaw, Poland)&lt;&#x2F;a&gt;&lt;&#x2F;h3&gt;
&lt;a href=&quot;https:&#x2F;&#x2F;www.rustikon.dev&#x2F;&quot; target=&quot;_blank&quot;&gt;
  &lt;img src=&quot;rustikon.jpg&quot; alt=&quot;Rustikon&quot; &#x2F;&gt;
&lt;&#x2F;a&gt;
&lt;p&gt;Aims to bring together Rust developers from the region and beyond.
Expect a developer-friendly atmosphere with expert talks in a single-track format, perfect for staying connected and engaged.&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;When&lt;&#x2F;strong&gt;: March 19-20, 2026&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Where&lt;&#x2F;strong&gt;: &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;maps.app.goo.gl&#x2F;tPT7GzRc7kUh4d3s5&quot;&gt;POLIN Conference Centre, Warsaw, Poland&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Format&lt;&#x2F;strong&gt;: 2 day conference&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Focus&lt;&#x2F;strong&gt;: Rust adoption in Poland and beyond&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Pricing&lt;&#x2F;strong&gt;: &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.rustikon.dev&#x2F;tickets&quot;&gt;€300&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;CFP&lt;&#x2F;strong&gt;: &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;sessionize.com&#x2F;rustikon-2026&#x2F;&quot;&gt;Closed&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Links&lt;&#x2F;strong&gt;: &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.rustikon.dev&#x2F;&quot;&gt;Website&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Social&lt;&#x2F;strong&gt;: &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;x.com&#x2F;rustikonconf&quot;&gt;Twitter&lt;&#x2F;a&gt; | &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;mastodon.social&#x2F;@Rustikon&quot;&gt;Mastodon&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h3 id=&quot;rustasia-hong-kong-dates-tba&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#rustasia-hong-kong-dates-tba&quot; aria-label=&quot;Anchor link for: rustasia-hong-kong-dates-tba&quot;&gt;RUSTAsia (Hong Kong) &lt;span class=&quot;conference-badge tentative&quot;&gt;Dates TBA&lt;&#x2F;span&gt;&lt;&#x2F;a&gt;&lt;&#x2F;h3&gt;
&lt;a target=&quot;_blank&quot;&gt;
  &lt;img src=&quot;rustasia.jpg&quot; alt=&quot;RUSTAsia&quot; &#x2F;&gt;
&lt;&#x2F;a&gt;
&lt;p&gt;A conference for Rust developers in Asia.&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;When&lt;&#x2F;strong&gt;: TBA (typically March)&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Where&lt;&#x2F;strong&gt;: Hong Kong&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Format&lt;&#x2F;strong&gt;: Hybrid (in-person + online)&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Focus&lt;&#x2F;strong&gt;: Rust in Asia&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Pricing&lt;&#x2F;strong&gt;: TBA&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;CFP&lt;&#x2F;strong&gt;: TBA&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Links&lt;&#x2F;strong&gt;: Website offline&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Social&lt;&#x2F;strong&gt;: &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;x.com&#x2F;rustasiaconf&quot;&gt;Twitter&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h2 id=&quot;q2-2026&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#q2-2026&quot; aria-label=&quot;Anchor link for: q2-2026&quot;&gt;Q2 2026&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;h3 id=&quot;rust-india-bengaluru-india&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#rust-india-bengaluru-india&quot; aria-label=&quot;Anchor link for: rust-india-bengaluru-india&quot;&gt;Rust India (Bengaluru, India)&lt;&#x2F;a&gt;&lt;&#x2F;h3&gt;
&lt;a href=&quot;https:&#x2F;&#x2F;rustindia.org&#x2F;&quot; target=&quot;_blank&quot;&gt;
  &lt;img src=&quot;rustindia.jpg&quot; alt=&quot;Rust India&quot; &#x2F;&gt;
&lt;&#x2F;a&gt;
&lt;p&gt;A single-day community conference where maintainers, compiler tinkerers, infra teams, and curious builders
come together for practical Rust talks, hallway conversations, and real production stories.&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;When&lt;&#x2F;strong&gt;: April 18, 2026&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Where&lt;&#x2F;strong&gt;: Bengaluru, India&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Format&lt;&#x2F;strong&gt;: 1 day (5 full talks + 8 lightning talks)&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Focus&lt;&#x2F;strong&gt;: Systems programming, reliability, performance tuning, production Rust&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Pricing&lt;&#x2F;strong&gt;: Tickets opening soon&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;CFP&lt;&#x2F;strong&gt;: &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;rustindia.org&#x2F;&quot;&gt;Open&lt;&#x2F;a&gt; (25 and 45 min formats)&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Links&lt;&#x2F;strong&gt;: &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;rustindia.org&#x2F;&quot;&gt;Website&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h3 id=&quot;tokioconf-portland-usa&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#tokioconf-portland-usa&quot; aria-label=&quot;Anchor link for: tokioconf-portland-usa&quot;&gt;TokioConf (Portland, USA)&lt;&#x2F;a&gt;&lt;&#x2F;h3&gt;
&lt;a href=&quot;https:&#x2F;&#x2F;www.tokioconf.com&#x2F;&quot; target=&quot;_blank&quot;&gt;
  &lt;img src=&quot;tokioconf.jpg&quot; alt=&quot;TokioConf&quot; &#x2F;&gt;
&lt;&#x2F;a&gt;
&lt;p&gt;The first-ever dedicated conference for developers building high-performance network applications with Tokio and async Rust. A single-track event bringing together ~300 developers from across the Rust ecosystem.&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;When&lt;&#x2F;strong&gt;: April 20-22, 2026&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Where&lt;&#x2F;strong&gt;: &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.hyatt.com&#x2F;hyatt-regency&#x2F;en-US&#x2F;pdxrp-hyatt-regency-portland-at-the-oregon-convention-center&quot;&gt;Hyatt Regency Portland, 375 NE Holladay St, Portland, OR 97232&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Format&lt;&#x2F;strong&gt;: 3 days (1 day optional workshops + 2 days single-track conference)&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Focus&lt;&#x2F;strong&gt;: Async Rust, Tokio, high-performance network applications&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Pricing&lt;&#x2F;strong&gt;: &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.eventbrite.com&#x2F;e&#x2F;tokioconf-2026-tickets-1595919270499&quot;&gt;Early Bird $650, General Admission $750&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;CFP&lt;&#x2F;strong&gt;: &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;sessionize.com&#x2F;tokioconf-2026&quot;&gt;Closed&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Links&lt;&#x2F;strong&gt;: &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.tokioconf.com&#x2F;&quot;&gt;Website&lt;&#x2F;a&gt; | &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.eventbrite.com&#x2F;e&#x2F;tokioconf-2026-tickets-1595919270499&quot;&gt;Tickets&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Social&lt;&#x2F;strong&gt;: &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;tokio.rs&#x2F;blog&quot;&gt;Tokio Blog&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h3 id=&quot;rustweek-utrecht-netherlands&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#rustweek-utrecht-netherlands&quot; aria-label=&quot;Anchor link for: rustweek-utrecht-netherlands&quot;&gt;RustWeek (Utrecht, Netherlands)&lt;&#x2F;a&gt;&lt;&#x2F;h3&gt;
&lt;a href=&quot;https:&#x2F;&#x2F;2026.rustweek.org&#x2F;&quot; target=&quot;_blank&quot;&gt;
  &lt;img src=&quot;rustweek.jpg&quot; alt=&quot;RustWeek&quot; &#x2F;&gt;
&lt;&#x2F;a&gt;
&lt;p&gt;RustWeek is a week-long event that combines talks, workshops, and social events.
It’s located in cozy Utrecht, the fourth-largest city in the Netherlands.
The world’s biggest Rust conference returns, welcoming over 900+ community members.
All Rustaceans are welcome to attend and submit talks.&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;When&lt;&#x2F;strong&gt;: May 18-23, 2026&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Where&lt;&#x2F;strong&gt;: Utrecht, Netherlands&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Format&lt;&#x2F;strong&gt;: Full week (2 days talks + 1 day workshops + social events)&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Focus&lt;&#x2F;strong&gt;: Broad, open to everyone&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Pricing&lt;&#x2F;strong&gt;: &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;event.onliveevent.nl&#x2F;rustweek-2026&quot;&gt;Tickets available&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;CFP&lt;&#x2F;strong&gt;: Closed&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Links&lt;&#x2F;strong&gt;: &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;2026.rustweek.org&#x2F;&quot;&gt;Website&lt;&#x2F;a&gt; | &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.youtube.com&#x2F;@rustnederlandrustnl&quot;&gt;Past Talks&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Social&lt;&#x2F;strong&gt;: &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;bsky.app&#x2F;profile&#x2F;rustnl.bsky.social&quot;&gt;BlueSky&lt;&#x2F;a&gt; | &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;fosstodon.org&#x2F;@rustnl&quot;&gt;Mastodon&lt;&#x2F;a&gt; | &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.linkedin.com&#x2F;company&#x2F;rustnl&#x2F;&quot;&gt;LinkedIn&lt;&#x2F;a&gt; | &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;x.com&#x2F;Rust_NL&quot;&gt;Twitter&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h3 id=&quot;rustmeet-krakow-poland&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#rustmeet-krakow-poland&quot; aria-label=&quot;Anchor link for: rustmeet-krakow-poland&quot;&gt;RUSTMEET (Kraków, Poland)&lt;&#x2F;a&gt;&lt;&#x2F;h3&gt;
&lt;a href=&quot;https:&#x2F;&#x2F;rustmeet.eu&#x2F;&quot; target=&quot;_blank&quot;&gt;
  &lt;img src=&quot;rustmeet.jpg&quot; alt=&quot;RUSTMEET&quot; &#x2F;&gt;
&lt;&#x2F;a&gt;
&lt;p&gt;An event in Poland, actively co-created by Rust enthusiasts.&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;When&lt;&#x2F;strong&gt;: June 12-14, 2026&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Where&lt;&#x2F;strong&gt;: &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;rustmeet.eu&#x2F;&quot;&gt;Hotel Kolna, Kraków, Poland&lt;&#x2F;a&gt; (also online)&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Format&lt;&#x2F;strong&gt;: 3 days (talks + workshops + lightning talks + social event)&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Focus&lt;&#x2F;strong&gt;: Rust programming language&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Pricing&lt;&#x2F;strong&gt;: Available via &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;rustmeet.eu&#x2F;&quot;&gt;Confreg&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;CFP&lt;&#x2F;strong&gt;: &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;rustmeet.eu&#x2F;&quot;&gt;Open until March 22, 2026&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Links&lt;&#x2F;strong&gt;: &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;rustmeet.eu&#x2F;&quot;&gt;Website&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Social&lt;&#x2F;strong&gt;: &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.linkedin.com&#x2F;company&#x2F;rustmeet&#x2F;&quot;&gt;LinkedIn&lt;&#x2F;a&gt; | &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;c.im&#x2F;@rustmeet&quot;&gt;Mastodon&lt;&#x2F;a&gt; | &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;bsky.app&#x2F;profile&#x2F;rustmeet.bsky.social&quot;&gt;BlueSky&lt;&#x2F;a&gt; | &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;discord.com&#x2F;invite&#x2F;CsVnFrYVzm&quot;&gt;Discord&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h2 id=&quot;q3-2026&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#q3-2026&quot; aria-label=&quot;Anchor link for: q3-2026&quot;&gt;Q3 2026&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;h3 id=&quot;rustconf-montreal-canada&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#rustconf-montreal-canada&quot; aria-label=&quot;Anchor link for: rustconf-montreal-canada&quot;&gt;RustConf (Montreal, Canada)&lt;&#x2F;a&gt;&lt;&#x2F;h3&gt;
&lt;a href=&quot;https:&#x2F;&#x2F;rustconf.com&#x2F;&quot; target=&quot;_blank&quot;&gt;
  &lt;img src=&quot;rustconf.jpg&quot; alt=&quot;RustConf&quot; &#x2F;&gt;
&lt;&#x2F;a&gt;
&lt;p&gt;RustConf is the official Rust conference organized by the Rust Foundation.
It’s a great place to meet the Rust core team and other community members.
After Seattle in 2025, RustConf returns to beautiful Montreal, Canada.&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;When&lt;&#x2F;strong&gt;: September 8-11, 2026&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Where&lt;&#x2F;strong&gt;: &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;congresmtl.com&#x2F;&quot;&gt;Palais des Congrès de Montréal&lt;&#x2F;a&gt;, Montréal, Canada, Québec&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Format&lt;&#x2F;strong&gt;: 4 days (1 day workshops + 3 days talks)&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Focus&lt;&#x2F;strong&gt;: Official Rust conference&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Pricing&lt;&#x2F;strong&gt;: TBA&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;CFP&lt;&#x2F;strong&gt;: Closed&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Links&lt;&#x2F;strong&gt;: &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;rustconf.com&#x2F;&quot;&gt;Website&lt;&#x2F;a&gt; | &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;mailchi.mp&#x2F;e0f01ceec688&#x2F;rustconf-newsletter-registration&quot;&gt;Newsletter&lt;&#x2F;a&gt; | &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.youtube.com&#x2F;@rustfoundation&quot;&gt;Past Talks&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Social&lt;&#x2F;strong&gt;: &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;hachyderm.io&#x2F;@rustconf&quot;&gt;Mastodon&lt;&#x2F;a&gt; | &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;bsky.app&#x2F;profile&#x2F;rustconf.com&quot;&gt;BlueSky&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h3 id=&quot;oxidize-berlin-germany&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#oxidize-berlin-germany&quot; aria-label=&quot;Anchor link for: oxidize-berlin-germany&quot;&gt;Oxidize (Berlin, Germany)&lt;&#x2F;a&gt;&lt;&#x2F;h3&gt;
&lt;a href=&quot;https:&#x2F;&#x2F;oxidizeconf.com&#x2F;&quot; target=&quot;_blank&quot;&gt;
  &lt;img src=&quot;oxidize.jpg&quot; alt=&quot;Oxidize&quot; &#x2F;&gt;
&lt;&#x2F;a&gt;
&lt;p&gt;Two days of applied Rust insights from industry innovators.
Topics range from cross-platform GUI development to Rust in safety-critical systems.&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;When&lt;&#x2F;strong&gt;: September 14-16, 2026&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Where&lt;&#x2F;strong&gt;: &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;maps.app.goo.gl&#x2F;Q3SzoU7EDJv4kxnHA&quot;&gt;Tagungswerk, Berlin, Germany&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Format&lt;&#x2F;strong&gt;: 3 days (1 day workshops + 2 days talks)&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Focus&lt;&#x2F;strong&gt;: Applied Rust insights&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Pricing&lt;&#x2F;strong&gt;: TBA&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;CFP&lt;&#x2F;strong&gt;: &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;oxidizeconf.com&#x2F;&quot;&gt;Open until March 23, 2026&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Links&lt;&#x2F;strong&gt;: &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;oxidizeconf.com&#x2F;&quot;&gt;Website&lt;&#x2F;a&gt; | &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.youtube.com&#x2F;@OxidizeConf&quot;&gt;Past Talks&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Social&lt;&#x2F;strong&gt;: &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;x.com&#x2F;OxidizeConf&quot;&gt;Twitter&lt;&#x2F;a&gt; | &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;social.ferrous-systems.com&#x2F;@oxidize&quot;&gt;Mastodon&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h2 id=&quot;q4-2026&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#q4-2026&quot; aria-label=&quot;Anchor link for: q4-2026&quot;&gt;Q4 2026&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;h3 id=&quot;eurorust-barcelona-spain&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#eurorust-barcelona-spain&quot; aria-label=&quot;Anchor link for: eurorust-barcelona-spain&quot;&gt;EuroRust (Barcelona, Spain)&lt;&#x2F;a&gt;&lt;&#x2F;h3&gt;
&lt;a href=&quot;https:&#x2F;&#x2F;eurorust.eu&#x2F;&quot; target=&quot;_blank&quot;&gt;
  &lt;img src=&quot;eurorust.jpg&quot; alt=&quot;EuroRust&quot; &#x2F;&gt;
&lt;&#x2F;a&gt;
&lt;p&gt;One of the largest Rust conferences in Europe and a well-established event in
the Rust community. A 2-day conference that covers all things Rust: from
Rust patterns and idioms to system programming and CLI tooling, servers WASM and
embedded systems.&lt;&#x2F;p&gt;
&lt;p&gt;The conference travels to a different European city each year.
This time, it’s in Barcelona, Spain. 🇪🇸&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;When&lt;&#x2F;strong&gt;: October 14-17, 2026&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Where&lt;&#x2F;strong&gt;: &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;maps.app.goo.gl&#x2F;nUzwZ1x7fahyD7aW9&quot;&gt;Auditori L’illa, Barcelona, Spain&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Format&lt;&#x2F;strong&gt;: 2 day event&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Focus&lt;&#x2F;strong&gt;: Rust patterns, idioms, system programming, CLI tooling, servers, WASM, embedded systems&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Pricing&lt;&#x2F;strong&gt;: &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;ti.to&#x2F;events-matter&#x2F;eurorust-2026&quot;&gt;Private Ticket €275, Freelancer Ticket €332, Company Ticket: €600&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;CFP&lt;&#x2F;strong&gt;: &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;sessionize.com&#x2F;eurorust-2026&quot;&gt;Open until April 27, 2026&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Links&lt;&#x2F;strong&gt;: &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;eurorust.eu&#x2F;&quot;&gt;Website&lt;&#x2F;a&gt; | &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.youtube.com&#x2F;@eurorust&quot;&gt;Past Talks&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Social&lt;&#x2F;strong&gt;: &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;x.com&#x2F;euro_rust&quot;&gt;Twitter&lt;&#x2F;a&gt; | &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;fosstodon.org&#x2F;@eurorust&quot;&gt;Mastodon&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h3 id=&quot;rustlab-bologna-italy&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#rustlab-bologna-italy&quot; aria-label=&quot;Anchor link for: rustlab-bologna-italy&quot;&gt;RustLab (Bologna, Italy)&lt;&#x2F;a&gt;&lt;&#x2F;h3&gt;
&lt;a href=&quot;https:&#x2F;&#x2F;rustlab.it&#x2F;&quot; target=&quot;_blank&quot;&gt;
  &lt;img src=&quot;rustlab.jpg&quot; alt=&quot;RustLab&quot; &#x2F;&gt;
&lt;&#x2F;a&gt;
&lt;p&gt;The Italian Rust conference traditionally takes place in Florence.
It’s lovingly organized featuring delicious Italian food and a great community.&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;When&lt;&#x2F;strong&gt;: November 1-3, 2026&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Where&lt;&#x2F;strong&gt;: &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;maps.app.goo.gl&#x2F;PFdKnc3hivvwjj6X7&quot;&gt;Savoia Regency Hotel, Bologna&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Format&lt;&#x2F;strong&gt;: 3 days (1 day workshops + 2 days talks)&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Focus&lt;&#x2F;strong&gt;: Rust in Italy and beyond&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Pricing&lt;&#x2F;strong&gt;: &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;rustlab.it&#x2F;&quot;&gt;€240 Early Bird Lite &#x2F; €370 Early Bird Premium&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;CFP&lt;&#x2F;strong&gt;: &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;sessionize.com&#x2F;rustlab-2026&quot;&gt;Open until April 13, 2026&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Links&lt;&#x2F;strong&gt;: &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;rustlab.it&#x2F;&quot;&gt;Website&lt;&#x2F;a&gt; | &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.youtube.com&#x2F;@rustlabconference3671&quot;&gt;Past Talks&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Social&lt;&#x2F;strong&gt;: &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;x.com&#x2F;rustlab_conf&quot;&gt;Twitter&lt;&#x2F;a&gt; | &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;mastodon.uno&#x2F;@rustlab&quot;&gt;Mastodon&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;hr &#x2F;&gt;
&lt;p&gt;That’s all we know about Rust conferences for 2026 so far! As conferences announce their dates and details, we’ll keep this page updated.&lt;&#x2F;p&gt;
&lt;p&gt;Missing an event? Spot an error? Feel free to &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;corrode&#x2F;corrode.github.io&#x2F;edit&#x2F;master&#x2F;content&#x2F;blog&#x2F;rust-conferences-2026&#x2F;index.md&quot;&gt;edit this list directly&lt;&#x2F;a&gt; or let us know.&lt;&#x2F;p&gt;
&lt;p&gt;See you at the next conference! 🦀&lt;&#x2F;p&gt;
&lt;p&gt;&lt;em&gt;Note: This list will be updated regularly as more conferences announce their 2026 dates. Most conferences are yet to announce their exact dates, venues, ticket prices, and CFP timelines. Check back often for updates!&lt;&#x2F;em&gt;&lt;&#x2F;p&gt;
&lt;script
  src=&quot;https:&#x2F;&#x2F;unpkg.com&#x2F;leaflet@1.9.4&#x2F;dist&#x2F;leaflet.js&quot;
  integrity=&quot;sha256-20nQCchB9co0qIjJZRGuk2&#x2F;Z9VM+kNiyxNV1lvTlZBo=&quot;
  crossorigin=&quot;&quot;
&gt;&lt;&#x2F;script&gt;
&lt;link
  rel=&quot;stylesheet&quot;
  href=&quot;https:&#x2F;&#x2F;unpkg.com&#x2F;leaflet@1.9.4&#x2F;dist&#x2F;leaflet.css&quot;
  integrity=&quot;sha256-p4NxAoJBhIIN+hmNHrzRCf9tD&#x2F;miZyoHS5obTRR9BMY=&quot;
  crossorigin=&quot;&quot;
&#x2F;&gt;
&lt;style&gt;
  iframe, object, embed {
    max-width: 100%;
  }

  &#x2F;* Filter buttons - overrides for .button class *&#x2F;
  .conference-filters {
    display: flex;
    gap: 0.75rem;
    margin: 2rem 0;
    flex-wrap: wrap;
  }

  .filter-btn {
    padding: 8px 16px;
    font-size: 0.9rem;
    border: 2px solid rgba(17, 17, 17, 0.2);
    background: transparent !important;
    color: #111 !important;
  }

  .filter-btn:hover {
    border-color: #111;
    background: rgba(17, 17, 17, 0.05) !important;
  }

  .filter-btn.active {
    background: #111 !important;
    color: white !important;
    border-color: #111;
  }

  &#x2F;* Conference badge styling *&#x2F;
  .conference-badge {
    font-size: 0.85rem;
    font-weight: 700;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    padding: 0.4rem 0.9rem;
    border: 2px solid;
    border-radius: 4px;
    display: inline-block;
    margin-left: 0.75rem;
    vertical-align: middle;
  }

  .conference-badge.tentative {
    color: #111;
    background: transparent;
    border-color: rgba(17, 17, 17, 0.3);
  }

  .conference-badge.days {
    color: #111;
    background: #fab71c;
    border-color: #fab71c;
  }

  .conference-badge.cfp-open {
    color: #111;
    background: #22c55e;
    border-color: #22c55e;
  }

  &#x2F;* Map styles *&#x2F;
  #conference-map {
    position: relative;
    height: 500px;
    width: 110%;
    margin-left: -5%;
    overflow: hidden;
    border-radius: 8px;
  }

  .map-attribution {
    font-size: 0.75rem;
    color: #888;
    margin: 0.5rem 0 2rem 0;
    text-align: center;
    width: 110%;
    margin-left: -5%;
  }

  .map-attribution a {
    color: #888;
    text-decoration: none;
  }

  .map-attribution a:hover {
    color: #555;
    text-decoration: underline;
  }

  .marker-container {
    width: 20px;
    height: 20px;
  }

  .pulse-marker {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: #ff1493;
    box-shadow: 0 0 0 0 rgba(255, 20, 147, 0.7);
    animation: pulse 2s infinite;
    position: relative;
    cursor: pointer;
  }

  .pulse-marker::before {
    content: &#x27;&#x27;;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: #fff;
  }

  @keyframes pulse {
    0% {
      box-shadow: 0 0 0 0 rgba(255, 20, 147, 0.7);
    }
    70% {
      box-shadow: 0 0 0 15px rgba(255, 20, 147, 0);
    }
    100% {
      box-shadow: 0 0 0 0 rgba(255, 20, 147, 0);
    }
  }

  .leaflet-tooltip {
    background: white;
    border: 2px solid #ff1493;
    border-radius: 8px;
    padding: 12px 16px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    font-size: 14px;
    line-height: 1.5;
    min-width: 200px;
  }

  .leaflet-tooltip::before {
    border-top-color: #ff1493;
  }

  .tooltip-title {
    font-weight: bold;
    font-size: 16px;
    color: #ff1493;
    margin-bottom: 6px;
  }

  .tooltip-dates {
    font-size: 13px;
    color: #666;
    margin-bottom: 4px;
  }

  .tooltip-location {
    font-size: 12px;
    color: #888;
  }

  &#x2F;* Dark mode support *&#x2F;
  @media (prefers-color-scheme: dark) {
    .filter-btn {
      color: white !important;
      border-color: rgba(255, 255, 255, 0.3);
    }

    .filter-btn:hover {
      background: rgba(255, 255, 255, 0.1) !important;
      border-color: rgba(255, 255, 255, 0.5);
    }

    .filter-btn.active {
      background: white !important;
      color: #111 !important;
      border-color: white;
    }

    .conference-badge.tentative {
      color: white;
      border-color: rgba(255, 255, 255, 0.3);
    }

    .conference-badge.cfp-open {
      background: #4ade80;
    }

    &#x2F;* Map dark mode *&#x2F;
    .leaflet-tooltip {
      background: #1f2937;
      border-color: #ff1493;
      color: #e5e7eb;
    }

    .tooltip-title {
      color: #ff69b4;
    }

    .tooltip-dates {
      color: #9ca3af;
    }

    .tooltip-location {
      color: #6b7280;
    }

    &#x2F;* Map attribution dark mode *&#x2F;
    .map-attribution {
      color: #aaa;
    }

    .map-attribution a {
      color: #aaa;
    }

    .map-attribution a:hover {
      color: #ddd;
    }
  }
&lt;&#x2F;style&gt;
&lt;script&gt;
&#x2F;&#x2F; Only show confirmed conferences on the map
function initConferenceMap() {
  const conferences = [
    {
      name: &#x27;Rust Nation&#x27;,
      city: &#x27;London&#x27;,
      country: &#x27;UK&#x27;,
      lat: 51.5074,
      lng: -0.1278,
      dates: &#x27;February 18-19, 2026&#x27;
    },
    {
      name: &#x27;Rust in Paris&#x27;,
      city: &#x27;Paris&#x27;,
      country: &#x27;France&#x27;,
      lat: 48.8682,
      lng: 2.3663,
      dates: &#x27;March 27, 2026&#x27;
    },
    {
      name: &#x27;Rustikon&#x27;,
      city: &#x27;Warsaw&#x27;,
      country: &#x27;Poland&#x27;,
      lat: 52.2297,
      lng: 21.0122,
      dates: &#x27;March 19-20, 2026&#x27;
    },
    {
      name: &#x27;TokioConf&#x27;,
      city: &#x27;Portland&#x27;,
      country: &#x27;USA&#x27;,
      lat: 45.5272,
      lng: -122.6645,
      dates: &#x27;April 20-22, 2026&#x27;
    },
    {
      name: &#x27;RustWeek&#x27;,
      city: &#x27;Utrecht&#x27;,
      country: &#x27;Netherlands&#x27;,
      lat: 52.0907,
      lng: 5.1214,
      dates: &#x27;May 18-23, 2026&#x27;
    },
    {
      name: &#x27;Rust India&#x27;,
      city: &#x27;Bengaluru&#x27;,
      country: &#x27;India&#x27;,
      lat: 12.9716,
      lng: 77.5946,
      dates: &#x27;April 18, 2026&#x27;
    },
    {
      name: &#x27;RUSTMEET&#x27;,
      city: &#x27;Kraków&#x27;,
      country: &#x27;Poland&#x27;,
      lat: 50.0647,
      lng: 19.9450,
      dates: &#x27;June 12-14, 2026&#x27;
    },
    {
      name: &#x27;RustConf&#x27;,
      city: &#x27;Montreal&#x27;,
      country: &#x27;Canada&#x27;,
      lat: 45.5017,
      lng: -73.5673,
      dates: &#x27;September 8-11, 2026&#x27;
    },
    {
      name: &#x27;Oxidize&#x27;,
      city: &#x27;Berlin&#x27;,
      country: &#x27;Germany&#x27;,
      lat: 52.5200,
      lng: 13.4050,
      dates: &#x27;September 14-16, 2026&#x27;
    },
    {
      name: &#x27;EuroRust&#x27;,
      city: &#x27;Barcelona&#x27;,
      country: &#x27;Spain&#x27;,
      lat: 41.3851,
      lng: 2.1734,
      dates: &#x27;October 14-17, 2026&#x27;
    },
    {
      name: &#x27;RustLab&#x27;,
      city: &#x27;Bologna&#x27;,
      country: &#x27;Italy&#x27;,
      lat: 44.4949,
      lng: 11.3426,
      dates: &#x27;November 1-3, 2026&#x27;
    }
  ];

  &#x2F;&#x2F; Create the map
  const map = L.map(&#x27;conference-map&#x27;, {
    attributionControl: false,
    center: [30, 10],
    zoom: 2,
    minZoom: 2,
    maxZoom: 10
  });

  &#x2F;&#x2F; Light and dark tile layers - using Stamen Toner from Stadia Maps
  const stadiaApiKey = &#x27;07e2d930-9008-40cb-aa03-2cdf13cf5e2f&#x27;;

  const lightLayer = L.tileLayer(
    `https:&#x2F;&#x2F;tiles.stadiamaps.com&#x2F;tiles&#x2F;stamen_toner_lite&#x2F;{z}&#x2F;{x}&#x2F;{y}{r}.png?api_key=${stadiaApiKey}`,
    {
      minZoom: 0,
      maxZoom: 20,
      attribution: &#x27;&amp;copy; &lt;a href=&quot;https:&#x2F;&#x2F;www.stadiamaps.com&#x2F;&quot; target=&quot;_blank&quot;&gt;Stadia Maps&lt;&#x2F;a&gt; &amp;copy; &lt;a href=&quot;https:&#x2F;&#x2F;www.stamen.com&#x2F;&quot; target=&quot;_blank&quot;&gt;Stamen Design&lt;&#x2F;a&gt; &amp;copy; &lt;a href=&quot;https:&#x2F;&#x2F;openmaptiles.org&#x2F;&quot; target=&quot;_blank&quot;&gt;OpenMapTiles&lt;&#x2F;a&gt; &amp;copy; &lt;a href=&quot;https:&#x2F;&#x2F;www.openstreetmap.org&#x2F;copyright&quot;&gt;OpenStreetMap&lt;&#x2F;a&gt; contributors&#x27;
    }
  );

  const darkLayer = L.tileLayer(
    `https:&#x2F;&#x2F;tiles.stadiamaps.com&#x2F;tiles&#x2F;stamen_toner&#x2F;{z}&#x2F;{x}&#x2F;{y}{r}.png?api_key=${stadiaApiKey}`,
    {
      minZoom: 0,
      maxZoom: 20,
      attribution: &#x27;&amp;copy; &lt;a href=&quot;https:&#x2F;&#x2F;www.stadiamaps.com&#x2F;&quot; target=&quot;_blank&quot;&gt;Stadia Maps&lt;&#x2F;a&gt; &amp;copy; &lt;a href=&quot;https:&#x2F;&#x2F;www.stamen.com&#x2F;&quot; target=&quot;_blank&quot;&gt;Stamen Design&lt;&#x2F;a&gt; &amp;copy; &lt;a href=&quot;https:&#x2F;&#x2F;openmaptiles.org&#x2F;&quot; target=&quot;_blank&quot;&gt;OpenMapTiles&lt;&#x2F;a&gt; &amp;copy; &lt;a href=&quot;https:&#x2F;&#x2F;www.openstreetmap.org&#x2F;copyright&quot;&gt;OpenStreetMap&lt;&#x2F;a&gt; contributors&#x27;
    }
  );

  function applyMapTheme(scheme) {
    if (scheme === &#x27;dark&#x27;) {
      if (map.hasLayer(lightLayer)) {
        map.removeLayer(lightLayer);
      }
      if (!map.hasLayer(darkLayer)) {
        darkLayer.addTo(map);
      }
    } else {
      if (map.hasLayer(darkLayer)) {
        map.removeLayer(darkLayer);
      }
      if (!map.hasLayer(lightLayer)) {
        lightLayer.addTo(map);
      }
    }
  }

  &#x2F;&#x2F; Hook into site&#x27;s theme system
  const originalToggleColorScheme = window.toggleColorScheme;
  window.toggleColorScheme = function() {
    if (originalToggleColorScheme) {
      originalToggleColorScheme();
    }
    &#x2F;&#x2F; Wait a bit for the theme to apply, then update map
    setTimeout(() =&gt; {
      const scheme = typeof getPreferredColorScheme === &#x27;function&#x27;
        ? getPreferredColorScheme()
        : (window.matchMedia(&#x27;(prefers-color-scheme: dark)&#x27;).matches ? &#x27;dark&#x27; : &#x27;light&#x27;);
      applyMapTheme(scheme);
    }, 50);
  };

  &#x2F;&#x2F; Get initial theme from site&#x27;s theme system
  const currentScheme = typeof getPreferredColorScheme === &#x27;function&#x27;
    ? getPreferredColorScheme()
    : (window.matchMedia(&#x27;(prefers-color-scheme: dark)&#x27;).matches ? &#x27;dark&#x27; : &#x27;light&#x27;);

  applyMapTheme(currentScheme);

  &#x2F;&#x2F; Add conference markers
  conferences.forEach(conf =&gt; {
    &#x2F;&#x2F; Create custom divIcon with pulsating marker
    &#x2F;&#x2F; Use wrapper class and inner HTML to avoid conflicts with Leaflet&#x27;s transform positioning
    const icon = L.divIcon({
      className: &#x27;marker-container&#x27;,
      html: &#x27;&lt;div class=&quot;pulse-marker&quot;&gt;&lt;&#x2F;div&gt;&#x27;,
      iconSize: [20, 20],
      iconAnchor: [10, 10],
      tooltipAnchor: [0, -10]
    });

    &#x2F;&#x2F; Create tooltip content
    const tooltipContent = `
      &lt;div class=&quot;tooltip-title&quot;&gt;${conf.name}&lt;&#x2F;div&gt;
      &lt;div class=&quot;tooltip-dates&quot;&gt;${conf.dates}&lt;&#x2F;div&gt;
      &lt;div class=&quot;tooltip-location&quot;&gt;${conf.city}, ${conf.country}&lt;&#x2F;div&gt;
    `;

    &#x2F;&#x2F; Create marker
    const marker = L.marker([conf.lat, conf.lng], { icon: icon })
      .addTo(map)
      .bindTooltip(tooltipContent, {
        permanent: false,
        direction: &#x27;top&#x27;,
        offset: [0, -10]
      });

    &#x2F;&#x2F; Show tooltip on hover
    marker.on(&#x27;mouseover&#x27;, function() {
      this.openTooltip();
    });

    marker.on(&#x27;mouseout&#x27;, function() {
      this.closeTooltip();
    });
  });
}

&#x2F;&#x2F; Add days until conference start
function addDaysUntilConference() {
    &#x2F;&#x2F; Find all h3 headings (conference titles)
    const headings = document.querySelectorAll(&#x27;article h3&#x27;);
    
    headings.forEach(h3 =&gt; {
        &#x2F;&#x2F; Find the next list that contains conference details
        let currentElement = h3.nextElementSibling;
        while (currentElement) {
            if (currentElement.tagName === &#x27;UL&#x27;) {
                &#x2F;&#x2F; Found the list, now look for the &quot;When:&quot; item
                const listItems = currentElement.querySelectorAll(&#x27;li&#x27;);
                
                listItems.forEach(li =&gt; {
                    const text = li.textContent;

                    &#x2F;&#x2F; Check if this list item contains &quot;When:&quot; and doesn&#x27;t have &quot;TBA&quot;
                    if (!text.includes(&#x27;When:&#x27;) || text.includes(&#x27;TBA&#x27;)) return;

                    &#x2F;&#x2F; Match date pattern: &quot;Month Day(-Day)?, Year&quot;
                    const datePattern = &#x2F;(January|February|March|April|May|June|July|August|September|October|November|December)\s+(\d{1,2})(?:-\d{1,2})?,\s+(\d{4})&#x2F;;
                    const match = text.match(datePattern);

                    if (match) {
                        const monthName = match[1];
                        const day = parseInt(match[2], 10);
                        const year = parseInt(match[3], 10);

                        &#x2F;&#x2F; Map month names to numbers (0-indexed)
                        const monthMap = {
                            &#x27;January&#x27;: 0, &#x27;February&#x27;: 1, &#x27;March&#x27;: 2, &#x27;April&#x27;: 3,
                            &#x27;May&#x27;: 4, &#x27;June&#x27;: 5, &#x27;July&#x27;: 6, &#x27;August&#x27;: 7,
                            &#x27;September&#x27;: 8, &#x27;October&#x27;: 9, &#x27;November&#x27;: 10, &#x27;December&#x27;: 11
                        };

                        &#x2F;&#x2F; Create date object using Date constructor with explicit parameters
                        const confDate = new Date(year, monthMap[monthName], day);
                        const today = new Date();
                        today.setHours(0, 0, 0, 0); &#x2F;&#x2F; Reset time to midnight for accurate day calculation

                        &#x2F;&#x2F; Calculate days difference
                        const diffTime = confDate - today;
                        const diffDays = Math.ceil(diffTime &#x2F; (1000 * 60 * 60 * 24));

                        &#x2F;&#x2F; Add a days badge if conference is in the future
                        if (diffDays &gt; 0) {
                            &#x2F;&#x2F; Check if badge already exists
                            const existingDaysBadge = h3.querySelector(&#x27;.conference-badge.days&#x27;);
                            if (!existingDaysBadge) {
                                const daysBadge = document.createElement(&#x27;span&#x27;);
                                daysBadge.className = &#x27;conference-badge days&#x27;;
                                daysBadge.textContent = `In ${diffDays} days`;
                                h3.appendChild(daysBadge);
                            }
                        }
                    }
                });
                
                break;
            }
            currentElement = currentElement.nextElementSibling;
        }
    });
}

&#x2F;&#x2F; Add CFP open badges
function addCFPBadges() {
    &#x2F;&#x2F; Find all h3 headings (conference titles)
    const headings = document.querySelectorAll(&#x27;article h3&#x27;);

    headings.forEach(h3 =&gt; {
        &#x2F;&#x2F; Find the next list that contains conference details
        let currentElement = h3.nextElementSibling;
        while (currentElement) {
            if (currentElement.tagName === &#x27;UL&#x27;) {
                &#x2F;&#x2F; Found the list, now look for the &quot;CFP:&quot; item
                const listItems = currentElement.querySelectorAll(&#x27;li&#x27;);

                listItems.forEach(li =&gt; {
                    const text = li.textContent;

                    &#x2F;&#x2F; Check if this list item contains &quot;CFP:&quot;
                    if (!text.includes(&#x27;CFP:&#x27;)) return;

                    &#x2F;&#x2F; Check if CFP is open (contains &quot;Open&quot; or &quot;Extended&quot; but not &quot;Closed&quot; or &quot;TBA&quot;)
                    const isOpen = (text.includes(&#x27;Open&#x27;) || text.includes(&#x27;Extended&#x27;)) &amp;&amp;
                                  !text.includes(&#x27;Closed&#x27;) &amp;&amp;
                                  !text.includes(&#x27;TBA&#x27;);

                    if (isOpen) {
                        &#x2F;&#x2F; Check if badge already exists
                        const existingCFPBadge = h3.querySelector(&#x27;.conference-badge.cfp-open&#x27;);
                        if (!existingCFPBadge) {
                            const cfpBadge = document.createElement(&#x27;span&#x27;);
                            cfpBadge.className = &#x27;conference-badge cfp-open&#x27;;
                            cfpBadge.textContent = &#x27;CFP Open&#x27;;
                            cfpBadge.title = &#x27;Call for Proposals is currently open&#x27;;
                            h3.appendChild(cfpBadge);
                        }
                    }
                });

                break;
            }
            currentElement = currentElement.nextElementSibling;
        }
    });
}

&#x2F;&#x2F; Filter conferences
function setupFilters() {
    const filterButtons = document.querySelectorAll(&#x27;.filter-btn&#x27;);
    const headings = document.querySelectorAll(&#x27;article h3&#x27;);

    &#x2F;&#x2F; Store conference data for filtering
    const conferences = [];
    headings.forEach(h3 =&gt; {
        let currentElement = h3.nextElementSibling;
        const conferenceElements = [h3];
        let cfpText = &#x27;&#x27;;
        let whenText = &#x27;&#x27;;

        &#x2F;&#x2F; Collect all elements for this conference
        while (currentElement &amp;&amp; currentElement.tagName !== &#x27;H3&#x27; &amp;&amp; currentElement.tagName !== &#x27;H2&#x27;) {
            conferenceElements.push(currentElement);

            &#x2F;&#x2F; Extract CFP and When info
            if (currentElement.tagName === &#x27;UL&#x27;) {
                const listItems = currentElement.querySelectorAll(&#x27;li&#x27;);
                listItems.forEach(li =&gt; {
                    const text = li.textContent;
                    if (text.includes(&#x27;CFP:&#x27;)) cfpText = text;
                    if (text.includes(&#x27;When:&#x27;)) whenText = text;
                });
            }

            currentElement = currentElement.nextElementSibling;
        }

        conferences.push({
            elements: conferenceElements,
            cfpText: cfpText,
            whenText: whenText
        });
    });

    &#x2F;&#x2F; Handle filter button clicks
    filterButtons.forEach(btn =&gt; {
        btn.addEventListener(&#x27;click&#x27;, () =&gt; {
            &#x2F;&#x2F; Update active state
            filterButtons.forEach(b =&gt; b.classList.remove(&#x27;active&#x27;));
            btn.classList.add(&#x27;active&#x27;);

            const filter = btn.dataset.filter;

            &#x2F;&#x2F; Filter conferences
            conferences.forEach(conf =&gt; {
                let shouldShow = true;

                if (filter === &#x27;cfp-open&#x27;) {
                    const hasCFP = conf.cfpText &amp;&amp;
                                  (conf.cfpText.includes(&#x27;Open&#x27;) || conf.cfpText.includes(&#x27;Extended&#x27;)) &amp;&amp;
                                  !conf.cfpText.includes(&#x27;Closed&#x27;) &amp;&amp;
                                  !conf.cfpText.includes(&#x27;TBA&#x27;);
                    shouldShow = hasCFP;
                } else if (filter === &#x27;announced&#x27;) {
                    shouldShow = conf.whenText &amp;&amp; !conf.whenText.includes(&#x27;TBA&#x27;);
                }
                &#x2F;&#x2F; &#x27;all&#x27; shows everything

                conf.elements.forEach(el =&gt; {
                    el.style.display = shouldShow ? &#x27;&#x27; : &#x27;none&#x27;;
                });
            });
        });
    });
}

&#x2F;&#x2F; Run after DOM is loaded
if (document.readyState === &#x27;loading&#x27;) {
    document.addEventListener(&#x27;DOMContentLoaded&#x27;, () =&gt; {
        initConferenceMap();
        addDaysUntilConference();
        addCFPBadges();
        setupFilters();
    });
} else {
    initConferenceMap();
    addDaysUntilConference();
    addCFPBadges();
    setupFilters();
}
&lt;&#x2F;script&gt;
</description>
      </item>
      <item>
          <title>Prime Video</title>
          <pubDate>Thu, 02 Oct 2025 00:00:00 +0000</pubDate>
          <author>Matthias Endler</author>
          <link>https://corrode.dev/podcast/s05e01-prime-video/</link>
          <guid>https://corrode.dev/podcast/s05e01-prime-video/</guid>
          <description xml:base="https://corrode.dev/podcast/s05e01-prime-video/">&lt;div&gt;&lt;script id=&quot;letscast-player-111a5334&quot; src=&quot;https:&#x2F;&#x2F;letscast.fm&#x2F;podcasts&#x2F;rust-in-production-82281512&#x2F;episodes&#x2F;prime-video-with-alexandru-ene&#x2F;player.js?size=s&quot;&gt;&lt;&#x2F;script&gt;&lt;&#x2F;div&gt;
&lt;p&gt;Are you one of over 240 million subscribers of Amazon’s Prime Video service? If so, you might be surprised to learn that much of the infrastructure behind Prime Video is built using Rust. They use a single codebase for media players, game consoles, and tablets. In this episode, we sit down with Alexandru Ene, a Principal Engineer at Amazon, to discuss how Rust is used at Prime Video, the challenges they face in building a global streaming service, and the benefits of using Rust for their systems.&lt;&#x2F;p&gt;
&lt;div class=&quot;info dashed&quot;&gt;
  &lt;div class=&quot;info-header&quot;&gt;
    &lt;i class=&quot;icon icon-info&quot;&gt;&lt;&#x2F;i&gt;
    &lt;h4&gt;Proudly Supported by CodeCrafters&lt;&#x2F;h4&gt;
  &lt;&#x2F;div&gt;
  &lt;p&gt;
    CodeCrafters helps you become proficient in Rust by building real-world,
    production-grade projects. Learn hands-on by creating your own shell, HTTP
    server, Redis, Kafka, Git, SQLite, or DNS service from scratch.
  &lt;&#x2F;p&gt;
  &lt;p&gt;
    Start for free today and enjoy 40% off any paid plan by using
    &lt;a href=&quot;https:&#x2F;&#x2F;app.codecrafters.io&#x2F;join?via=mre&quot;&gt;this link&lt;&#x2F;a&gt;.
  &lt;&#x2F;p&gt;
&lt;&#x2F;div&gt;
&lt;h2 id=&quot;show-notes&quot;&gt;Show Notes&lt;&#x2F;h2&gt;
&lt;h3 id=&quot;about-prime-video&quot;&gt;About Prime Video&lt;&#x2F;h3&gt;
&lt;p&gt;Prime Video is a streaming service offered by Amazon that provides a wide range of movies, TV shows, and original content to its subscribers. With over 240 million subscribers worldwide, Prime Video is one of the largest streaming platforms in the world. In addition to its vast content library, Prime Video also offers features such as offline viewing, 4K streaming, and support for multiple devices. On the backend, Prime Video relies on a variety of technologies to deliver its content, including Rust, which is used for building high-performance and reliable systems that can handle the demands of a global audience.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;about-alexandru-ene&quot;&gt;About Alexandru Ene&lt;&#x2F;h3&gt;
&lt;p&gt;Alexandru worked on the transition of Prime Video’s user interface from JavaScript to Rust. He has been with Amazon for over 8 years and previously worked at companies like Ubisoft and EA. He has a background in computer science and is an active open source maintainer. Alexandru lives in London.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;links-from-the-episode&quot;&gt;Links From The Episode&lt;&#x2F;h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.youtube.com&#x2F;watch?v=Fsi9HPcyrU8&quot;&gt;Ferris Makes Emulators Ep.001 - The Journey Begins&lt;&#x2F;a&gt; - First episode of a famous series where Jake Taylor wrote a Nintendo 64 emulator in Rust from scratch&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;CMake&quot;&gt;CMake&lt;&#x2F;a&gt; - Very common build system used in C++ applications&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;conan.io&#x2F;&quot;&gt;Conan&lt;&#x2F;a&gt; - C++ Package Manager community project&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;ericlippert.com&#x2F;2003&#x2F;09&#x2F;16&#x2F;smart-pointers-are-too-smart&#x2F;&quot;&gt;C++ Smart Pointers&lt;&#x2F;a&gt; - Still a footgun&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;http:&#x2F;&#x2F;gotw.ca&#x2F;publications&#x2F;concurrency-ddj.htm&quot;&gt;Herb Sutter: The Free Lunch Is Over&lt;&#x2F;a&gt; - The seminal 2005 paper that highlights the importance of concurrency, well past C++’s mainstream adoption&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;corrode.dev&#x2F;podcast&#x2F;s02e01-curl&#x2F;&quot;&gt;Rust in Production: cURL&lt;&#x2F;a&gt; - Baseline library used everywhere, written in C, but performant &lt;em&gt;and&lt;&#x2F;em&gt; safe&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.amazon.com&#x2F;b?node=16775794011&quot;&gt;Prime Video Platforms&lt;&#x2F;a&gt; - One app runs on all of these&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;webassembly.org&#x2F;&quot;&gt;WebAssembly (WASM)&lt;&#x2F;a&gt; - Enabling Rust code with good performance that you can still download and run like JavaScript, avoiding the need for firmware updates on some devices&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Entity_component_system&quot;&gt;Entity Component System&lt;&#x2F;a&gt; - Used in the UI Rust code for pages in the app&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;bevy.org&#x2F;&quot;&gt;Bevy&lt;&#x2F;a&gt; - Game engine written in Rust&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.leptos.dev&#x2F;&quot;&gt;Leptos&lt;&#x2F;a&gt; - UI framework that makes reactive programming in Rust easier&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;tokio.rs&#x2F;&quot;&gt;tokio&lt;&#x2F;a&gt; - The de facto standard async runtime for Rust&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Single_instruction,_multiple_data&quot;&gt;SIMD&lt;&#x2F;a&gt; - A nice feature set some CPUs support&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;bytecodealliance&#x2F;wasm-micro-runtime&quot;&gt;WebAssembly Micro Runtime&lt;&#x2F;a&gt; - A tiny WASM runtime well suited for IoT platforms&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.w3.org&#x2F;groups&#x2F;wg&#x2F;wasm&#x2F;&quot;&gt;WebAssembly Working Group&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h3 id=&quot;official-links&quot;&gt;Official Links&lt;&#x2F;h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.primevideo.com&quot;&gt;Amazon Prime Video&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.youtube.com&#x2F;watch?v=_wcOovoDFMI&quot;&gt;Rust &amp;amp; WASM for UI: Faster Prime Video on ANY Device - Alexandru Ene, QCon San Francisco 2024&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.linkedin.com&#x2F;in&#x2F;alexene0x0a&#x2F;&quot;&gt;Alexandru Ene on LinkedIn&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;alexene.dev&quot;&gt;Alexandru’s Blog&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;AlexEne&quot;&gt;Alexandru Ene on GitHub&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
</description>
      </item>
      <item>
          <title>Be Simple</title>
          <pubDate>Thu, 11 Sep 2025 00:00:00 +0000</pubDate>
          <author>Matthias Endler</author>
          <link>https://corrode.dev/blog/simple/</link>
          <guid>https://corrode.dev/blog/simple/</guid>
          <description xml:base="https://corrode.dev/blog/simple/">&lt;p&gt;&lt;strong&gt;The phone buzzes at 3 AM.&lt;&#x2F;strong&gt;&lt;&#x2F;p&gt;
&lt;p&gt;You roll out of bed, open your laptop, and see this in the logs:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;thread &amp;#39;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;tokio&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;-&lt;&#x2F;span&gt;&lt;span&gt;runtime&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;-&lt;&#x2F;span&gt;&lt;span&gt;worker&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt;&amp;#39; panicked at &amp;#39;&lt;&#x2F;span&gt;&lt;span&gt;called `&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;Result&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;unwrap&lt;&#x2F;span&gt;&lt;span&gt;()` on an `&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;Err&lt;&#x2F;span&gt;&lt;span&gt;` value&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span&gt; &lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;Error&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt;&amp;quot;data did not match any variant of untagged enum Customer at line 1 column 15&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt;&amp;#39;, &lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt;src&#x2F;parsers&#x2F;universal.rs:47:23&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;You open the codebase and find this:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;pub struct&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; UniversalParser&lt;&#x2F;span&gt;&lt;span&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;T&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; DeserializeOwned&lt;&#x2F;span&gt;&lt;span&gt;&amp;gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    format&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Box&lt;&#x2F;span&gt;&lt;span&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;dyn&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; DataFormat&lt;&#x2F;span&gt;&lt;span&gt;&amp;gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    _marker&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span&gt; std&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span&gt;marker&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;PhantomData&lt;&#x2F;span&gt;&lt;span&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;T&lt;&#x2F;span&gt;&lt;span&gt;&amp;gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;impl&lt;&#x2F;span&gt;&lt;span&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;T&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; DeserializeOwned&lt;&#x2F;span&gt;&lt;span&gt;&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; UniversalParser&lt;&#x2F;span&gt;&lt;span&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;T&lt;&#x2F;span&gt;&lt;span&gt;&amp;gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    pub fn&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; parse&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;&amp;amp;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;font-style: italic;&quot;&gt;self&lt;&#x2F;span&gt;&lt;span&gt;, content&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;: &amp;amp;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;str&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; -&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Result&lt;&#x2F;span&gt;&lt;span&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;Vec&lt;&#x2F;span&gt;&lt;span&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;T&lt;&#x2F;span&gt;&lt;span&gt;&amp;gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Box&lt;&#x2F;span&gt;&lt;span&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;dyn&lt;&#x2F;span&gt;&lt;span&gt; std&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span&gt;error&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;Error&lt;&#x2F;span&gt;&lt;span&gt;&amp;gt;&amp;gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #BD93F9;font-style: italic;&quot;&gt;        self&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span&gt;format&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;parse&lt;&#x2F;span&gt;&lt;span&gt;(content)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;A few thoughts rush through your head:&lt;&#x2F;p&gt;
&lt;p&gt;“What the hell is a PhantomData?”&lt;br &#x2F;&gt;
“Why is there a trait object?”&lt;br &#x2F;&gt;
“This is going to be a long night.”&lt;&#x2F;p&gt;
&lt;p&gt;The error must be buried &lt;em&gt;somewhere&lt;&#x2F;em&gt; in the interaction between that &lt;code&gt;DataFormat&lt;&#x2F;code&gt; trait, the generic parser, and serde deserialization.
You scroll through 200 lines of trait implementations and generic constraints.
Each layer adds another level of indirection.
The stack trace is 15 levels deep.
It’s like peeling an onion… it makes you cry.&lt;&#x2F;p&gt;
&lt;p&gt;You run &lt;code&gt;git blame&lt;&#x2F;code&gt; and curse the colleague who wrote this code.
Whoops, it was you a few months ago.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;strong&gt;Quick rewind. The phone buzzes at 3 AM.&lt;&#x2F;strong&gt;&lt;&#x2F;p&gt;
&lt;p&gt;You roll out of bed, open your laptop, and see this in the logs:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;plain&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;Error: CSV parse error at line 847: invalid UTF-8 sequence at byte index 23&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;You find this code:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;#[derive(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;Debug&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Deserialize&lt;&#x2F;span&gt;&lt;span&gt;)]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;pub struct&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Customer&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    pub&lt;&#x2F;span&gt;&lt;span&gt; name&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; String&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    pub&lt;&#x2F;span&gt;&lt;span&gt; email&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; String&lt;&#x2F;span&gt;&lt;span&gt;, &lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    pub&lt;&#x2F;span&gt;&lt;span&gt; phone&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; String&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;pub fn&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; parse_customers&lt;&#x2F;span&gt;&lt;span&gt;(csv_content&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;: &amp;amp;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;str&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; -&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Result&lt;&#x2F;span&gt;&lt;span&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;Vec&lt;&#x2F;span&gt;&lt;span&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;Customer&lt;&#x2F;span&gt;&lt;span&gt;&amp;gt;, csv&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;Error&lt;&#x2F;span&gt;&lt;span&gt;&amp;gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    let mut&lt;&#x2F;span&gt;&lt;span&gt; reader&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; csv&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;Reader&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;from_reader&lt;&#x2F;span&gt;&lt;span&gt;(csv_content&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;as_bytes&lt;&#x2F;span&gt;&lt;span&gt;());&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    reader&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;deserialize&lt;&#x2F;span&gt;&lt;span&gt;()&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;collect&lt;&#x2F;span&gt;&lt;span&gt;()&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;All right, we seem to be parsing some customer data from a CSV file.&lt;&#x2F;p&gt;
&lt;p&gt;You look at line 847 of the input file and see corrupted character encoding.
You remove the bad line, deploy a fix, and go back to sleep.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;don-t-be-clever&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#don-t-be-clever&quot; aria-label=&quot;Anchor link for: don-t-be-clever&quot;&gt;Don’t Be Clever&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;p&gt;Rust programmers tend to be very clever.
Too clever for their own good at times.
Let me be the first to admit that I’m guilty of this myself.&lt;&#x2F;p&gt;
&lt;p&gt;We love to stretch Rust to its limits.
After all, this is Rust!
An empowering playground of infinite possibility.
Shouldn’t we use the language to its full extent?&lt;&#x2F;p&gt;
&lt;p&gt;Nothing in Rust forces us to be fancy.
You can write straightforward code in Rust just like in any other language.
But in code reviews, I often see people trying to outsmart themselves and stumbling over their own shoelaces.
They use all the advanced features at their disposal without thinking much about maintainability.&lt;&#x2F;p&gt;
&lt;p&gt;Here’s the problem: &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;idiallo.com&#x2F;blog&#x2F;writing-code-is-easy-reading-is-hard&quot;&gt;Writing code is easy. Reading it isn’t.&lt;&#x2F;a&gt;
These advanced features are like salt: a little bit can enhance the flavor, but too much can ruin the dish.
And advanced features have a tendency to overcomplicate things and make readability harder.&lt;&#x2F;p&gt;
&lt;p&gt;Software engineering is all about managing complexity, and complexity creeps in when we’re not looking.
We should focus on keeping complexity down.&lt;&#x2F;p&gt;
&lt;p&gt;Of course, some complexity is truly unavoidable.
That’s the inherent complexity of the task.
What we should avoid, however, is the accidental complexity, which we introduce ourselves.
As projects grow, accidental complexity tends to grow with them.
That is the cruft we all should challenge.&lt;&#x2F;p&gt;
&lt;p&gt;And simplicity also has other benefits:&lt;&#x2F;p&gt;
&lt;blockquote&gt;
&lt;p&gt;Simplicity is prerequisite for reliability.&lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
&lt;p&gt;I don’t always agree with Edsger W. Dijkstra, but in this case, he was spot-on.
Without simplicity, reliability is impossible (or at least hard to achieve).
That’s because simple systems have fewer moving parts to reason about.&lt;&#x2F;p&gt;
&lt;p&gt;Good code is mostly boring, especially for production use.
Simple is obvious.
Simple is predictable.
Predictable is good.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;why-simple-is-hard&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#why-simple-is-hard&quot; aria-label=&quot;Anchor link for: why-simple-is-hard&quot;&gt;Why Simple is Hard&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;p&gt;But if simplicity is so obviously “better,” why isn’t it the norm?
Because achieving simplicity is hard!
It doesn’t come naturally.
Simplicity is typically not the &lt;em&gt;first attempt&lt;&#x2F;em&gt; but the &lt;em&gt;last revision&lt;&#x2F;em&gt;. &lt;sup class=&quot;footnote-reference&quot; id=&quot;fr-pascal-1&quot;&gt;&lt;a href=&quot;#fn-pascal&quot;&gt;1&lt;&#x2F;a&gt;&lt;&#x2F;sup&gt;&lt;&#x2F;p&gt;
&lt;blockquote&gt;
&lt;p&gt;Simplicity and elegance are unpopular because they require hard work and discipline to achieve.&lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
&lt;p&gt;Well put, Edsger.&lt;&#x2F;p&gt;
&lt;p&gt;It takes &lt;em&gt;effort&lt;&#x2F;em&gt; to build simple systems.
It takes even more effort to &lt;em&gt;keep&lt;&#x2F;em&gt; them simple.
That’s because you constantly have to fight &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Entropy&quot;&gt;entropy&lt;&#x2F;a&gt;.
Going from simple to more complex is much easier than the reverse.&lt;&#x2F;p&gt;
&lt;p&gt;Let’s come back to our 3 AM phone call.&lt;&#x2F;p&gt;
&lt;p&gt;The first version of the code was built by an engineer who wanted to make the system “flexible and extensible.”
The second was written by a developer who just wanted to parse a CSV file.
Turns out there never once was a need to parse anything other than CSV files.&lt;&#x2F;p&gt;
&lt;p&gt;Of course, the original author likely had good reasons for their design.
Maybe prior experience might have suggested that more formats would be needed in the future?
Or the team wanted to simplify testing by mocking the data format and ended up with a set of abstractions that turned out to be limiting?
And shouldn’t the problem have been discovered during code review?&lt;&#x2F;p&gt;
&lt;p&gt;These are all valid points!
But code reviews also take effort, and it’s easy to miss the forest for the trees.
A less experienced Rust developer might not have the experience to evaluate the situation properly and saying “I don’t get it” also takes courage.
And even if the code review had caught the complexity, it might have consumed a lot of energy to convince the original author to simplify the code or to change the design because of deadlines or sunk cost fallacies.
It’s easy to judge past decisions with hindsight; that’s not my intention.
Quite the opposite, actually:
&lt;strong&gt;a series of individually perfectly reasonable decisions can lead to an overly complex, unmaintainable system.&lt;&#x2F;strong&gt;
And taken in isolation, each small bit of complexity looks harmless.
But complexity quickly compounds.&lt;&#x2F;p&gt;
&lt;p&gt;One lesson here is that the path to complexity is paved with good intentions.
Another is that senior engineers should pair with junior ones more often to avoid knowledge silos.&lt;&#x2F;p&gt;
&lt;p&gt;More experienced developers tend to use more abstractions because they get excited about the possibilities.
And I can’t blame them, really.
Writing simple code is oftentimes pretty boring.
It’s much more fun to test out that new feature we just learned.
But after a while we forget how Rust beginners feel about our code: it’s the &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Curse_of_knowledge&quot;&gt;curse of knowledge&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;Remember: &lt;strong&gt;abstractions are never zero cost.&lt;&#x2F;strong&gt; &lt;sup class=&quot;footnote-reference&quot; id=&quot;fr-nasa-1&quot;&gt;&lt;a href=&quot;#fn-nasa&quot;&gt;2&lt;&#x2F;a&gt;&lt;&#x2F;sup&gt;&lt;&#x2F;p&gt;
&lt;blockquote&gt;
&lt;p&gt;Not all abstractions are created equal.&lt;&#x2F;p&gt;
&lt;p&gt;In fact, many are not abstractions at all — they’re just thin veneers, layers of
indirection that add complexity without adding real value.&lt;&#x2F;p&gt;
&lt;p&gt;– &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;fhur.me&#x2F;posts&#x2F;2024&#x2F;thats-not-an-abstraction&quot;&gt;Fernando Hurtado Cardenas&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
&lt;p&gt;Abstractions cause complexity, and complexity has very real consequences.
At some point, complexity will slow you down because it causes cognitive load.
And cognitive load matters a lot because our mental capacity is finite.&lt;&#x2F;p&gt;
&lt;p&gt;The people who are starting with Rust are often overwhelmed by the complexity of the language.
Try to keep that in mind as you get more proficient.
If you fail to do that, you might alienate team members who are not as experienced as you, and they might give up on the project or Rust altogether.&lt;&#x2F;p&gt;
&lt;p&gt;Furthermore, if you switch companies and leave behind a complex codebase, the team will have a hard time maintaining it and onboarding new team members.
The biggest holdup is &lt;a href=&quot;&#x2F;blog&#x2F;flattening-rusts-learning-curve&quot;&gt;how quickly people will be able to get up to speed with Rust&lt;&#x2F;a&gt;.
Don’t make it even harder on them.
From time to time, look at Rust through a beginner’s eyes.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;generics-are-a-liability&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#generics-are-a-liability&quot; aria-label=&quot;Anchor link for: generics-are-a-liability&quot;&gt;Generics Are A Liability&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;p&gt;For some reason I feel compelled to talk about generics for a moment…&lt;&#x2F;p&gt;
&lt;p&gt;Not only do they make the code harder to understand, they can also have a real cost on compile times.
Each generic gets monomorphized, i.e. a separate copy of the code is generated for each type that is used with that generic at compile time.&lt;&#x2F;p&gt;
&lt;p&gt;My advice is to only make something generic if you need to switch out the implementation &lt;em&gt;right now&lt;&#x2F;em&gt;.
Resist premature generalization!
(Which is related—but not identical to—premature optimization.)&lt;&#x2F;p&gt;
&lt;p&gt;“We might need it in the future” is a dangerous statement.
The classic example is “we might need to switch databases in the future” leading to over-abstracted data access layers that nobody asked for.
Be careful with that assumption because it’s hard to predict the future. &lt;sup class=&quot;footnote-reference&quot; id=&quot;fr-future-1&quot;&gt;&lt;a href=&quot;#fn-future&quot;&gt;3&lt;&#x2F;a&gt;&lt;&#x2F;sup&gt;&lt;&#x2F;p&gt;
&lt;p&gt;Your beautiful abstraction might become your biggest nemesis.
If you can defer the decision for &lt;em&gt;just&lt;&#x2F;em&gt; a little longer, it’s often better to do so.&lt;&#x2F;p&gt;
&lt;p&gt;Generics also have an impact on the “feel” of the entire codebase.
If you use a lot of generics, you will have to deal with the consequences everywhere.
You will have to understand the signatures of functions and structs as well as the error messages that come with them.
The hidden compilation cost of generics is hard to measure and optimize for.&lt;&#x2F;p&gt;
&lt;p&gt;Use generics sparingly.
The thinking should be “this is generic functionality” instead of “I could make this generic.”&lt;&#x2F;p&gt;
&lt;p&gt;Let’s say you are working on a public API.
A function that will be used a lot will need to take some string-based data from the user.
You wonder whether you should take a &lt;code&gt;&amp;amp;str&lt;&#x2F;code&gt; or a &lt;code&gt;String&lt;&#x2F;code&gt; or something else as an input to your functions and why.&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;fn&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; process_user_input&lt;&#x2F;span&gt;&lt;span&gt;(input&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;: &amp;amp;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;str&lt;&#x2F;span&gt;&lt;span&gt;) {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;    &#x2F;&#x2F; do something with input&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;That’s quite simple and doesn’t allocate.
But what if the caller wants to pass a String?&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;fn&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; process_user_input&lt;&#x2F;span&gt;&lt;span&gt;(input&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; String&lt;&#x2F;span&gt;&lt;span&gt;) {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;    &#x2F;&#x2F; do something with input&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;We take ownership of the input.
But hold on, what if we don’t need ownership and we want to support both?&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;fn&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; process_user_input&lt;&#x2F;span&gt;&lt;span&gt;(input&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;: impl&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; AsRef&lt;&#x2F;span&gt;&lt;span&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;str&lt;&#x2F;span&gt;&lt;span&gt;&amp;gt;) {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;    &#x2F;&#x2F; do something with input&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;That works.
But do you see how the complexity goes up?&lt;&#x2F;p&gt;
&lt;p&gt;Behind the scenes, it monomorphizes the function for each type that implements &lt;code&gt;AsRef&amp;lt;str&amp;gt;&lt;&#x2F;code&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;That means that if we pass a &lt;code&gt;String&lt;&#x2F;code&gt; and a &lt;code&gt;&amp;amp;str&lt;&#x2F;code&gt;, we get two copies of that function.
That means longer compile times and larger binaries.&lt;&#x2F;p&gt;
&lt;p&gt;Wait, what if we need to return something that references the input and we need the result to live as long as the input?&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;fn&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; process_user_input&lt;&#x2F;span&gt;&lt;span&gt;&amp;lt;&amp;#39;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;a&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; S&lt;&#x2F;span&gt;&lt;span&gt;&amp;gt;(input&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;: &amp;amp;&lt;&#x2F;span&gt;&lt;span&gt;&amp;#39;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;a S&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; -&amp;gt; &amp;amp;&lt;&#x2F;span&gt;&lt;span&gt;&amp;#39;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;a str&lt;&#x2F;span&gt;&lt;span&gt; &lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;where&lt;&#x2F;span&gt;&lt;span&gt; &lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;    S&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; AsRef&lt;&#x2F;span&gt;&lt;span&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;str&lt;&#x2F;span&gt;&lt;span&gt;&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; + ?&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;Sized&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;{&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;    &#x2F;&#x2F; do something with input&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Oh wait, we might need to send this across threads:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;fn&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; process_user_input&lt;&#x2F;span&gt;&lt;span&gt;&amp;lt;&amp;#39;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;a&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; S&lt;&#x2F;span&gt;&lt;span&gt;&amp;gt;(input&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;: &amp;amp;&lt;&#x2F;span&gt;&lt;span&gt;&amp;#39;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;a S&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; -&amp;gt; &amp;amp;&lt;&#x2F;span&gt;&lt;span&gt;&amp;#39;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;a str&lt;&#x2F;span&gt;&lt;span&gt; &lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;where&lt;&#x2F;span&gt;&lt;span&gt; &lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;    S&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; AsRef&lt;&#x2F;span&gt;&lt;span&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;str&lt;&#x2F;span&gt;&lt;span&gt;&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; +&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Send&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; +&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Sync&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; + ?&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;Sized&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;{&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;    &#x2F;&#x2F; do something with input&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;See how we went from a simple &lt;code&gt;&amp;amp;str&lt;&#x2F;code&gt; parameter to this monstrosity?
Each step seemed “reasonable,” but we’ve created a nightmare that nobody wants to read or debug.&lt;&#x2F;p&gt;
&lt;p&gt;The problem is so simple, so how did that complexity creep in?
We were trying to be clever!
We were trying to improve the function by making it more generic.
But is it really “better”?&lt;&#x2F;p&gt;
&lt;p&gt;All we wanted was a simple function that takes a string and does something with it.&lt;&#x2F;p&gt;
&lt;p&gt;Stay simple.
Don’t overthink it!&lt;&#x2F;p&gt;
&lt;p&gt;Say we’re writing a &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;lycheeverse&#x2F;lychee&quot;&gt;link checker&lt;&#x2F;a&gt; and we want to build a bunch of requests to check the links.
We could use a function that returns a &lt;code&gt;Vec&amp;lt;Result&amp;lt;Request&amp;gt;&amp;gt;&lt;&#x2F;code&gt;.&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;fn&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; create_requests&lt;&#x2F;span&gt;&lt;span&gt;(urls&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Vec&lt;&#x2F;span&gt;&lt;span&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;String&lt;&#x2F;span&gt;&lt;span&gt;&amp;gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; -&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Vec&lt;&#x2F;span&gt;&lt;span&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;Result&lt;&#x2F;span&gt;&lt;span&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;Request&lt;&#x2F;span&gt;&lt;span&gt;&amp;gt;&amp;gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    urls&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;into_iter&lt;&#x2F;span&gt;&lt;span&gt;()&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;        .&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;map&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;|&lt;&#x2F;span&gt;&lt;span&gt;url&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;|&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; create_request&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;&amp;amp;&lt;&#x2F;span&gt;&lt;span&gt;url))&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;        .&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;collect&lt;&#x2F;span&gt;&lt;span&gt;()&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Or, we could return an iterator instead:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;fn&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; create_requests&lt;&#x2F;span&gt;&lt;span&gt;(urls&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Vec&lt;&#x2F;span&gt;&lt;span&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;String&lt;&#x2F;span&gt;&lt;span&gt;&amp;gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; -&amp;gt; impl&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Iterator&lt;&#x2F;span&gt;&lt;span&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;Item&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Result&lt;&#x2F;span&gt;&lt;span&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;Request&lt;&#x2F;span&gt;&lt;span&gt;&amp;gt;&amp;gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    urls&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;into_iter&lt;&#x2F;span&gt;&lt;span&gt;()&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;map&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;|&lt;&#x2F;span&gt;&lt;span&gt;url&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;|&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; create_request&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;&amp;amp;&lt;&#x2F;span&gt;&lt;span&gt;url))&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;The iterator doesn’t look too bad, but the vec is simpler.
What to do?
The caller likely needs to collect the results anyway.
Since we’re processing a finite set of URLs, the link checker needs all results to report successes&#x2F;failures, and the results will probably be iterated multiple times.
Memory usage isn’t a big concern here since the number of URLs in a document is typically small.
All else being equal, the vec is probably the simpler choice.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;simple-code-is-often-fast-code&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#simple-code-is-often-fast-code&quot; aria-label=&quot;Anchor link for: simple-code-is-often-fast-code&quot;&gt;Simple Code Is Often Fast Code&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;p&gt;There’s a prejudice that simple code is slow.
Quite the contrary!
It turns out many effective algorithms are surprisingly simple.
In fact, some of the simplest algorithms we’ve discovered are also the most efficient.&lt;&#x2F;p&gt;
&lt;p&gt;Take quicksort or path tracing, for example.
Both can be written down in a handful of lines and described in a few sentences.&lt;&#x2F;p&gt;
&lt;p&gt;The idea is pretty simple and can fit on a napkin:&lt;&#x2F;p&gt;
&lt;ol&gt;
&lt;li&gt;Try to get the first element from the list. If there is no element, the list is empty and we’re done.&lt;&#x2F;li&gt;
&lt;li&gt;Split the list into two sublists: elements smaller than the pivot and elements larger than or equal to the pivot.&lt;&#x2F;li&gt;
&lt;li&gt;Sort each sublist recursively.&lt;&#x2F;li&gt;
&lt;li&gt;By combining the sorted smaller list, the pivot, and the sorted larger list, you get the fully sorted list!&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;p&gt;Here’s an ad-hoc version of this algorithm in Rust:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;pub fn&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; quicksort&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;mut&lt;&#x2F;span&gt;&lt;span&gt; v&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Vec&lt;&#x2F;span&gt;&lt;span&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;usize&lt;&#x2F;span&gt;&lt;span&gt;&amp;gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; -&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Vec&lt;&#x2F;span&gt;&lt;span&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;usize&lt;&#x2F;span&gt;&lt;span&gt;&amp;gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    let&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Some&lt;&#x2F;span&gt;&lt;span&gt;(pivot)&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; v&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;pop&lt;&#x2F;span&gt;&lt;span&gt;()&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; else&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;        return&lt;&#x2F;span&gt;&lt;span&gt; v;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    };&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    let&lt;&#x2F;span&gt;&lt;span&gt; (smaller, larger)&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; v&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;into_iter&lt;&#x2F;span&gt;&lt;span&gt;()&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;partition&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;|&lt;&#x2F;span&gt;&lt;span&gt;x&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;|&lt;&#x2F;span&gt;&lt;span&gt; x &amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; &amp;amp;&lt;&#x2F;span&gt;&lt;span&gt;pivot);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;    quicksort&lt;&#x2F;span&gt;&lt;span&gt;(smaller)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;        .&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;into_iter&lt;&#x2F;span&gt;&lt;span&gt;()&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;        .&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;chain&lt;&#x2F;span&gt;&lt;span&gt;(std&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span&gt;iter&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;once&lt;&#x2F;span&gt;&lt;span&gt;(pivot))&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;        .&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;chain&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;quicksort&lt;&#x2F;span&gt;&lt;span&gt;(larger))&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;        .&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;collect&lt;&#x2F;span&gt;&lt;span&gt;()&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;It’s not too far off from the description.&lt;&#x2F;p&gt;
&lt;p&gt;Yes, my simple implementation only supports &lt;code&gt;usize&lt;&#x2F;code&gt; right now and for any real-world use case, you should use the &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;doc.rust-lang.org&#x2F;std&#x2F;primitive.slice.html#method.sort&quot;&gt;built-in sort algorithm&lt;&#x2F;a&gt;, which is 20x faster than the above version in my benchmarks, but my point is that simple code packs a punch.
On my machine, this implementation sorts 100k numbers in 1 millisecond.&lt;&#x2F;p&gt;
&lt;p&gt;This is an O(n log n) algorithm.
It’s as fast as it gets for a comparison-based sort and it’s just a few lines of code. &lt;sup class=&quot;footnote-reference&quot; id=&quot;fr-optimization-1&quot;&gt;&lt;a href=&quot;#fn-optimization&quot;&gt;4&lt;&#x2F;a&gt;&lt;&#x2F;sup&gt;&lt;&#x2F;p&gt;
&lt;p&gt;Often, simple code can be optimized by the compiler more easily and runs faster on CPUs.
That’s because CPUs are optimized for basic data structures and predictable access patterns.
And parallelizing work is also easier when that is the case.
All of that works in our favor when our code is simple.&lt;&#x2F;p&gt;
&lt;p&gt;Somewhat counterintuitively, especially when you’re doing something complicated, you should be extra careful to keep it simple.
Simplicity is a sign of deep insight, of great understanding, of clarity—and clarity has a positive effect on the way a system functions.
And since complicated systems are, well, complicated, that extra clarity helps keep things under control.&lt;&#x2F;p&gt;
&lt;p&gt;What I appreciate about Rust is how it balances high-level and low-level programming.
We should leverage that more often.
Most of the time, I write Rust code in a straightforward manner, and when that extra bit of performance becomes critical, Rust always lets me go back and optimize.&lt;&#x2F;p&gt;
&lt;p&gt;For example, in hot code paths, avoiding allocations might make sense, at which point you might have to deal with &lt;a href=&quot;&#x2F;blog&#x2F;lifetimes&#x2F;&quot;&gt;lifetimes&lt;&#x2F;a&gt;.
But that’s a late-stage optimization. Don’t reach for it while the design is still in flux.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;keep-your-users-in-mind&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#keep-your-users-in-mind&quot; aria-label=&quot;Anchor link for: keep-your-users-in-mind&quot;&gt;Keep Your Users in Mind&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;p&gt;Most of the code you’ll write for companies will be application code, not library code.
That’s because most companies don’t make money writing libraries, but business logic.
There’s no need to get fancy here.
Application code should be straightforward.&lt;&#x2F;p&gt;
&lt;p&gt;Library code can be a slightly different story.
It can get complicated if it ends up being an important building block for other code.
For example, in hot code paths, avoiding allocations might make sense, at which point you might have to deal with &lt;a href=&quot;&#x2F;blog&#x2F;lifetimes&quot;&gt;lifetimes&lt;&#x2F;a&gt;.
This uncertainty about how code might get used by others can lead to overabstraction.
Try to make the common case straightforward.
The correct path should be the obvious path users take.&lt;&#x2F;p&gt;
&lt;p&gt;Say you’re building a base64 encoder.
It’s safe to assume that most people will want to encode a string (probably a unicode string like a &lt;code&gt;&amp;amp;str&lt;&#x2F;code&gt;) and that they want to use a “canonical” or “standard” base64 encoding.
Don’t expect your users to jump through hoops to do the &lt;em&gt;most common thing&lt;&#x2F;em&gt;.
Unless you have a &lt;em&gt;really&lt;&#x2F;em&gt; good reason, your API should have a function like this somewhere:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;&#x2F;&#x2F;&#x2F; Encode input as Base64 string&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;fn&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; base64_encode&lt;&#x2F;span&gt;&lt;span&gt;(input&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;: &amp;amp;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;str&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; -&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; String&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Yes, you could make it generic over &lt;code&gt;AsRef&amp;lt;[u8]&amp;gt;&lt;&#x2F;code&gt; or support multiple alphabets:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;&#x2F;&#x2F;&#x2F; Generic base64 encoder supporting multiple alphabets&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;fn&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; base64_encode&lt;&#x2F;span&gt;&lt;span&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;T&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; AsRef&lt;&#x2F;span&gt;&lt;span&gt;&amp;lt;[&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;u8&lt;&#x2F;span&gt;&lt;span&gt;]&amp;gt;&amp;gt;(input&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; T&lt;&#x2F;span&gt;&lt;span&gt;, alphabet&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Base64Alphabet&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; -&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; String&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;…and you might even offer a builder pattern for maximum flexibility:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;let&lt;&#x2F;span&gt;&lt;span&gt; encoded&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Base64Encoder&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;new&lt;&#x2F;span&gt;&lt;span&gt;()&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    .&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;with_alphabet&lt;&#x2F;span&gt;&lt;span&gt;(Base64Alphabet&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;UrlSafe&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt; &#x2F;&#x2F; What is UrlSafe?&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    .&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;with_decode_allow_trailing_bits&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt;true&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt; &#x2F;&#x2F; Huh?&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    .&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;with_decode_padding_mode&lt;&#x2F;span&gt;&lt;span&gt;(engine&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span&gt;DecodePaddingMode&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;RequireNone&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt; &#x2F;&#x2F; I don&amp;#39;t even...&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    .&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;encode&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt;&amp;quot;Hello, world!&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;But what most users care about is how to get an encoded string:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;let&lt;&#x2F;span&gt;&lt;span&gt; encoded&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; base64_encode&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt;&amp;quot;Hello, world!&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;You could call the function above &lt;code&gt;base64_encode_simple&lt;&#x2F;code&gt; or &lt;code&gt;base64::encode_standard&lt;&#x2F;code&gt; to make it clear that it’s a simplified version of a more generic algorithm.&lt;&#x2F;p&gt;
&lt;p&gt;Simplicity is especially important when working with other developers because code is a way to communicate ideas, and you should strive to express your ideas clearly.
It’s fine to offer additional functionality, but don’t make the easy thing hard in the process.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;tips-for-fighting-complexity&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#tips-for-fighting-complexity&quot; aria-label=&quot;Anchor link for: tips-for-fighting-complexity&quot;&gt;Tips For Fighting Complexity&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;blockquote&gt;
&lt;p&gt;Controlling complexity is the essence of computer programming.
– &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;The_Elements_of_Programming_Style&quot;&gt;Brian Kernighan and P.J. Plauger, The Elements of Programming Style&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
&lt;h3 id=&quot;start-small&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#start-small&quot; aria-label=&quot;Anchor link for: start-small&quot;&gt;Start Small&lt;&#x2F;a&gt;&lt;&#x2F;h3&gt;
&lt;p&gt;Jerry Seinfeld had two writing modes: &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;perell.com&#x2F;note&#x2F;the-jerry-seinfeld-guide-to-writing&#x2F;&quot;&gt;creating mode and editing mode&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;When in creating mode, he’s exploring possibilities and letting ideas flow freely.&lt;&#x2F;li&gt;
&lt;li&gt;When in editing mode, he’s refining, cutting, and polishing.&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;These modes require different mindsets, and trying to do both simultaneously leads to paralysis.
As a consequence, Seinfeld would never edit while creating because it would kill the creative flow.&lt;&#x2F;p&gt;
&lt;p&gt;The same principle applies to coding.
Don’t try to architect the perfect solution on your first attempt.
Write the naïve implementation first, then let your inner editor refine it.
Switch off that inner critic.
Who knows?
You might just come up with a simpler design!&lt;&#x2F;p&gt;
&lt;h3 id=&quot;resist-the-temptation-to-optimize-early&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#resist-the-temptation-to-optimize-early&quot; aria-label=&quot;Anchor link for: resist-the-temptation-to-optimize-early&quot;&gt;Resist the Temptation To Optimize Early&lt;&#x2F;a&gt;&lt;&#x2F;h3&gt;
&lt;p&gt;It can be tempting to use all of these fine, sharp tools you have at your disposal.
But sharp tools they are!
To master Rust is to say “no” to these tools more often than you say “yes.”&lt;&#x2F;p&gt;
&lt;p&gt;You might see an optimization opportunity and feel the urge to jump at it.
But time and again, I see people make that optimization without prior validation.
The result is that the code performs the same or becomes slower or is otherwise less ideal than the previous version.
Measure twice, cut once.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;defer-refactoring&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#defer-refactoring&quot; aria-label=&quot;Anchor link for: defer-refactoring&quot;&gt;Defer Refactoring&lt;&#x2F;a&gt;&lt;&#x2F;h3&gt;
&lt;p&gt;That might sound counterintuitive.
After all, shouldn’t constant refactoring make our code better as we go?&lt;&#x2F;p&gt;
&lt;p&gt;The problem is that we have limited information at the time of writing our first prototype.
If we refactor too early, we might end up in a worse place than where we started.&lt;&#x2F;p&gt;
&lt;p&gt;Take the CSV exporter from the beginning as an example: a smart engineer saw an opportunity to refactor the code in order to support multiple input formats.
That locked us into a place where we had a generic exporter, which became a huge debugging burden while preventing us from seeing a better abstraction had we deferred the refactoring.
Maybe we would have noticed that we’re always dealing with CSV data, but we could decouple data validation from data exportation.
If we had seen that, it would have led to better error messages like:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;plain&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;Error: Customer 123 has invalid address field:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;Invalid UTF-8 sequence at byte index 23: Address: &amp;quot;123 M\xE9n St.&amp;quot;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;This opportunity was lost because we jumped the gun and refactored too early.&lt;&#x2F;p&gt;
&lt;p&gt;I propose solving the problem at hand first and refactoring afterward.
That’s because refactoring a simple program is way easier than doing the same for a complex one.
Everyone can do the former, while I can count on one hand those who can do the latter.
Preserve the opportunity to refactor your code.
Refactoring might look like the smart thing to do at the time, but if you allow the simple code to just stick around for a little longer, the right opportunity for the refactor might present itself.&lt;&#x2F;p&gt;
&lt;p&gt;A good time to reflect is when your code starts to feel repetitive.
That’s a sign that there’s a hidden pattern in your data.
The right abstraction is trying to talk to you!
It’s fine to make multiple attempts at an abstraction.
See what feels right.
If none of it does, just go back to the simple version and document your findings.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;performance-crimes-are-ok&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#performance-crimes-are-ok&quot; aria-label=&quot;Anchor link for: performance-crimes-are-ok&quot;&gt;Performance Crimes Are “OK”&lt;&#x2F;a&gt;&lt;&#x2F;h3&gt;
&lt;p&gt;Rust is super fast, so you can literally commit all the performance crimes you like.
Clone liberally, iterate over the same data structure multiple times, use a vector where a hashmap would be better.&lt;&#x2F;p&gt;
&lt;p&gt;It simply doesn’t matter.
Hardware is fast and cheap, so put it to work.&lt;&#x2F;p&gt;
&lt;p&gt;Despite this reality, there’s a noticeable tendency among Rust developers to add significant complexity or extra code to avoid any and all allocations in code that isn’t even performance-critical.
I think that’s because Rust is very anal about memory management, which makes developers hyper-aware of these costs.
This awareness can get in the way of simplicity.
Sometimes using &lt;code&gt;Arc&lt;&#x2F;code&gt; or &lt;code&gt;Box&lt;&#x2F;code&gt; is not worth optimizing away if it keeps the code simple.&lt;&#x2F;p&gt;
&lt;p&gt;If you’d like to learn more, I gave a talk on that topic titled &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;corrode&#x2F;four-horsemen-talk&quot;&gt;The Four Horsemen of Bad Rust Code&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;be-curious-but-conservative&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#be-curious-but-conservative&quot; aria-label=&quot;Anchor link for: be-curious-but-conservative&quot;&gt;Be Curious But Conservative&lt;&#x2F;a&gt;&lt;&#x2F;h3&gt;
&lt;p&gt;All of the above doesn’t mean you should not learn about the good abstractions.
It’s fun to learn and to be knowledgeable.&lt;&#x2F;p&gt;
&lt;p&gt;But you can focus on learning new concepts without hurting yourself.
Understanding macros, lifetimes, interior mutability, etc. is very helpful, but in everyday “normal” Rust code you almost never make use of these concepts, so don’t worry about them too much and keep moving.&lt;&#x2F;p&gt;
&lt;p&gt;Use all the features you need and none you don’t.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;don-t-confuse-simple-with-sloppy&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#don-t-confuse-simple-with-sloppy&quot; aria-label=&quot;Anchor link for: don-t-confuse-simple-with-sloppy&quot;&gt;Don’t Confuse Simple with Sloppy&lt;&#x2F;a&gt;&lt;&#x2F;h3&gt;
&lt;p&gt;Crucially, writing simple software does not mean implementing “good-enough-for-now” software.
That approach surely will lead to technical debt and maintenance nightmares further down the line as workarounds get stacked on top of each other.
No, simple software can still be well-designed software, but it keeps the current requirements in mind.
For example, &lt;a href=&quot;&#x2F;blog&#x2F;compile-time-invariants&#x2F;&quot;&gt;compile-time invariants&lt;&#x2F;a&gt; and &lt;a href=&quot;&#x2F;blog&#x2F;illegal-state&#x2F;&quot;&gt;making illegal states unrepresentable&lt;&#x2F;a&gt; are techniques that add real safety without adding accidental complexity. The type system does the work so your code doesn’t have to.
The goal is not to take shortcuts. Quite the contrary: the goal is to avoid unnecessary complexity, which often is the root cause for having
to take shortcuts later on when bad systems design prevents a cleaner solution.
In &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;endler.dev&#x2F;2025&#x2F;how-to-review-code&#x2F;&quot;&gt;code reviews&lt;&#x2F;a&gt;, I pay extra attention to ensuring we don’t cut corners to avoid doing the necessary design work.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;how-to-recognize-the-right-level-of-abstraction&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#how-to-recognize-the-right-level-of-abstraction&quot; aria-label=&quot;Anchor link for: how-to-recognize-the-right-level-of-abstraction&quot;&gt;How to Recognize The Right Level of Abstraction&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;p&gt;One litmus test I like to use is “Does it feel good to add new functionality?”&lt;&#x2F;p&gt;
&lt;p&gt;Good abstractions tend to “click” together.
It just feels like there’s no overlap between the abstractions and no grunt work or extra conversions needed.
The next step always feels obvious.
Testing works without much mocking, your documentation for your structs almost writes itself.
There’s no “this struct does X &lt;strong&gt;and&lt;&#x2F;strong&gt; Y” in your documentation.
It’s either X &lt;strong&gt;or&lt;&#x2F;strong&gt; Y.
Explaining the design to a fellow developer is straightforward.
This is when you know you have a winner.&lt;&#x2F;p&gt;
&lt;p&gt;Getting there is not easy.
It can take many iterations.
The result of that process is what you’ll often see in popular libraries.&lt;&#x2F;p&gt;
&lt;p&gt;The right abstractions guide you to do the right thing: to find the obvious place to add new functionality, the right place to look for a bug, the right spot to make that database query.&lt;&#x2F;p&gt;
&lt;p&gt;All of that is easier if the code is simple.
That’s why experienced developers always have simplicity in mind when they build out abstractions.&lt;&#x2F;p&gt;
&lt;p&gt;It’s possible that the original sin of a smart engineer is to optimize a thing that should not exist in the first place.
Cross that bridge when you get there.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;write-code-for-humans&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#write-code-for-humans&quot; aria-label=&quot;Anchor link for: write-code-for-humans&quot;&gt;Write Code for Humans&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;p&gt;Be clear, not clever.
Write code for humans, not computers.&lt;&#x2F;p&gt;
&lt;p&gt;Simplicity is clarity.
Simplicity is to succinctly express the essence of a thing.
Simplicity is about removing the unnecessary, the irrelevant, the noise.
Simple is good.
Be simple.&lt;&#x2F;p&gt;
&lt;section class=&quot;footnotes&quot;&gt;
&lt;ol class=&quot;footnotes-list&quot;&gt;
&lt;li id=&quot;fn-pascal&quot;&gt;
&lt;p&gt;I think there’s a similarity to writing here, where elegance (which is correlated with simplicity, in my opinion) requires an iterative process of constant improvement. The editing process is what makes most writing great. In 1657, Blaise Pascal famously wrote: “I have only made this letter longer because I have not had the time to make it shorter.” I think about that a lot when I write. &lt;a href=&quot;#fr-pascal-1&quot;&gt;↩&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;&#x2F;li&gt;
&lt;li id=&quot;fn-nasa&quot;&gt;
&lt;p&gt;For reference, see &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;web.eecs.umich.edu&#x2F;~imarkov&#x2F;10rules.pdf&quot;&gt;“The Power of 10 Rules”&lt;&#x2F;a&gt; by Gerard J. Holzmann of the NASA&#x2F;JPL Laboratory for Reliable Software. &lt;a href=&quot;#fr-nasa-1&quot;&gt;↩&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;&#x2F;li&gt;
&lt;li id=&quot;fn-future&quot;&gt;
&lt;p&gt;I should know because I passed on a few very risky but lucrative investment opportunities because I lacked the ability to accurately predict the future. &lt;a href=&quot;#fr-future-1&quot;&gt;↩&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;&#x2F;li&gt;
&lt;li id=&quot;fn-optimization&quot;&gt;
&lt;p&gt;Of course, this is not the most efficient implementation of quicksort. It allocates a lot of intermediate vectors and has O(n^2) worst-case performance. There are optimizations for partially sorted data, better pivot selection strategies, and in-place partitioning. But they are just that: optimizations. The core idea remains the same. &lt;a href=&quot;#fr-optimization-1&quot;&gt;↩&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;&#x2F;section&gt;
</description>
      </item>
      <item>
          <title>Season 4 - Finale</title>
          <pubDate>Thu, 24 Jul 2025 00:00:00 +0000</pubDate>
          <author>Matthias Endler</author>
          <link>https://corrode.dev/podcast/s04e08-season-finale/</link>
          <guid>https://corrode.dev/podcast/s04e08-season-finale/</guid>
          <description xml:base="https://corrode.dev/podcast/s04e08-season-finale/">&lt;div&gt;&lt;script id=&quot;letscast-player-77a830f9&quot; src=&quot;https:&#x2F;&#x2F;letscast.fm&#x2F;podcasts&#x2F;rust-in-production-82281512&#x2F;episodes&#x2F;season-4-finale&#x2F;player.js?size=s&quot;&gt;&lt;&#x2F;script&gt;&lt;&#x2F;div&gt;
&lt;p&gt;It’s time for another recap including our highlights of Season 4.&lt;&#x2F;p&gt;
&lt;p&gt;We’ve been at this for a while now (four seasons, and 32 episodes to be exact).
We had guests from a wide range of industries: from Microsoft to Astral, and
from password managers to satellite systems.&lt;&#x2F;p&gt;
&lt;p&gt;This time, it’s all about using Rust for foundational software, which is
software that is critical to a team or even an entire organization. Rust is a
great fit for this type of software!&lt;&#x2F;p&gt;</description>
      </item>
      <item>
          <title>KSAT</title>
          <pubDate>Thu, 10 Jul 2025 00:00:00 +0000</pubDate>
          <author>Matthias Endler</author>
          <link>https://corrode.dev/podcast/s04e07-ksat/</link>
          <guid>https://corrode.dev/podcast/s04e07-ksat/</guid>
          <description xml:base="https://corrode.dev/podcast/s04e07-ksat/">&lt;div&gt;&lt;script id=&quot;letscast-player-204ce5f9&quot; src=&quot;https:&#x2F;&#x2F;letscast.fm&#x2F;podcasts&#x2F;rust-in-production-82281512&#x2F;episodes&#x2F;ksat-with-vegard-sandengen&#x2F;player.js?size=s&quot;&gt;&lt;&#x2F;script&gt;&lt;&#x2F;div&gt;
&lt;p&gt;As a kid, I was always fascinated by space tech.
That fascination has only grown as I’ve learned more about the engineering challenges involved in space exploration.&lt;&#x2F;p&gt;
&lt;p&gt;In this episode, we talk to Vegard Sandengen, a Rust engineer at KSAT, a company that provides ground station services for satellites.
They use Rust to manage the data flow from hundreds of satellites, ensuring that data is received, processed, and stored efficiently.
This data is then made available to customers around the world, enabling them to make informed decisions based on real-time satellite data.&lt;&#x2F;p&gt;
&lt;p&gt;We dive deep into the technical challenges of building reliable, high-performance systems that operate 24&#x2F;7 to capture and process satellite data.
Vegard shares insights into why Rust was chosen for these mission-critical systems, how they handle the massive scale of data processing,
and the unique reliability requirements when dealing with space-based infrastructure.&lt;&#x2F;p&gt;
&lt;p&gt;From ground station automation to data pipeline optimization, this conversation explores how modern systems programming languages
are enabling the next generation of space technology infrastructure.&lt;&#x2F;p&gt;
&lt;div class=&quot;info dashed&quot;&gt;
  &lt;div class=&quot;info-header&quot;&gt;
    &lt;i class=&quot;icon icon-info&quot;&gt;&lt;&#x2F;i&gt;
    &lt;h4&gt;Proudly Supported by CodeCrafters&lt;&#x2F;h4&gt;
  &lt;&#x2F;div&gt;
  &lt;p&gt;
    CodeCrafters helps you become proficient in Rust by building real-world,
    production-grade projects. Learn hands-on by creating your own shell, HTTP
    server, Redis, Kafka, Git, SQLite, or DNS service from scratch.
  &lt;&#x2F;p&gt;
  &lt;p&gt;
    Start for free today and enjoy 40% off any paid plan by using
    &lt;a href=&quot;https:&#x2F;&#x2F;app.codecrafters.io&#x2F;join?via=mre&quot;&gt;this link&lt;&#x2F;a&gt;.
  &lt;&#x2F;p&gt;
&lt;&#x2F;div&gt;
&lt;h2 id=&quot;show-notes&quot;&gt;Show Notes&lt;&#x2F;h2&gt;
&lt;h3 id=&quot;about-ksat&quot;&gt;About KSAT&lt;&#x2F;h3&gt;
&lt;p&gt;KSAT, or Kongsberg Satellite Services, is a global leader in providing ground station services for satellites.
The company slogan is “We Connect Space And Earth,” and their mission-critical services are used by customers around the world to access satellite data
for a wide range of applications, including weather monitoring, environmental research, and disaster response.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;about-vegard-sandengen&quot;&gt;About Vegard Sandengen&lt;&#x2F;h3&gt;
&lt;p&gt;Vegard Sandengen is a Rust engineer at KSAT, where he works on the company’s data management systems.
He has a Master’s degree in computer science and has been working in the space industry for several years.&lt;&#x2F;p&gt;
&lt;p&gt;At KSAT, Vegard focuses on building high-performance data processing pipelines that handle satellite telemetry and payload data
from ground stations around the world. His work involves optimizing real-time data flows and ensuring system reliability
for mission-critical space operations.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;links-from-the-episode&quot;&gt;Links From The Episode&lt;&#x2F;h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.spacex.com&#x2F;&quot;&gt;SpaceX&lt;&#x2F;a&gt; - Private space exploration company revolutionizing satellite launches&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;ccsds.org&#x2F;&quot;&gt;CCSDS&lt;&#x2F;a&gt; - Space data systems standardization body&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Ground_station&quot;&gt;Ground Station&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Polar_orbit&quot;&gt;Polar Orbit&lt;&#x2F;a&gt; - Orbit with usually limited ground station visibility&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Troll_Satellite_Station&quot;&gt;TrollSat&lt;&#x2F;a&gt; - Remote Ground Station in Antarctica&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.openstack.org&#x2F;&quot;&gt;OpenStack&lt;&#x2F;a&gt; - Build-your-own-cloud software stack&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;youtu.be&#x2F;rME_t6Jn_Kw?list=PL2b0df3jKKiTWZeF7cip6ZUsaVXxWioRi&amp;amp;t=736&quot;&gt;RustConf 2024: K2 Space Lightning Talk&lt;&#x2F;a&gt; - K2 Space’s sponsored lightning talk, talking about 100% Rust based satellites&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.k2space.com&#x2F;&quot;&gt;K2 Space&lt;&#x2F;a&gt; - Space company building satellites entirely in Rust&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.blueorigin.com&#x2F;&quot;&gt;Blue Origin&lt;&#x2F;a&gt; - Space exploration company focused on reusable rockets&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.rocketlabusa.com&#x2F;&quot;&gt;Rocket Lab&lt;&#x2F;a&gt; - Small satellite launch provider&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;aws.amazon.com&#x2F;ground-station&#x2F;&quot;&gt;AWS Ground Station&lt;&#x2F;a&gt; - Cloud-based satellite ground station service&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Strangler_fig_pattern&quot;&gt;Strangler Pattern&lt;&#x2F;a&gt; - A software design pattern to replace legacy applications step-by-step&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;doc.rust-lang.org&#x2F;rust-by-example&#x2F;generics&#x2F;new_types.html&quot;&gt;Rust by Example: New Type Idiom&lt;&#x2F;a&gt; - Creating new wrapper types to leverage Rust’s type system guarantees for correct code&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;serde.rs&#x2F;&quot;&gt;serde&lt;&#x2F;a&gt; - Serialization and deserialization framework for Rust&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;juhaku&#x2F;utoipa&quot;&gt;utoipa&lt;&#x2F;a&gt; - OpenAPI specification generation from Rust code&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;serde-rs&#x2F;json&quot;&gt;serde-json&lt;&#x2F;a&gt; - The go-to solution for parsing JSON in Rust&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;tokio-rs&#x2F;axum&quot;&gt;axum&lt;&#x2F;a&gt; - Ergonomic web framework built on tokio and tower&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;launchbadge&#x2F;sqlx&quot;&gt;sqlx&lt;&#x2F;a&gt; - Async SQL toolkit with compile-time checked queries&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;rayon-rs&#x2F;rayon&quot;&gt;rayon&lt;&#x2F;a&gt; - Data parallelism library for Rust&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;tokio.rs&#x2F;&quot;&gt;tokio&lt;&#x2F;a&gt; - Asynchronous runtime for Rust applications&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;tokio-rs&#x2F;console&quot;&gt;tokio-console&lt;&#x2F;a&gt; - Debugger for async Rust applications&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;tracing.rs&#x2F;&quot;&gt;tracing&lt;&#x2F;a&gt; - Application-level tracing framework for async-aware diagnostics&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.w3.org&#x2F;TR&#x2F;trace-context&#x2F;&quot;&gt;W3C Trace Context&lt;&#x2F;a&gt; - Standard for distributed tracing context propagation&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;opentelemetry.io&#x2F;&quot;&gt;OpenTelemetry&lt;&#x2F;a&gt; - Observability framework for distributed systems&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.honeycomb.io&#x2F;&quot;&gt;Honeycomb&lt;&#x2F;a&gt; - Observability platform for complex distributed systems&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;learn.microsoft.com&#x2F;en-us&#x2F;azure&#x2F;azure-monitor&#x2F;app&#x2F;app-insights-overview&quot;&gt;Azure Application Insights&lt;&#x2F;a&gt; - Application performance monitoring service&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h3 id=&quot;official-links&quot;&gt;Official Links&lt;&#x2F;h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.ksat.no&#x2F;&quot;&gt;KSAT&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;veeg&quot;&gt;Vegard on GitHub&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
</description>
      </item>
      <item>
          <title>1Password</title>
          <pubDate>Thu, 26 Jun 2025 00:00:00 +0000</pubDate>
          <author>Matthias Endler</author>
          <link>https://corrode.dev/podcast/s04e06-1password/</link>
          <guid>https://corrode.dev/podcast/s04e06-1password/</guid>
          <description xml:base="https://corrode.dev/podcast/s04e06-1password/">&lt;div&gt;&lt;script id=&quot;letscast-player-0e3cbed3&quot; src=&quot;https:&#x2F;&#x2F;letscast.fm&#x2F;podcasts&#x2F;rust-in-production-82281512&#x2F;episodes&#x2F;1password-with-andrew-burkhart&#x2F;player.js?size=s&quot;&gt;&lt;&#x2F;script&gt;&lt;&#x2F;div&gt;
&lt;p&gt;Handling secrets is extremely hard.
You have to keep them safe (obviously), while at the same time you need to integrate with a ton of different systems and always provide a great user-experience, because otherwise people will just find a way around your system.
When talking to peers, a lot of people mention 1Password as a company that nailed this balance.&lt;&#x2F;p&gt;
&lt;p&gt;In today’s episode, I talk to Andrew about how 1Password uses Rust to build critical systems that must never fail, how Rust helps them handle secrets for millions of users, and the lessons they learned when adopting Rust in their stack.&lt;&#x2F;p&gt;
&lt;div class=&quot;info dashed&quot;&gt;
  &lt;div class=&quot;info-header&quot;&gt;
    &lt;i class=&quot;icon icon-info&quot;&gt;&lt;&#x2F;i&gt;
    &lt;h4&gt;Proudly Supported by CodeCrafters&lt;&#x2F;h4&gt;
  &lt;&#x2F;div&gt;
  &lt;p&gt;
    CodeCrafters helps you become proficient in Rust by building real-world,
    production-grade projects. Learn hands-on by creating your own shell, HTTP
    server, Redis, Kafka, Git, SQLite, or DNS service from scratch.
  &lt;&#x2F;p&gt;
  &lt;p&gt;
    Start for free today and enjoy 40% off any paid plan by using
    &lt;a href=&quot;https:&#x2F;&#x2F;app.codecrafters.io&#x2F;join?via=mre&quot;&gt;this link&lt;&#x2F;a&gt;.
  &lt;&#x2F;p&gt;
&lt;&#x2F;div&gt;
&lt;h2 id=&quot;show-notes&quot;&gt;Show Notes&lt;&#x2F;h2&gt;
&lt;h3 id=&quot;about-1password&quot;&gt;About 1Password&lt;&#x2F;h3&gt;
&lt;p&gt;1Password is a password manager that helps users securely store and manage their passwords, credit card information, and other sensitive data. It provides a user-friendly interface and strong security features to protect users’ secrets across multiple devices.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;about-andrew-burkhart&quot;&gt;About Andrew Burkhart&lt;&#x2F;h3&gt;
&lt;p&gt;Andrew is a Senior Rust Developer at 1Password in the Product Foundations org, on the Frameworks team and specifically on the Core Platform squad handling the asynchronous frameworks other developers use to build features (i.e. requests into the Rust core from the Native clients, data sync, etc.).
He specifically specialized in that synchronization process, getting data federated from cloud to clients to native apps and back.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;links-from-the-episode&quot;&gt;Links From The Episode&lt;&#x2F;h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;samnewman.io&#x2F;patterns&#x2F;architectural&#x2F;bff&#x2F;&quot;&gt;Backend for Frontend Pattern&lt;&#x2F;a&gt; - Architectural pattern for creating dedicated backends for specific frontends&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;1Password&#x2F;typeshare&quot;&gt;typeshare&lt;&#x2F;a&gt; - Generate types for multiple languages from Rust code&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;1Password&#x2F;zeroizing-alloc&quot;&gt;zeroizing-alloc&lt;&#x2F;a&gt; - 1Password’s minimal secure heap zero-on-free implementation for Rust&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;1Password&#x2F;arboard&quot;&gt;arboard&lt;&#x2F;a&gt; - Cross-platform clipboard manager written in Rust&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;1password&#x2F;passkey-rs&quot;&gt;passkey-rs&lt;&#x2F;a&gt; - Pure Rust implementation of the WebAuthn Passkey specification&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;webassembly.org&#x2F;&quot;&gt;WebAssembly (WASM)&lt;&#x2F;a&gt; - Binary instruction format for portable execution across platforms&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;tokio.rs&#x2F;&quot;&gt;tokio&lt;&#x2F;a&gt; - The de facto standard async runtime for Rust&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;rust-lang&#x2F;rust-clippy&quot;&gt;Clippy&lt;&#x2F;a&gt; - A collection of lints to catch common mistakes in Rust&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;EmbarkStudios&#x2F;cargo-deny&quot;&gt;cargo-deny&lt;&#x2F;a&gt; - Cargo plugin for linting dependencies, licenses, and security advisories&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;nixos.org&#x2F;&quot;&gt;Nix&lt;&#x2F;a&gt; - Purely functional package manager for reproducible builds&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;nixos.wiki&#x2F;wiki&#x2F;Flakes&quot;&gt;Nix Flakes&lt;&#x2F;a&gt; - Experimental feature for hermetic, reproducible Nix builds&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;direnv.net&#x2F;&quot;&gt;direnv&lt;&#x2F;a&gt; - Load and unload environment variables based on current directory&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;cacm.acm.org&#x2F;research&#x2F;spotify-guilds&#x2F;&quot;&gt;ACM: Spotify Guilds&lt;&#x2F;a&gt; - A study into Spotify’s Agile Model’s Guilds&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;tokio-rs&#x2F;axum&quot;&gt;axum&lt;&#x2F;a&gt; - Ergonomic and modular web framework built on tokio and tower&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;tower-rs&#x2F;tower&quot;&gt;tower&lt;&#x2F;a&gt; - Library for building robust networking clients and servers&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;tokio-rs&#x2F;tracing&quot;&gt;tracing&lt;&#x2F;a&gt; - Application-level tracing framework for async-aware diagnostics&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;rusqlite&#x2F;rusqlite&quot;&gt;rusqlite&lt;&#x2F;a&gt; - Ergonomic wrapper for SQLite in Rust&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;docs.rs&#x2F;mockall&#x2F;latest&#x2F;mockall&#x2F;&quot;&gt;mockall&lt;&#x2F;a&gt; - Powerful mock object library for Rust&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;docs.rs&#x2F;pretty_assertions&#x2F;latest&#x2F;pretty_assertions&#x2F;&quot;&gt;pretty_assertions&lt;&#x2F;a&gt; - Better assertion macros with colored diff output&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;neon-rs.dev&#x2F;&quot;&gt;neon&lt;&#x2F;a&gt; - Library for writing native Node.js modules in Rust&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;docs.rs&#x2F;nom-supreme&#x2F;latest&#x2F;nom_supreme&#x2F;&quot;&gt;nom-supreme&lt;&#x2F;a&gt; - Parser combinator additions and utilities for nom&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;ipetkov&#x2F;crane&quot;&gt;crane&lt;&#x2F;a&gt; - Nix library for building Cargo projects&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a href=&quot;&#x2F;podcast&#x2F;s03e01-zed&#x2F;&quot;&gt;Rust in Production: Zed&lt;&#x2F;a&gt; - High-performance code editor built in Rust&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;tokio-rs&#x2F;console&quot;&gt;tokio-console&lt;&#x2F;a&gt; - Debugger for async Rust programs using tokio&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;marabos.nl&#x2F;atomics&#x2F;&quot;&gt;Rust Atomics and Locks by Mara Bos&lt;&#x2F;a&gt; - Free online book about low-level concurrency in Rust&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;rust-book.cs.brown.edu&#x2F;&quot;&gt;The Rust Programming Language (Brown University Edition)&lt;&#x2F;a&gt; - Interactive version of the Rust Book with quizzes&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;rust-lang&#x2F;rustlings&quot;&gt;Rustlings&lt;&#x2F;a&gt; - Small exercises to get you used to reading and writing Rust code&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h3 id=&quot;official-links&quot;&gt;Official Links&lt;&#x2F;h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;1password.com&#x2F;&quot;&gt;1Password&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;DrewBurkhart&quot;&gt;Andrew on GitHub&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.linkedin.com&#x2F;in&#x2F;andrewburkhartdev&#x2F;&quot;&gt;Andrew on LinkedIn&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
</description>
      </item>
      <item>
          <title>Tembo</title>
          <pubDate>Thu, 12 Jun 2025 00:00:00 +0000</pubDate>
          <author>Matthias Endler</author>
          <link>https://corrode.dev/podcast/s04e05-tembo/</link>
          <guid>https://corrode.dev/podcast/s04e05-tembo/</guid>
          <description xml:base="https://corrode.dev/podcast/s04e05-tembo/">&lt;div&gt;&lt;script id=&quot;letscast-player-a72393de&quot; src=&quot;https:&#x2F;&#x2F;letscast.fm&#x2F;podcasts&#x2F;rust-in-production-82281512&#x2F;episodes&#x2F;tembo-with-adam-hendel&#x2F;player.js?size=s&quot;&gt;&lt;&#x2F;script&gt;&lt;&#x2F;div&gt;
&lt;p&gt;Recently I was in need of a simple job queue for a Rust project. I already had
Postgres in place and wondered if I could reuse it for this purpose. I found PGMQ by
&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.tembo.io&#x2F;&quot;&gt;Tembo&lt;&#x2F;a&gt;. PGMQ a simple job queue written in Rust that uses
Postgres as a backend. It fit the bill perfectly.&lt;&#x2F;p&gt;
&lt;p&gt;In today’s episode, I talk to &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.linkedin.com&#x2F;in&#x2F;adam-hendel&#x2F;&quot;&gt;Adam
Hendel&lt;&#x2F;a&gt;, the founding engineer of
Tembo, about one of their projects, PGMQ, and how it came to be. We discuss the design
decisions behind job queues, interfacing from Rust to Postgres, and the
engineering decisions that went into building the extension.&lt;&#x2F;p&gt;
&lt;p&gt;It was delightful to hear that you could build all of this yourself, but that
you would probably just waste your time doing so and would come up with the same
design decisions as Adam and the team.&lt;&#x2F;p&gt;
&lt;div class=&quot;info dashed&quot;&gt;
  &lt;div class=&quot;info-header&quot;&gt;
    &lt;i class=&quot;icon icon-info&quot;&gt;&lt;&#x2F;i&gt;
    &lt;h4&gt;Proudly Supported by CodeCrafters&lt;&#x2F;h4&gt;
  &lt;&#x2F;div&gt;
  &lt;p&gt;
    CodeCrafters helps you become proficient in Rust by building real-world,
    production-grade projects. Learn hands-on by creating your own shell, HTTP
    server, Redis, Kafka, Git, SQLite, or DNS service from scratch.
  &lt;&#x2F;p&gt;
  &lt;p&gt;
    Start for free today and enjoy 40% off any paid plan by using
    &lt;a href=&quot;https:&#x2F;&#x2F;app.codecrafters.io&#x2F;join?via=mre&quot;&gt;this link&lt;&#x2F;a&gt;.
  &lt;&#x2F;p&gt;
&lt;&#x2F;div&gt;
&lt;h2 id=&quot;show-notes&quot;&gt;Show Notes&lt;&#x2F;h2&gt;
&lt;h3 id=&quot;about-tembo&quot;&gt;About Tembo&lt;&#x2F;h3&gt;
&lt;p&gt;Tembo builds developer tools that help teams build and ship software faster.
Their first product, &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;pgmq&#x2F;pgmq&#x2F;&quot;&gt;PGMQ&lt;&#x2F;a&gt;, was created to solve
the problem of job queues in a simple and efficient way, leveraging the power of
Postgres. They since made a pivot to focus on AI-driven code assistance, but
PGMQ can be used independently and is available as an open-source project.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;about-adam-hendel&quot;&gt;About Adam Hendel&lt;&#x2F;h3&gt;
&lt;p&gt;Adam Hendel is the founding engineer at Tembo, where he has been instrumental in
developing PGMQ and other tools like
&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;ChuckHend&#x2F;pg_vectorize&quot;&gt;pg_vectorize&lt;&#x2F;a&gt;. He has since moved on
to work on his own startup, but remains involved with the PGMQ project.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;links-from-the-episode&quot;&gt;Links From The Episode&lt;&#x2F;h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.postgresql.org&#x2F;about&#x2F;&quot;&gt;PostgreSQL&lt;&#x2F;a&gt; - Super flexible ~40 year old relational database that just works&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.r-project.org&#x2F;&quot;&gt;R&lt;&#x2F;a&gt; - Statistical  Programming Language&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;pgcentralfoundation&#x2F;pgrx&#x2F;&quot;&gt;pgrx&lt;&#x2F;a&gt; - Extend Postgres with Rust&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.postgresql.org&#x2F;docs&#x2F;current&#x2F;plpgsql.html&quot;&gt;Postgres Docs: PL&#x2F;pgSQL&lt;&#x2F;a&gt; - Scripting with Procedural Language in PostgreSQL&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.postgresql.org&#x2F;docs&#x2F;current&#x2F;spi.html&quot;&gt;Postgres Docs: SPI&lt;&#x2F;a&gt; - The Postgres Server Programming Interface&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;pgmq&#x2F;pgmq&quot;&gt;pgmq&lt;&#x2F;a&gt; - A lightweight message queue extension, initially written in Rust&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.tembo.io&#x2F;blog&#x2F;introducing-pgmq&quot;&gt;Tembo Blog: Introducing PGMQ&lt;&#x2F;a&gt; - a blog post about the project&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;launchbadge&#x2F;sqlx&quot;&gt;sqlx&lt;&#x2F;a&gt; - All of the great things of an ORM, without all of the bad things of an ORM&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;tokio.rs&#x2F;&quot;&gt;tokio&lt;&#x2F;a&gt; - The de facto standard async runtime for Rust&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;aws.amazon.com&#x2F;sqs&#x2F;&quot;&gt;AWS SQS&lt;&#x2F;a&gt; - Amazon Web Services Simple Queue Service&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.postgresql.org&#x2F;docs&#x2F;current&#x2F;sql-listen.html&quot;&gt;Postgres Docs: LISTEN&lt;&#x2F;a&gt; - The native Postgres &lt;code&gt;sub&lt;&#x2F;code&gt; part of of pubsub&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.postgresql.org&#x2F;docs&#x2F;current&#x2F;sql-notify.html&quot;&gt;Postgres Docs: NOTIFY&lt;&#x2F;a&gt; - The native Postgres &lt;code&gt;pub&lt;&#x2F;code&gt; part of of pubsub&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;docs.rs&#x2F;tokio-stream&#x2F;latest&#x2F;tokio_stream&#x2F;&quot;&gt;tokio-stream&lt;&#x2F;a&gt; - Tokio utility for asynchronous series of values&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.postgresql.org&#x2F;docs&#x2F;current&#x2F;textsearch.html&quot;&gt;Postgres Docs: Full Text Search&lt;&#x2F;a&gt; - Postgres included FTS capabilities&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;pgvector&#x2F;pgvector&quot;&gt;pgvector&lt;&#x2F;a&gt; - The standard extension for vector&#x2F;AI workloads in Postgres&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;ChuckHend&#x2F;pg_vectorize&quot;&gt;pg_vectorize&lt;&#x2F;a&gt; - Automatically create embeddings for use with pgvector&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;docs.python.org&#x2F;3&#x2F;library&#x2F;constants.html#None&quot;&gt;Python Standard Library: None&lt;&#x2F;a&gt; - A type, but not an enum&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;corrode.dev&#x2F;podcast&#x2F;s04e03-astral&#x2F;&quot;&gt;Rust in Production: Astral with Charlie Marsh&lt;&#x2F;a&gt; - Massively improving Python day 1 experience&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;huggingface&#x2F;candle&quot;&gt;Hugging Face candle&lt;&#x2F;a&gt; - Use ML models in Rust&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h3 id=&quot;official-links&quot;&gt;Official Links&lt;&#x2F;h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.tembo.io&#x2F;&quot;&gt;Tembo&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.linkedin.com&#x2F;in&#x2F;adam-hendel&#x2F;&quot;&gt;Adam on LinkedIn&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;ChuckHend&quot;&gt;Adam on GitHub&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
</description>
      </item>
      <item>
          <title>Rust For Foundational Software</title>
          <pubDate>Fri, 06 Jun 2025 00:00:00 +0000</pubDate>
          <author>Matthias Endler</author>
          <link>https://corrode.dev/blog/foundational-software/</link>
          <guid>https://corrode.dev/blog/foundational-software/</guid>
          <description xml:base="https://corrode.dev/blog/foundational-software/">&lt;p&gt;Ten years of stable Rust; writing this feels surreal.&lt;&#x2F;p&gt;
&lt;p&gt;It’s only been &lt;em&gt;yesterday&lt;&#x2F;em&gt; that we all celebrated the 1.0 release of this incredible language.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;users.rust-lang.org&#x2F;t&#x2F;happy-birthday-rust-from-cologne-germany&#x2F;5824&quot;&gt;&lt;img src=&quot;https:&#x2F;&#x2F;corrode.dev&#x2F;blog&#x2F;foundational-software&#x2F;rust-10.png&quot; alt=&quot;The Rust Cologne&#x2F;Bonn User Group wishes Rust 1.0 a Happy Birthday!&quot; &#x2F;&gt;&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;p&gt;I was at Rust Week where Niko Matsakis gave his talk “Our Vision for Rust” in which he made a profound and insightful statement:&lt;&#x2F;p&gt;
&lt;blockquote&gt;
&lt;p&gt;Rust is a language for building &lt;strong&gt;foundational software&lt;&#x2F;strong&gt;.&lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
&lt;p&gt;That deeply struck me.&lt;&#x2F;p&gt;
&lt;p&gt;I highly recommend you read his blog post titled &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;smallcultfollowing.com&#x2F;babysteps&#x2F;blog&#x2F;2025&#x2F;03&#x2F;10&#x2F;rust-2025-intro&#x2F;&quot;&gt;“Rust in 2025: Targeting foundational software”&lt;&#x2F;a&gt;, which is a great summary on the topic.
I wanted to expand on the idea and share what this means to corrode (and perhaps to a wider extent to Rust in the industry).&lt;&#x2F;p&gt;
&lt;h2 id=&quot;the-issue-with-systems-programming&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#the-issue-with-systems-programming&quot; aria-label=&quot;Anchor link for: the-issue-with-systems-programming&quot;&gt;The Issue With “Systems Programming”&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;p&gt;First off, do we really need another term?
After all, many people still think of Rust as a systems programming language first and foremost, so why can’t we just stick to “systems programming”?&lt;&#x2F;p&gt;
&lt;p&gt;I believe the framing is all wrong.
From the outside, “systems programming” might establish that it is about “building systems,” but the term is loaded with historical baggage that feels limiting and prohibitive.
It creates an artificial distinction between systems programming and “other types of programming.”&lt;&#x2F;p&gt;
&lt;p&gt;The mindset “We are not a systems programming company so we don’t need Rust” is common, but limiting.&lt;&#x2F;p&gt;
&lt;p&gt;If I may be candid for a moment, I believe well-known systems-programming domains have a tendency to be toxic.
Even the best developers in the world have had that experience.&lt;&#x2F;p&gt;
&lt;blockquote&gt;
&lt;p&gt;The first contribution that I had to the Linux kernel was some fix for the ext3 file system. It was a very emotional moment for me. I sent a patch to the Linux Kernel and then I saw an email response from Al Viro - one of those developers I’d only heard about and dreamed of meeting someday.
He responded, &lt;strong&gt;‘I’ve never seen code this bad in my life. You managed to introduce three new bugs in two new lines of code. People like you should never be allowed to get close to a keyboard again.’&lt;&#x2F;strong&gt;
That was my introduction to Linux.&lt;&#x2F;p&gt;
&lt;p&gt;– Glauber Costa, co-founder of Turso, on the &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.youtube.com&#x2F;watch?v=biBLEKm2dtY&amp;amp;t=307s&quot;&gt;Top Shelf Podcast&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
&lt;p&gt;Glauber went on to work at Red Hat, Parallels, ScyllaDB, and Datadog on schedulers, databases, and performance optimizations, but just imagine how many capable developers got discouraged by similar early feedback or never even tried to contribute to the Linux kernel in the first place.&lt;&#x2F;p&gt;
&lt;p&gt;I find that ironic because &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Tanenbaum%E2%80%93Torvalds_debate&quot;&gt;people once dismissed Linux itself as just a toy project&lt;&#x2F;a&gt;.
The Linux kernel wasn’t built in a day.
&lt;strong&gt;People need time to learn.&lt;&#x2F;strong&gt;&lt;&#x2F;p&gt;
&lt;p&gt;The whole idea of Rust is to enable &lt;strong&gt;everyone&lt;&#x2F;strong&gt; to build reliable and efficient software.
To me, it’s about breaking down the barriers to entry and making larger parts of the software stack accessible to more people.
You can sit with us.&lt;&#x2F;p&gt;
&lt;blockquote&gt;
&lt;p&gt;We are committed to providing a friendly, safe and welcoming environment for all&lt;&#x2F;p&gt;
&lt;p&gt;– &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.rust-lang.org&#x2F;policies&#x2F;code-of-conduct&quot;&gt;The Rust Code of Conduct&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
&lt;p&gt;That is also where the idea for corrode comes from:
To cut through red tape in the industry.
The goal is to gradually chip away at the crust of our legacy software with all its flaws and limitations and establish a better foundation for the future of infrastructure.
To &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;smallcultfollowing.com&#x2F;babysteps&#x2F;blog&#x2F;2025&#x2F;05&#x2F;15&#x2F;10-years-of-rust&#x2F;&quot;&gt;try and defy the ‘common wisdom’ about what the tradeoffs have to be&lt;&#x2F;a&gt;.
The term corrode is Latin for &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.etymonline.com&#x2F;search?q=corrode&quot;&gt;“to gnaw to bits, wear away.”&lt;&#x2F;a&gt; &lt;sup class=&quot;footnote-reference&quot; id=&quot;fr-corrode-1&quot;&gt;&lt;a href=&quot;#fn-corrode&quot;&gt;1&lt;&#x2F;a&gt;&lt;&#x2F;sup&gt;&lt;&#x2F;p&gt;
&lt;h2 id=&quot;where-rust-shines&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#where-rust-shines&quot; aria-label=&quot;Anchor link for: where-rust-shines&quot;&gt;Where Rust Shines&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;blockquote&gt;
&lt;p&gt;“I think ‘infrastructure’ is a more useful way of thinking about Rust’s niche than arguing over the exact boundary that defines ‘systems programming’.”&lt;&#x2F;p&gt;
&lt;p&gt;“This is the essence of the systems Rust is best for writing: not flashy, not attention-grabbing, often entirely unnoticed. Just the robust and reliable necessities that enable us to get our work done, to attend to other things, confident that the system will keep humming along unattended.”&lt;&#x2F;p&gt;
&lt;p&gt;– Graydon Hoare, &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;rustfoundation.org&#x2F;media&#x2F;10-years-of-stable-rust-an-infrastructure-story&#x2F;&quot;&gt;10 Years of Stable Rust: An Infrastructure Story&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
&lt;p&gt;In conversations with potential customers, one key aspect that comes up with Rust a lot is this perception that Rust is merely a systems programming language.
They see the benefit of reliable software, but they don’t see how Rust could help them.&lt;&#x2F;p&gt;
&lt;p&gt;I used to reply along the lines of Rust’s mantra: “empowering everyone to build reliable and efficient software” – and while I love this mission, it didn’t always “click” with people.&lt;&#x2F;p&gt;
&lt;p&gt;In practice, my clients use Rust for a &lt;strong&gt;much broader range of software&lt;&#x2F;strong&gt;, not just kernel drivers and embedded code!
They use Rust for writing software that &lt;strong&gt;underpins other software&lt;&#x2F;strong&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;Then I used to tell my own story:
I did some C++ in the past, but I wouldn’t call myself a hardcore systems person.
And yet, I help a lot of clients with really interesting and complex pieces of software.
I ship code that is used by many people and companies like Google, Microsoft, AWS, and NVIDIA.
Rust is a great enabler, a superpower, a &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;web.archive.org&#x2F;web&#x2F;20230603070738&#x2F;https:&#x2F;&#x2F;thefeedbackloop.xyz&#x2F;safety-is-rusts-fireflower&#x2F;&quot;&gt;fireflower&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;rust-the-great-enabler&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#rust-the-great-enabler&quot; aria-label=&quot;Anchor link for: rust-the-great-enabler&quot;&gt;Rust, The Great Enabler&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;p&gt;I found that my clients often don’t use Rust as a C++ replacement.
Many of them don’t even have any C++ in production to begin with.
They also don’t need to work on the hardware-software interface or spend their time in low-level code.&lt;&#x2F;p&gt;
&lt;p&gt;What all clients have in common, however, is that the services they build with Rust are &lt;strong&gt;foundational to their core business&lt;&#x2F;strong&gt;.
Rust is used for building platforms: systems which enable building other systems on top.&lt;&#x2F;p&gt;
&lt;p&gt;These services need to be robust and reliable and serve as platforms for other code that might or might not be written in Rust.
This is, in my opinion, the core value proposition of Rust: to build things that form the bedrock of critical infrastructure and must operate reliably for years.&lt;&#x2F;p&gt;
&lt;p&gt;Rust is a day-2 language, i.e. it only starts to shine after taking a leap of faith and using it for an extensive period of time.
In Rust, all of the problems that you have during the lifecycle of your application surface early in development.
Once a service hits production, maintaining it is a breeze.
There is very little on-call work.&lt;&#x2F;p&gt;
&lt;p&gt;The focus should be on what Rust enables: a way to express very complicated ideas on a type-system level, which will help build complex abstractions through simple core mechanics: ownership, borrowing, lifetimes, and its trait system.&lt;&#x2F;p&gt;
&lt;p&gt;This mindset takes away the focus from Rust as a C++ replacement and also explains why so many teams which use languages like Python, TypeScript, and Kotlin are attracted to Rust.&lt;&#x2F;p&gt;
&lt;p&gt;What is less often talked about is that Rust is a language that enables people to move across domain boundaries: from embedded to cloud, from data science to developer tooling.
Few other languages are so versatile and none offer the same level of correctness guarantees.&lt;&#x2F;p&gt;
&lt;p&gt;If you know Rust, you can program simple things in all of these domains.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;why-focus-on-foundational-software&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#why-focus-on-foundational-software&quot; aria-label=&quot;Anchor link for: why-focus-on-foundational-software&quot;&gt;Why Focus On Foundational Software?&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;p&gt;But don’t we just replace “Systems Programming” with “Foundational Software”?
Does using the term “Foundational Software” simply create a new limiting category?&lt;&#x2F;p&gt;
&lt;p&gt;Crucially, foundational software is different from low-level software and systems software.
For my clients, it’s all foundational.
For example, building a data plane is foundational.
Writing a media-processing pipeline is foundational.&lt;&#x2F;p&gt;
&lt;p&gt;Rust serves as a catalyst: companies start using it for critical software but then, as they get more comfortable with the language, expand into using it in other areas of their business:&lt;&#x2F;p&gt;
&lt;blockquote&gt;
&lt;p&gt;I’ve seen it play out as we built Aurora DSQL - we chose Rust for the new dataplane components, and started off developing other components with other tools. The control plane in Kotlin, operations tools in TypeScript, etc. Standard “right tool for the job” stuff. But, as the team has become more and more familiar and comfortable with Rust, it’s become the way everything is built. A lot of this is because we’ve seen the benefits of Rust, but at least some is because the team just enjoys writing Rust.&lt;&#x2F;p&gt;
&lt;p&gt;– &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;smallcultfollowing.com&#x2F;babysteps&#x2F;blog&#x2F;2025&#x2F;05&#x2F;15&#x2F;10-years-of-rust&#x2F;&quot;&gt;Marc Brooker, engineer at Amazon Web Services in Seattle on lobste.rs&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
&lt;p&gt;That fully aligns with my experience: I find that teams become ambitious after a while.
They reach for loftier goals because they &lt;em&gt;can&lt;&#x2F;em&gt;.
The fact they don’t have to deal with security issues anymore enables better affordances.
From my conversations with other Rustaceans, we all made the same observation: suddenly we can build more ambitious projects that we never dared tackle before.&lt;&#x2F;p&gt;
&lt;p&gt;It feels to me as if this direction is more promising: starting with the foundational tech and growing into application-level&#x2F;business-level code if needed&#x2F;helpful.
That’s better than the other way around, which often feels unnecessarily clunky.
Once the foundations are in Rust, other systems can be built on top of it.&lt;&#x2F;p&gt;
&lt;p&gt;Just because we focus on foundational software doesn’t mean we can’t do other things.
But the focus is to make sure that Rust stays true to its roots.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;systems-you-plan-to-maintain-for-years&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#systems-you-plan-to-maintain-for-years&quot; aria-label=&quot;Anchor link for: systems-you-plan-to-maintain-for-years&quot;&gt;Systems You Plan To Maintain For Years&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;p&gt;So, what &lt;em&gt;is&lt;&#x2F;em&gt; foundational software?&lt;&#x2F;p&gt;
&lt;p&gt;It’s software that organizations deem critical for their success.
It might be:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;a robust web backend&lt;&#x2F;li&gt;
&lt;li&gt;a package manager&lt;&#x2F;li&gt;
&lt;li&gt;a platform for robotics&lt;&#x2F;li&gt;
&lt;li&gt;a storage layer&lt;&#x2F;li&gt;
&lt;li&gt;a satellite control system&lt;&#x2F;li&gt;
&lt;li&gt;an SDK for multiple languages&lt;&#x2F;li&gt;
&lt;li&gt;a real-time notification service&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;and many, many more.&lt;&#x2F;p&gt;
&lt;p&gt;All of these things power organizations and &lt;em&gt;must not fail&lt;&#x2F;em&gt; or at least do so &lt;em&gt;gracefully&lt;&#x2F;em&gt;.
My clients and the companies I interviewed on our &lt;a href=&quot;&#x2F;podcast&quot;&gt;podcast&lt;&#x2F;a&gt; all have one thing in common:
They work on Rust projects that are not on the sideline, but front and center, and they shape the future of their infrastructure.
Rust is useful in situations where the &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;dreamsongs.com&#x2F;Files&#x2F;worse-is-worse.pdf&quot;&gt;“worse is better” philosophy falls apart&lt;&#x2F;a&gt;; it’s a language for building the “right thing”:&lt;&#x2F;p&gt;
&lt;blockquote&gt;
&lt;p&gt;With the right thing, designers are equally concerned with simplicity, correctness, consistency, and completeness.&lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
&lt;p&gt;I think many companies will choose Rust to build their future platforms on.
As such, it competes with C++ as much as it does with Kotlin or Python &lt;sup class=&quot;footnote-reference&quot; id=&quot;fr-sustainability-1&quot;&gt;&lt;a href=&quot;#fn-sustainability&quot;&gt;2&lt;&#x2F;a&gt;&lt;&#x2F;sup&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;I believe that we should shift the focus away from memory safety (which many other languages also offer) and instead focus on the explicitness, expressiveness, and ecosystem of Rust that is highly competitive with these languages.
It is a language for teams which want to build things &lt;em&gt;right&lt;&#x2F;em&gt; and are at odds with the “move fast and break things” philosophy of the past.
Rust is future-looking.
Backwards-compatibility is enforced by the compiler and many people work on the robustness aspect of the language.&lt;&#x2F;p&gt;
&lt;p&gt;Dropbox was one of the first production users of Rust.
They built their storage layer on top of it.
At no point did they think about using Rust as a C++ replacement.
Instead, they saw the potential of Rust as a language for building scalable and reliable systems.
Many more companies followed suit:
Amazon, Google, Microsoft, Meta, Discord, Cloudflare, and many more.
These organizations build platforms and Rust, a tool for professional programmers, developed by world experts over more than a decade of hard work, is best equipped to fit the bill.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;rust-is-a-tool-for-professionals&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#rust-is-a-tool-for-professionals&quot; aria-label=&quot;Anchor link for: rust-is-a-tool-for-professionals&quot;&gt;Rust Is A Tool For Professionals&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;p&gt;Is Rust used for real?&lt;&#x2F;p&gt;
&lt;blockquote&gt;
&lt;p&gt;“At this point, we now know the answer: yes, Rust is used a lot. It’s used for real, critical projects to do actual work by some of the largest companies in our industry. We did good.”&lt;&#x2F;p&gt;
&lt;p&gt;“[Rust is] not a great hobby language but it is a fantastic professional language, precisely because of the ease of refactors and speed of development that comes with the type system and borrow checker.”&lt;&#x2F;p&gt;
&lt;p&gt;– Graydon Hoare, &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;rustfoundation.org&#x2F;media&#x2F;10-years-of-stable-rust-an-infrastructure-story&#x2F;&quot;&gt;10 Years of Stable Rust: An Infrastructure Story&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
&lt;p&gt;To build a truly industrial-strength ecosystem, we need to remember the professional software lifecycle, which is often measured in decades.
Stability plays a big role in that.
The fact that Rust has stable editions and a language specification is crucial for industry adoption.&lt;&#x2F;p&gt;
&lt;p&gt;But Rust is more than just a compiler and its standard library: the tooling and wider ecosystem are equally important.
To build foundational software, you need guarantees that vulnerabilities get fixed and that the ecosystem evolves and adapts to the customer’s needs.
The ecosystem is still mostly driven by volunteers who maintain key libraries and tools in their free time.
There is more to be said about supply-chain security and sustainability in a future post.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;rust-is-a-language-for-decades&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#rust-is-a-language-for-decades&quot; aria-label=&quot;Anchor link for: rust-is-a-language-for-decades&quot;&gt;Rust Is A Language For Decades&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;p&gt;Building foundational systems is rooted in the profound belief that the efforts will pay off in the long run because organizations and society will benefit from them for decades.
(&lt;a href=&quot;&#x2F;blog&#x2F;long-term-rust-maintenance&#x2F;&quot;&gt;Long-term Rust Project Maintenance&lt;&#x2F;a&gt; covers the day-to-day work of keeping a Rust codebase healthy over years: dependency management, API design, release automation, and more.)&lt;&#x2F;p&gt;
&lt;p&gt;We are building systems that will be used by people who may not even know they are using them, but who will depend on them every day; that’s critical infrastructure.&lt;&#x2F;p&gt;
&lt;p&gt;And Rust allows us to do so with great ergonomics.
Rust inherited the pragmatism from C++ and the purism from Haskell.&lt;&#x2F;p&gt;
&lt;p&gt;Rust enables us to build sustainable software that stays within its means and is concerned about low resource usage.
Systems where precision and correctness matter.
Solutions that work across language boundaries and up and down the stack.&lt;&#x2F;p&gt;
&lt;p&gt;Rust is a language for decades and my mission is to be a part of this shift.&lt;&#x2F;p&gt;
&lt;p&gt;On to the next 10 years!&lt;&#x2F;p&gt;
&lt;section class=&quot;footnotes&quot;&gt;
&lt;ol class=&quot;footnotes-list&quot;&gt;
&lt;li id=&quot;fn-corrode&quot;&gt;
&lt;p&gt;Conveniently, it also has a ‘C’ and an ‘R’ in the name, which bridges both languages. &lt;a href=&quot;#fr-corrode-1&quot;&gt;↩&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;&#x2F;li&gt;
&lt;li id=&quot;fn-sustainability&quot;&gt;
&lt;p&gt;This also raises the question: &lt;a href=&quot;&#x2F;blog&#x2F;rust-in-ten-years&#x2F;&quot;&gt;“Will Rust be alive in 10 years?”&lt;&#x2F;a&gt; And to me the answer is clear: many large organizations have already bet on it and are building their future on top of it. Rust is here to stay. &lt;a href=&quot;#fr-sustainability-1&quot;&gt;↩&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;&#x2F;section&gt;
</description>
      </item>
      <item>
          <title>Rust</title>
          <pubDate>Thu, 29 May 2025 00:00:00 +0000</pubDate>
          <author>Matthias Endler</author>
          <link>https://corrode.dev/podcast/s04e04-rust/</link>
          <guid>https://corrode.dev/podcast/s04e04-rust/</guid>
          <description xml:base="https://corrode.dev/podcast/s04e04-rust/">&lt;div&gt;&lt;script id=&quot;letscast-player-439d0634&quot; src=&quot;https:&#x2F;&#x2F;letscast.fm&#x2F;podcasts&#x2F;rust-in-production-82281512&#x2F;episodes&#x2F;rust-with-niko-matsakis&#x2F;player.js?size=s&quot;&gt;&lt;&#x2F;script&gt;&lt;&#x2F;div&gt;
&lt;p&gt;Few developers have been as influential to my career as Niko Matsakis.
Of course he is a world-class engineer with a PhD from ETH Zürich, a Rust core maintainer who has been
working on the language for way more than a decade, and a Senior Principal Engineer at AWS.
But more importantly, he is an empathetic human and an exceptional communicator.&lt;&#x2F;p&gt;
&lt;p&gt;I’ve personally been waiting for one year to get him on the show and steal one hour of his
precious time. Now, finally, I got my chance at live recording at Rust Week 2025.
The result is everything I hoped for: a trip down memory lane which takes us back
to the early days of Rust, an honest and personal look at Rust’s strengths and weaknesses, and a glimpse into the future of the language.
All of that packed with insightful anecdotes based on Niko’s decades of experience.
If you like Rust, you will enjoy this episode.&lt;&#x2F;p&gt;
&lt;div class=&quot;info dashed&quot;&gt;
  &lt;div class=&quot;info-header&quot;&gt;
    &lt;i class=&quot;icon icon-info&quot;&gt;&lt;&#x2F;i&gt;
    &lt;h4&gt;Proudly Supported by CodeCrafters&lt;&#x2F;h4&gt;
  &lt;&#x2F;div&gt;
  &lt;p&gt;
    CodeCrafters helps you become proficient in Rust by building real-world,
    production-grade projects. Learn hands-on by creating your own shell, HTTP
    server, Redis, Kafka, Git, SQLite, or DNS service from scratch.
  &lt;&#x2F;p&gt;
  &lt;p&gt;
    Start for free today and enjoy 40% off any paid plan by using
    &lt;a href=&quot;https:&#x2F;&#x2F;app.codecrafters.io&#x2F;join?via=mre&quot;&gt;this link&lt;&#x2F;a&gt;.
  &lt;&#x2F;p&gt;
&lt;&#x2F;div&gt;
&lt;h2 id=&quot;show-notes&quot;&gt;Show Notes&lt;&#x2F;h2&gt;
&lt;h3 id=&quot;about-rust&quot;&gt;About Rust&lt;&#x2F;h3&gt;
&lt;p&gt;Rust is the language which brought us all together.
What started as a side-project of Graydon Hoare, a single developer at Mozilla, has grown into
a worldwide community of hobbyists, professionals, and companies which all share the same goal:
to build better, safer software paired with great ergonomics and performance.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;about-niko-matsakis&quot;&gt;About Niko Matsakis&lt;&#x2F;h3&gt;
&lt;p&gt;Niko is a long-time Rust core team member, having joined the project in 2012.
He was and still is part of the team which designed and implemented Rust’s borrow checker,
which is the language’s most important feature.
He has been a voice of reason and a guiding light for many of us, including myself.
His insightful talks and blog posts have helped countless developers to see the language and its goals in a new light.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;special-thanks&quot;&gt;Special Thanks&lt;&#x2F;h3&gt;
&lt;p&gt;Thanks to &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;rustnl.org&#x2F;&quot;&gt;RustNL&lt;&#x2F;a&gt;, the organizers of Rust Week 2025 for inviting Simon and me
to record this episode live. They did a fantastic job organizing the event,
and it was an honor to be part of it.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;links-from-the-episode&quot;&gt;Links From The Episode&lt;&#x2F;h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;rustweek.org&#x2F;&quot;&gt;RustWeek 2025&lt;&#x2F;a&gt; - Rust conference in Utrecht where we recorded this live episode&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;DataPower&quot;&gt;DataPower&lt;&#x2F;a&gt; - Niko’s employer before working on Rust&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;XSLT&quot;&gt;XSLT&lt;&#x2F;a&gt; - Language to transform arbitrarily shaped XML into different arbitrary shapes&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;ethz.ch&#x2F;&quot;&gt;ETH Zürich&lt;&#x2F;a&gt; - Niko’s Alma Mater&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.mozilla.org&#x2F;en-GB&#x2F;&quot;&gt;Mozilla&lt;&#x2F;a&gt; - Niko’s first employer while working on Rust&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;rust-lang&#x2F;rust&#x2F;tree&#x2F;ef75860a0a72f79f97216f8aaa5b388d98da6480&#x2F;src&#x2F;boot&quot;&gt;rustboot&lt;&#x2F;a&gt; - Rust’s first compiler written in OCaml&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Don_Quixote&quot;&gt;Don Quixote&lt;&#x2F;a&gt; - Personification of impractical idealism, just like Rust was in the beginning&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;archive.fosdem.org&#x2F;2015&#x2F;schedule&#x2F;event&#x2F;the_story_of_rust&#x2F;&quot;&gt;Steve Klabnik’s FOSDEM talk&lt;&#x2F;a&gt; - Coining “The Graydon years”, &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;steveklabnik.github.io&#x2F;history-of-rust&#x2F;&quot;&gt;Slides&lt;&#x2F;a&gt;, &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;youtu.be&#x2F;79PSagCD_AY&quot;&gt;Recording of the same talk for ACM&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;rust-lang&#x2F;rust&#x2F;blob&#x2F;0.2&#x2F;doc&#x2F;rust.md#keywords&quot;&gt;Rust 0.2 Keywords&lt;&#x2F;a&gt; - &lt;code&gt;ret&lt;&#x2F;code&gt; for &lt;code&gt;return&lt;&#x2F;code&gt;, &lt;code&gt;cont&lt;&#x2F;code&gt; for &lt;code&gt;continue&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;rust-lang&#x2F;rust&#x2F;blob&#x2F;0.8&#x2F;doc&#x2F;tutorial.md#boxes&quot;&gt;Boxes in Rust 0.8&lt;&#x2F;a&gt; - &lt;code&gt;~T&lt;&#x2F;code&gt; and &lt;code&gt;@T&lt;&#x2F;code&gt; as syntax features instead of &lt;code&gt;Box&amp;lt;T&amp;gt;&lt;&#x2F;code&gt; and &lt;code&gt;Rc&amp;lt;T&amp;gt;&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Green_thread&quot;&gt;Green Threads&lt;&#x2F;a&gt; - Like OS threads, but greener!&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;doc.rust-lang.org&#x2F;std&#x2F;thread&#x2F;index.html&quot;&gt;&lt;code&gt;std::threads&lt;&#x2F;code&gt;&lt;&#x2F;a&gt; - Not green, just part of the standard library&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;doc.rust-lang.org&#x2F;std&#x2F;rc&#x2F;struct.Rc.html&quot;&gt;&lt;code&gt;std::rc::Rc&lt;&#x2F;code&gt;&lt;&#x2F;a&gt; - The &lt;code&gt;@T&lt;&#x2F;code&gt; of &lt;code&gt;std&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;doc.rust-lang.org&#x2F;std&#x2F;boxed&#x2F;struct.Box.html&quot;&gt;&lt;code&gt;std::boxed::Box&lt;&#x2F;code&gt;&lt;&#x2F;a&gt; - The &lt;code&gt;~T&lt;&#x2F;code&gt; of &lt;code&gt;std&lt;&#x2F;code&gt; with some special compiler sauce&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;doc.rust-lang.org&#x2F;std&#x2F;sync&#x2F;struct.Arc.html&quot;&gt;&lt;code&gt;std::sync::Arc&lt;&#x2F;code&gt;&lt;&#x2F;a&gt; - Thread safe &lt;code&gt;Rc&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;docs.rs&#x2F;pyo3&#x2F;latest&#x2F;pyo3&#x2F;struct.Py.html&quot;&gt;&lt;code&gt;pyo3::Py&lt;&#x2F;code&gt;&lt;&#x2F;a&gt; - A pointer type in a different library!&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;doc.rust-lang.org&#x2F;book&#x2F;ch04-00-understanding-ownership.html&quot;&gt;The Rust Book: Understanding Ownership&lt;&#x2F;a&gt; - Ownership and borrowing are the first third of “the simple core of Rust”&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;doc.rust-lang.org&#x2F;book&#x2F;ch18-02-trait-objects.html&quot;&gt;The Rust Book: Using Trait Objects&lt;&#x2F;a&gt; - Trait-based dispatch being the second part of “the simple core of Rust”&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;doc.rust-lang.org&#x2F;std&#x2F;marker&#x2F;trait.Send.html&quot;&gt;&lt;code&gt;std::marker::Send&lt;&#x2F;code&gt;&lt;&#x2F;a&gt; - A trait without even a method to dispatch, aptly placed in the &lt;code&gt;marker&lt;&#x2F;code&gt; module&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;doc.rust-lang.org&#x2F;std&#x2F;marker&#x2F;trait.Sync.html&quot;&gt;&lt;code&gt;std::marker::Sync&lt;&#x2F;code&gt;&lt;&#x2F;a&gt; - Another example of a marker trait&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Substructural_type_system#Linear_type_systems&quot;&gt;Linear Type Systems&lt;&#x2F;a&gt; - Foundational research topic for borrowing in Rust&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;rust-lang&#x2F;regex&quot;&gt;regex&lt;&#x2F;a&gt; - “Real stuff” built in Rust&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;rayon-rs&#x2F;rayon&quot;&gt;rayon&lt;&#x2F;a&gt; - Turning iterators into parallel processing&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;tokio.rs&#x2F;&quot;&gt;Tokio Async Runtime&lt;&#x2F;a&gt; - An entire async ecosystem as a performant library&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;rust-lang&#x2F;rfcs&#x2F;pull&#x2F;2394#discussion_r179909812&quot;&gt;Comment on RFC 2394&lt;&#x2F;a&gt; - The beginning of the &lt;code&gt;await x&lt;&#x2F;code&gt; &#x2F; &lt;code&gt;x.await&lt;&#x2F;code&gt; discussion?&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;alexcrichton&quot;&gt;Alex Crichton&lt;&#x2F;a&gt; - Rust compiler, wasm, and lang-advisors team member&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;cramertj&quot;&gt;cramertj&lt;&#x2F;a&gt; - Rust lang-advisors and libs-contributors team member&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;without.boats&#x2F;&quot;&gt;withoutboats&lt;&#x2F;a&gt; - Rust team alumni&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;carllerche.com&#x2F;&quot;&gt;Carl Lerche&lt;&#x2F;a&gt; - tokio maintainer&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;aturon.github.io&#x2F;&quot;&gt;aturon&lt;&#x2F;a&gt; - Rust team alumni&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;ALGOL_60#Code_sample_comparisons&quot;&gt;ALGOL 60&lt;&#x2F;a&gt; - Doesn’t look like C&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;doc.rust-lang.org&#x2F;nightly&#x2F;unstable-book&#x2F;language-features&#x2F;try-blocks.html&quot;&gt;try blocks&lt;&#x2F;a&gt; - Do we need a postfix &lt;code&gt;match&lt;&#x2F;code&gt; operator for this?&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;blog.rust-lang.org&#x2F;2018&#x2F;12&#x2F;06&#x2F;Rust-1.31-and-rust-2018&#x2F;&quot;&gt;Rust Blog: Announcing Rust 1.31 and Rust 2018&lt;&#x2F;a&gt; - A watershed moment for Rust&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;blog.rust-lang.org&#x2F;2018&#x2F;12&#x2F;06&#x2F;Rust-1.31-and-rust-2018&#x2F;#non-lexical-lifetimes&quot;&gt;Non-lexical lifetimes&lt;&#x2F;a&gt; - Included in 1.31 and Rust 2018&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;santiagopastorino.com&#x2F;&quot;&gt;Santiago Pastorino&lt;&#x2F;a&gt; - Rust compiler contributor, worked on non-lexical lifetimes&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;git.kernel.org&#x2F;pub&#x2F;scm&#x2F;linux&#x2F;kernel&#x2F;git&#x2F;torvalds&#x2F;linux.git&#x2F;tree&#x2F;Makefile&quot;&gt;Makefile Example&lt;&#x2F;a&gt; - “We don’t need cargo, Make is fine”&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;blog.rust-lang.org&#x2F;2020&#x2F;08&#x2F;18&#x2F;laying-the-foundation-for-rusts-future&#x2F;&quot;&gt;Rust Blog: Laying the foundation for Rust’s future&lt;&#x2F;a&gt; - Mozilla’s parting gift to Rust?&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;tmandry&quot;&gt;Tyler Mandry&lt;&#x2F;a&gt; - Rust lang team co-lead with Niko&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;joshtriplett.org&#x2F;&quot;&gt;Josh Triplett&lt;&#x2F;a&gt; - Rust lang, cargo, and libs team member&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;aws.amazon.com&#x2F;s3&#x2F;storage-classes&#x2F;express-one-zone&#x2F;&quot;&gt;Amazon S3 Express One Zone storage class&lt;&#x2F;a&gt; - Super low latency S3, written in Rust&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;aws.amazon.com&#x2F;rds&#x2F;aurora&#x2F;dsql&#x2F;&quot;&gt;Amazon Aurora DSQL&lt;&#x2F;a&gt; - Serverless SQL, an AWS project that started 100% in JVM and finished 100% Rust&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.allthingsdistributed.com&#x2F;2025&#x2F;05&#x2F;just-make-it-scale-an-aurora-dsql-story.html&quot;&gt;Just make it scale: An Aurora DSQL story&lt;&#x2F;a&gt; - Blog post detailing the Aurora DSQL Rust rewrite&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;smallcultfollowing.com&#x2F;babysteps&#x2F;blog&#x2F;2025&#x2F;03&#x2F;10&#x2F;rust-2025-intro&#x2F;&quot;&gt;Rust in 2025: Targeting foundational software&lt;&#x2F;a&gt; - Niko’s vision for Rust&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;youtu.be&#x2F;rph_1DODXDU&quot;&gt;Be excellent to each other&lt;&#x2F;a&gt; - Party on dudes!&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h3 id=&quot;official-links&quot;&gt;Official Links&lt;&#x2F;h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.rust-lang.org&#x2F;&quot;&gt;Rust Language&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;rustfoundation.org&#x2F;&quot;&gt;Rust Foundation&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;smallcultfollowing.com&#x2F;babysteps&#x2F;&quot;&gt;Niko Matsakis’ Homepage&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;nikomatsakis&quot;&gt;Niko Matsakis on GitHub&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
</description>
      </item>
      <item>
          <title>Sharp Edges In The Rust Standard Library</title>
          <pubDate>Wed, 21 May 2025 00:00:00 +0000</pubDate>
          <author>Matthias Endler</author>
          <link>https://corrode.dev/blog/sharp-edges-in-rust-std/</link>
          <guid>https://corrode.dev/blog/sharp-edges-in-rust-std/</guid>
          <description xml:base="https://corrode.dev/blog/sharp-edges-in-rust-std/">&lt;p&gt;The &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;doc.rust-lang.org&#x2F;std&#x2F;&quot;&gt;Rust standard library&lt;&#x2F;a&gt;, affectionately called &lt;code&gt;std&lt;&#x2F;code&gt;, is exceptionally well-designed, but that doesn’t mean it’s perfect.
More experienced Rust developers tend to navigate around some of its sharper parts.&lt;&#x2F;p&gt;
&lt;p&gt;In this article, I want to highlight the areas in &lt;code&gt;std&lt;&#x2F;code&gt; that I personally avoid.
Keep in mind that this list is subjective, so take it with a grain of salt.
My intention is to point out some pitfalls and suggest alternatives where appropriate.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;threading&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#threading&quot; aria-label=&quot;Anchor link for: threading&quot;&gt;Threading&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;p&gt;Rust’s threading library is quite solid.
That said, managing threads can be a bit of a footgun.
In particular, forgetting to &lt;em&gt;join&lt;&#x2F;em&gt; a thread can have some unexpected side effects.&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;use&lt;&#x2F;span&gt;&lt;span&gt; std&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span&gt;thread;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;use&lt;&#x2F;span&gt;&lt;span&gt; std&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span&gt;time&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;Duration&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;struct&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Resource&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;impl&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Drop&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; for&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Resource&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    fn&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; drop&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;&amp;amp;mut&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;font-style: italic;&quot;&gt; self&lt;&#x2F;span&gt;&lt;span&gt;) {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;        &#x2F;&#x2F; This never gets called&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;        println!&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt;&amp;quot;CRITICAL CLEANUP: Resource dropped&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;fn&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; main&lt;&#x2F;span&gt;&lt;span&gt;() {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    let&lt;&#x2F;span&gt;&lt;span&gt; handle&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; thread&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;spawn&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;||&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;        let&lt;&#x2F;span&gt;&lt;span&gt; resource&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Resource&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;        &#x2F;&#x2F; Do some work... &lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        thread&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;sleep&lt;&#x2F;span&gt;&lt;span&gt;(Duration&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;from_secs&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt;60&lt;&#x2F;span&gt;&lt;span&gt;));&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;        &#x2F;&#x2F; Resource should be dropped here when thread ends&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    });&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;    &#x2F;&#x2F; Main thread exits immediately.&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;    &#x2F;&#x2F; But! We forgot to join the spawned thread!&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;    &#x2F;&#x2F; handle.join().unwrap();&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;In the above scenario, cleanup tasks (such as flushing caches or closing files) might not get executed.
So, even if you do nothing with the handle, it is still a best practice to &lt;code&gt;join()&lt;&#x2F;code&gt; it.
For more details on the topic, check out matklad’s article: &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;matklad.github.io&#x2F;2019&#x2F;08&#x2F;23&#x2F;join-your-threads.html&quot;&gt;“Join Your Threads”&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;In fact, there was a proposal to make &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;doc.rust-lang.org&#x2F;std&#x2F;thread&#x2F;struct.JoinHandle.html&quot;&gt;&lt;code&gt;std::thread::JoinHandle&lt;&#x2F;code&gt;&lt;&#x2F;a&gt; be &lt;code&gt;#[must_use]&lt;&#x2F;code&gt;, but it was ultimately &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;rust-lang&#x2F;rust&#x2F;pull&#x2F;48830&quot;&gt;declined&lt;&#x2F;a&gt; because it would produce too many warnings.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;rust-lang&#x2F;rust&#x2F;pull&#x2F;48830#issuecomment-371649213&quot;&gt;This comment summarized the situation pretty well&lt;&#x2F;a&gt;:&lt;&#x2F;p&gt;
&lt;blockquote&gt;
&lt;p&gt;I’d say the key issue here is that &lt;code&gt;thread::spawn&lt;&#x2F;code&gt; is the easiest way of spawning threads, but not the best one for casual use. Manually calling &lt;code&gt;.join().unwrap()&lt;&#x2F;code&gt; is a chore and easy to forget, which makes &lt;code&gt;thread::spawn&lt;&#x2F;code&gt; a potential footgun.&lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
&lt;p&gt;For new code, &lt;strong&gt;I recommend using &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;doc.rust-lang.org&#x2F;std&#x2F;thread&#x2F;fn.scope.html&quot;&gt;&lt;code&gt;thread::scope&lt;&#x2F;code&gt;&lt;&#x2F;a&gt;&lt;&#x2F;strong&gt; instead, which is a much better API in every conceivable way.
The documentation addresses the above issue directly:&lt;&#x2F;p&gt;
&lt;blockquote&gt;
&lt;p&gt;Unlike non-scoped threads, scoped threads can borrow non-&lt;code&gt;&#x27;static&lt;&#x2F;code&gt; data, as the scope guarantees &lt;strong&gt;all threads will be joined at the end of the scope&lt;&#x2F;strong&gt;.
All threads spawned within the scope that &lt;strong&gt;haven’t been manually joined will be automatically joined&lt;&#x2F;strong&gt; before this function returns.&lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
&lt;p&gt;Alternatively, you could use a thread pool library or &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;rayon-rs&#x2F;rayon&quot;&gt;rayon&lt;&#x2F;a&gt;, in case you have an iterator you want to parallelize without manually managing threads.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;std-collections-linkedlist&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#std-collections-linkedlist&quot; aria-label=&quot;Anchor link for: std-collections-linkedlist&quot;&gt;&lt;code&gt;std::collections::LinkedList&lt;&#x2F;code&gt;&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;p&gt;Implementing a linked list in Rust is &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;rust-unofficial.github.io&#x2F;too-many-lists&#x2F;&quot;&gt;not easy&lt;&#x2F;a&gt;.
That’s because Rust’s ownership model is detrimental to self-referential data structures.&lt;&#x2F;p&gt;
&lt;p&gt;Some people might not know that the standard library ships an implementation of a linked list at &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;doc.rust-lang.org&#x2F;std&#x2F;collections&#x2F;struct.LinkedList.html&quot;&gt;&lt;code&gt;std::collections::LinkedList&lt;&#x2F;code&gt;&lt;&#x2F;a&gt;.
In all those years, I never felt the urge to use it.
It might even be the least-used collection type in the standard library overall.&lt;&#x2F;p&gt;
&lt;p&gt;For all ordinary use cases, a &lt;code&gt;Vec&lt;&#x2F;code&gt; is superior and straightforward to use.
Vectors also have better cache locality and performance characteristics: all items are stored in contiguous memory, which is much better for fast memory access.
On the other side, elements in a linked list can be scattered all over the heap.
If you want to learn more, you can read &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;arxiv.org&#x2F;pdf&#x2F;2306.06942&quot;&gt;this paper&lt;&#x2F;a&gt;, which contains some benchmarks.&lt;&#x2F;p&gt;
&lt;p&gt;You might be wondering why linked lists get used at all.
They have their place as a very specialized data structure that is only really helpful in some resource-constrained or low-level environments like a kernel. The Linux kernel, for example, uses a lot of linked lists.
The reason is that the kernel’s intrusive linked list implementation embeds list nodes directly within data structures which is very memory efficient and allows objects to be in multiple lists simultaneously without additional allocations. &lt;sup class=&quot;footnote-reference&quot; id=&quot;fr-linux-1&quot;&gt;&lt;a href=&quot;#fn-linux&quot;&gt;1&lt;&#x2F;a&gt;&lt;&#x2F;sup&gt;&lt;&#x2F;p&gt;
&lt;p&gt;As for normal, everyday code, just use a &lt;code&gt;Vec&lt;&#x2F;code&gt;.
Even &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;doc.rust-lang.org&#x2F;nightly&#x2F;std&#x2F;collections&#x2F;struct.LinkedList.html&quot;&gt;the documentation of &lt;code&gt;LinkedList&lt;&#x2F;code&gt;&lt;&#x2F;a&gt; itself agrees:&lt;&#x2F;p&gt;
&lt;blockquote&gt;
&lt;p&gt;NOTE: It is almost always better to use &lt;code&gt;Vec&lt;&#x2F;code&gt; or &lt;code&gt;VecDeque&lt;&#x2F;code&gt; because array-based
containers are generally faster, more memory efficient, and make better use of
CPU cache.&lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
&lt;p&gt;I believe the LinkedList should not have been included in the standard library in the first place.
&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;rust-unofficial.github.io&#x2F;too-many-lists&#x2F;sixth.html&quot;&gt;Even its original author agrees&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;There are some surprising gaps in the API; for instance, &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;doc.rust-lang.org&#x2F;std&#x2F;collections&#x2F;struct.LinkedList.html#method.remove&quot;&gt;&lt;code&gt;LinkedList::remove&lt;&#x2F;code&gt;&lt;&#x2F;a&gt; is still a nightly-only feature&lt;sup class=&quot;footnote-reference&quot; id=&quot;fr-ll-remove-1&quot;&gt;&lt;a href=&quot;#fn-ll-remove&quot;&gt;2&lt;&#x2F;a&gt;&lt;&#x2F;sup&gt;:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;use&lt;&#x2F;span&gt;&lt;span&gt; std&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span&gt;collections&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;LinkedList&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;fn&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; main&lt;&#x2F;span&gt;&lt;span&gt;() {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    let mut&lt;&#x2F;span&gt;&lt;span&gt; list&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; LinkedList&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;from&lt;&#x2F;span&gt;&lt;span&gt;([&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt;1&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt;2&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt;3&lt;&#x2F;span&gt;&lt;span&gt;]);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;    dbg!&lt;&#x2F;span&gt;&lt;span&gt;(list);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;    &#x2F;&#x2F; This is still unstable!&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;    &#x2F;&#x2F; https:&#x2F;&#x2F;github.com&#x2F;rust-lang&#x2F;rust&#x2F;issues&#x2F;69210&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;    &#x2F;&#x2F; The operation should compute in O(n) time.&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;    &#x2F;&#x2F; Panics if out of range...&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;    &#x2F;&#x2F; list.remove(0);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Even if you wanted a linked list, it probably would not be &lt;code&gt;std::collections::LinkedList&lt;&#x2F;code&gt;:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;It doesn’t support O(1) splice, O(1) node erasure, or O(1) node insertion - only O(1) operations at the list ends&lt;&#x2F;li&gt;
&lt;li&gt;It has all the disadvantages of a doubly-linked list but none of its advantages&lt;&#x2F;li&gt;
&lt;li&gt;Custom implementations are often needed anyway. For example, many real-world use cases require an &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.data-structures-in-practice.com&#x2F;intrusive-linked-lists&#x2F;&quot;&gt;intrusive linked list&lt;&#x2F;a&gt; implementation, not provided by &lt;code&gt;std&lt;&#x2F;code&gt;.
An intrusive list is what the &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;elixir.bootlin.com&#x2F;linux&#x2F;v6.14.5&#x2F;source&#x2F;include&#x2F;linux&#x2F;list.h&quot;&gt;Linux kernel provides&lt;&#x2F;a&gt;
and even Rust for Linux has &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;rust-for-linux.github.io&#x2F;docs&#x2F;rust&#x2F;src&#x2F;kernel&#x2F;linked_list.rs.html&quot;&gt;its own implementation&lt;&#x2F;a&gt; of an intrusive list.&lt;&#x2F;li&gt;
&lt;li&gt;Arena-based linked lists are often needed for better performance.&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;There is a &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;internals.rust-lang.org&#x2F;t&#x2F;whats-the-status-of-std-linkedlist-maybe-deprecate-in-rust-2018&#x2F;8068&quot;&gt;longer discussion in the Rust forum&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;Better implementations exist that provide more of the missing operations expected from a proper linked list implementation:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;contain-rs&#x2F;linked-list&quot;&gt;contain-rs&#x2F;linked-list&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;Amanieu&#x2F;intrusive-rs&quot;&gt;intrusive-collections&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;There’s a thing to be said about &lt;code&gt;BTreeMap&lt;&#x2F;code&gt; as well, but I leave it at that. &lt;sup class=&quot;footnote-reference&quot; id=&quot;fr-btreemap-1&quot;&gt;&lt;a href=&quot;#fn-btreemap&quot;&gt;3&lt;&#x2F;a&gt;&lt;&#x2F;sup&gt;&lt;&#x2F;p&gt;
&lt;h2 id=&quot;path-handling&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#path-handling&quot; aria-label=&quot;Anchor link for: path-handling&quot;&gt;Path Handling&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;p&gt;&lt;code&gt;Path&lt;&#x2F;code&gt; does a decent job of abstracting away the underlying file system.
One thing I always disliked was that &lt;code&gt;Path::join&lt;&#x2F;code&gt; returns a &lt;code&gt;PathBuf&lt;&#x2F;code&gt; instead of a &lt;code&gt;Result&amp;lt;PathBuf, Error&amp;gt;&lt;&#x2F;code&gt;.
I mentioned in my &lt;a href=&quot;&#x2F;blog&#x2F;pitfalls-of-safe-rust&#x2F;#surprising-behavior-of-path-join-with-absolute-paths&quot;&gt;‘Pitfalls of Safe Rust’&lt;&#x2F;a&gt; article
that &lt;code&gt;Path::join&lt;&#x2F;code&gt; joining a relative path with an absolute path results in the absolute path being returned.&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;use&lt;&#x2F;span&gt;&lt;span&gt; std&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span&gt;path&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;Path&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;fn&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; main&lt;&#x2F;span&gt;&lt;span&gt;() {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    let&lt;&#x2F;span&gt;&lt;span&gt; relative_path&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Path&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;new&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt;&amp;quot;relative&#x2F;path&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    let&lt;&#x2F;span&gt;&lt;span&gt; absolute_path&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Path&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;new&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt;&amp;quot;&#x2F;absolute&#x2F;path&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;    &#x2F;&#x2F; This will return &amp;quot;&#x2F;absolute&#x2F;path&amp;quot;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    let&lt;&#x2F;span&gt;&lt;span&gt; result&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; relative_path&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;join&lt;&#x2F;span&gt;&lt;span&gt;(absolute_path);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;    assert_eq!&lt;&#x2F;span&gt;&lt;span&gt;(result, absolute_path); &lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;I think that’s pretty counterintuitive and a potential source of bugs.
On top of that, many programs assume paths are UTF-8 encoded and frequently convert them to &lt;code&gt;str&lt;&#x2F;code&gt;.
That’s always a fun dance:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;use&lt;&#x2F;span&gt;&lt;span&gt; std&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span&gt;path&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;Path&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;fn&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; main&lt;&#x2F;span&gt;&lt;span&gt;() {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;   let&lt;&#x2F;span&gt;&lt;span&gt; path&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Path&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;new&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt;&amp;quot;&#x2F;path&#x2F;to&#x2F;file.txt&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;   &lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;   &#x2F;&#x2F; The awkward dance with multiple conversions&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;   match&lt;&#x2F;span&gt;&lt;span&gt; path&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;as_os_str&lt;&#x2F;span&gt;&lt;span&gt;()&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;to_str&lt;&#x2F;span&gt;&lt;span&gt;() {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;       Some&lt;&#x2F;span&gt;&lt;span&gt;(s)&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&amp;gt;&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;           &#x2F;&#x2F; Yay! We can use string operations&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;       },&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;       None&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&amp;gt;&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;           &#x2F;&#x2F; Oh well, it&amp;#39;s not UTF-8.&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;           &#x2F;&#x2F; Many developers just use lossy conversion to avoid dealing with this&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;           &#x2F;&#x2F; Which might _silently_ corrupt path data but keeps the code moving...&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;           let&lt;&#x2F;span&gt;&lt;span&gt; lossy&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; path&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;to_string_lossy&lt;&#x2F;span&gt;&lt;span&gt;();&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;           &lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;       }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;   }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;These &lt;code&gt;path.as_os_str().to_str()&lt;&#x2F;code&gt; operations must be repeated everywhere.
It makes path manipulation ever so slightly annoying.&lt;&#x2F;p&gt;
&lt;p&gt;There are a few more issues with paths in Rust:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;Path&lt;&#x2F;code&gt;&#x2F;&lt;code&gt;OsStr&lt;&#x2F;code&gt; lacks common string manipulation methods (like &lt;code&gt;find()&lt;&#x2F;code&gt;, &lt;code&gt;replace()&lt;&#x2F;code&gt;, etc.), which makes many common operations on paths quite tedious&lt;&#x2F;li&gt;
&lt;li&gt;The design creates a poor experience for Windows users, with inefficient &lt;code&gt;Path&lt;&#x2F;code&gt;&#x2F;&lt;code&gt;OsStr&lt;&#x2F;code&gt; handling that doesn’t fit the platform well. It’s a cross-platform compromise, but it creates some real problems.&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;Of course, for everyday use, &lt;code&gt;Path&lt;&#x2F;code&gt; is perfectly okay, but if path handling is a core part of your application, you might want to consider using an external crate instead.
&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;camino-rs&#x2F;camino&quot;&gt;&lt;code&gt;camino&lt;&#x2F;code&gt;&lt;&#x2F;a&gt; is a good alternative crate, which just assumes that paths are UTF-8 (which, in 2025, is a fair assumption).
This way, operations have much better ergonomics.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;platform-specific-date-and-time-handling&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#platform-specific-date-and-time-handling&quot; aria-label=&quot;Anchor link for: platform-specific-date-and-time-handling&quot;&gt;Platform-Specific Date and Time Handling&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;p&gt;In my opinion, it’s actually great to have some basic time functionality right in the standard library.
However, just be aware that &lt;code&gt;std::time::SystemTime&lt;&#x2F;code&gt; is platform dependent, which &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;rust-lang&#x2F;rust&#x2F;issues&#x2F;44394&quot;&gt;causes some headaches&lt;&#x2F;a&gt;.
&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;rust-lang&#x2F;rust&#x2F;issues&#x2F;48980&quot;&gt;Same for &lt;code&gt;Instant&lt;&#x2F;code&gt;&lt;&#x2F;a&gt;, which is a wrapper around the most precise time source on each OS.&lt;&#x2F;p&gt;
&lt;p&gt;Since time is such a thin wrapper around whatever the operating system provides, you can run into some nasty behavior.
For example, &lt;strong&gt;this does not always result in “1 nanosecond” on Windows&lt;&#x2F;strong&gt;:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;use&lt;&#x2F;span&gt;&lt;span&gt; std&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span&gt;time&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span&gt;{&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;Duration&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; SystemTime&lt;&#x2F;span&gt;&lt;span&gt;};&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;fn&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; main&lt;&#x2F;span&gt;&lt;span&gt;() {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;let&lt;&#x2F;span&gt;&lt;span&gt; now&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; SystemTime&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;now&lt;&#x2F;span&gt;&lt;span&gt;();&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;dbg!&lt;&#x2F;span&gt;&lt;span&gt;((now&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; +&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Duration&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;from_nanos&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt;1&lt;&#x2F;span&gt;&lt;span&gt;))&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;duration_since&lt;&#x2F;span&gt;&lt;span&gt;(now));&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;The documentation does not specify the clock’s accuracy or how it handles leap seconds, except to note that &lt;code&gt;SystemTime&lt;&#x2F;code&gt; does not account for them.&lt;&#x2F;p&gt;
&lt;p&gt;If you depend on proper control over time, such as managing leap seconds or cross-platform support, you’re better off using an external crate.
For a great overview, see this survey in the Rust forum, titled: &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;users.rust-lang.org&#x2F;t&#x2F;the-state-of-time-in-rust-leaps-and-bounds&#x2F;107620&quot;&gt;‘The state of time in Rust: leaps and bounds’&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;In general, I believe &lt;code&gt;std::time&lt;&#x2F;code&gt; works well in combination with the rest of the standard library, such as for &lt;code&gt;sleep&lt;&#x2F;code&gt;:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;use&lt;&#x2F;span&gt;&lt;span&gt; std&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span&gt;thread;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;use&lt;&#x2F;span&gt;&lt;span&gt; std&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span&gt;time&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;Duration&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;thread&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;sleep&lt;&#x2F;span&gt;&lt;span&gt;(Duration&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;from_secs&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt;1&lt;&#x2F;span&gt;&lt;span&gt;));&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;…but apart from that, I don’t use it for much else. If I had to touch any sort of date calculations, I would defer to an external crate.&lt;&#x2F;p&gt;
&lt;p&gt;There are a few options:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;docs.rs&#x2F;jiff&#x2F;latest&#x2F;jiff&#x2F;_documentation&#x2F;comparison&#x2F;index.html&quot;&gt;&lt;code&gt;jiff&lt;&#x2F;code&gt;&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;chronotope&#x2F;chrono&quot;&gt;&lt;code&gt;chrono&lt;&#x2F;code&gt;&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;time-rs&#x2F;time&quot;&gt;&lt;code&gt;time&lt;&#x2F;code&gt;&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;&lt;code&gt;jiff&lt;&#x2F;code&gt; is a new library, which aims to improve upon the existing libraries.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;summary&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#summary&quot; aria-label=&quot;Anchor link for: summary&quot;&gt;Summary&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;p&gt;As you can see, my list of warts in the Rust standard library is quite short.
Given that Rust 1.0 was released more than a decade ago, the standard library has held up &lt;em&gt;really&lt;&#x2F;em&gt; well.
That said, I reserve the right to update this article in case I become aware of additional sharp edges in the future.&lt;&#x2F;p&gt;
&lt;p&gt;If you’re looking to go further, &lt;a href=&quot;&#x2F;blog&#x2F;pitfalls-of-safe-rust&#x2F;&quot;&gt;Pitfalls of Safe Rust&lt;&#x2F;a&gt; covers a broader set of bugs that the compiler won’t catch: integer overflows, unsafe type casts, TOCTOU races, and more.&lt;&#x2F;p&gt;
&lt;p&gt;In general, I like that Rust has a relatively small standard library because once a feature is in there it stays there forever. &lt;sup class=&quot;footnote-reference&quot; id=&quot;fr-forever-1&quot;&gt;&lt;a href=&quot;#fn-forever&quot;&gt;4&lt;&#x2F;a&gt;&lt;&#x2F;sup&gt;&lt;&#x2F;p&gt;
&lt;section class=&quot;footnotes&quot;&gt;
&lt;ol class=&quot;footnotes-list&quot;&gt;
&lt;li id=&quot;fn-linux&quot;&gt;
&lt;p&gt;For a more in-depth discussion on why the Linux kernel uses linked lists, see &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.data-structures-in-practice.com&#x2F;intrusive-linked-lists&#x2F;&quot;&gt;this article&lt;&#x2F;a&gt;. &lt;a href=&quot;#fr-linux-1&quot;&gt;↩&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;&#x2F;li&gt;
&lt;li id=&quot;fn-ll-remove&quot;&gt;
&lt;p&gt;Perhaps this is a little surprising if you mostly use vectors, but removing an element from a list is an &lt;code&gt;O(n)&lt;&#x2F;code&gt; operation. &lt;a href=&quot;#fr-ll-remove-1&quot;&gt;↩&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;&#x2F;li&gt;
&lt;li id=&quot;fn-btreemap&quot;&gt;
&lt;p&gt;“Hold on, what’s wrong with BTreeMap?” you might ask.&lt;&#x2F;p&gt;
&lt;details&gt;&lt;summary&gt;
This is just a mild observation rather than a strong criticism.
If you&#x27;re truly interested, expand the details by clicking here.&lt;&#x2F;summary&gt;
&lt;p&gt;Okay, as you know, Rust has two map implementations in the standard library:
&lt;code&gt;BTreeMap&lt;&#x2F;code&gt;, which guarantees insertion ordering, while &lt;code&gt;HashMap&lt;&#x2F;code&gt; is unordered, but more commonly used.
For a long time, a &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;users.rust-lang.org&#x2F;t&#x2F;hashmap-vs-btreemap&#x2F;13804&#x2F;2&quot;&gt;“performance trick”&lt;&#x2F;a&gt; was to use &lt;code&gt;BTreeMap&lt;&#x2F;code&gt; if you needed a faster hash map implementation.&lt;&#x2F;p&gt;
&lt;p&gt;Since then, the performance of &lt;code&gt;HashMap&lt;&#x2F;code&gt; has improved significantly.
One reason is that the implementation of &lt;code&gt;HashMap&lt;&#x2F;code&gt; has &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;doc.rust-lang.org&#x2F;book&#x2F;ch08-03-hash-maps.html#hashing-functions&quot;&gt;changed to use a “siphash” algorithm&lt;&#x2F;a&gt; and is now &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;doc.rust-lang.org&#x2F;std&#x2F;collections&#x2F;struct.HashMap.html&quot;&gt;based on Google’s SwissTable&lt;&#x2F;a&gt;.
The combination of these changes has made &lt;code&gt;HashMap&lt;&#x2F;code&gt; much more performant than before, so there is no good reason to use &lt;code&gt;BTreeMap&lt;&#x2F;code&gt; anymore, other than the ordering guarantee.&lt;&#x2F;p&gt;
&lt;p&gt;One important distinction to note: iteration order over a &lt;code&gt;HashMap&lt;&#x2F;code&gt; is random, while &lt;code&gt;BTreeMap&lt;&#x2F;code&gt;’s iteration order is always sorted by the key’s &lt;code&gt;Ord&lt;&#x2F;code&gt; implementation (not by insertion order). This makes &lt;code&gt;BTreeMap&lt;&#x2F;code&gt; useful when you need to iterate over keys in a sorted manner. If you’re aggregating data in a &lt;code&gt;HashMap&lt;&#x2F;code&gt; but need a sorted list, you’ll need to collect into a vector and sort it manually. In contrast, &lt;code&gt;BTreeMap&lt;&#x2F;code&gt; gives you sorted iteration for free. So while &lt;code&gt;HashMap&lt;&#x2F;code&gt; is better for random access operations, &lt;code&gt;BTreeMap&lt;&#x2F;code&gt; is still helpful when sorted iteration is required.
I would argue that it’s a bit of a niche use case, however.&lt;&#x2F;p&gt;
&lt;p&gt;In &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.scattered-thoughts.net&#x2F;writing&#x2F;smolderingly-fast-btrees&#x2F;&quot;&gt;“Smolderingly fast b-trees”&lt;&#x2F;a&gt;, Jamie Brandon compares the performance of Rust’s &lt;code&gt;BTreeMap&lt;&#x2F;code&gt; and &lt;code&gt;HashMap&lt;&#x2F;code&gt;. Here are the key takeaways:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;When comparing performance, btrees were found to be significantly slower than hashmaps in most scenarios,
especially for lookups. In the worst case with random-ish strings that share common prefixes, btrees performed dramatically worse.&lt;&#x2F;li&gt;
&lt;li&gt;Hashmaps benefit more from speculative execution between multiple lookups, while btrees don’t.&lt;&#x2F;li&gt;
&lt;li&gt;btrees have performance “cliffs” when comparisons get more expensive and touch more memory&lt;&#x2F;li&gt;
&lt;li&gt;For space usage, the author estimates that btrees would use &amp;gt;60% more memory than hashmaps for random keys.&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;I’d argue that a normal HashMap is almost always the better choice and having two map implementations in the standard library can be confusing.&lt;&#x2F;p&gt;
&lt;p&gt;On top of that, if the hash map is your bottleneck, you’re doing pretty well already.
If you need anything faster, there are plenty of great external crates like &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;indexmap-rs&#x2F;indexmap&quot;&gt;indexmap&lt;&#x2F;a&gt; for insertion-order preservation and &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;xacrimon&#x2F;dashmap&quot;&gt;dashmap&lt;&#x2F;a&gt; for concurrent access.&lt;&#x2F;p&gt;
&lt;p&gt;As I said, nothing earth-shaking, but I think it’s worth mentioning that there are better alternatives to &lt;code&gt;BTreeMap&lt;&#x2F;code&gt;
out there in the ecosystem.&lt;&#x2F;p&gt;
&lt;&#x2F;details&gt;
 &lt;a href=&quot;#fr-btreemap-1&quot;&gt;↩&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li id=&quot;fn-forever&quot;&gt;
&lt;p&gt;Yes, you &lt;em&gt;can&lt;&#x2F;em&gt; deprecate functionality, but this is a very timid and &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;rust-lang.github.io&#x2F;rfcs&#x2F;1270-deprecation.html&quot;&gt;laborious process&lt;&#x2F;a&gt; and that still doesn’t mean functionality gets removed. For example, &lt;code&gt;std::env::home_dir()&lt;&#x2F;code&gt; has been deprecated for years and is now not getting removed, but instead will be &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;releases.rs&#x2F;docs&#x2F;1.85.0&#x2F;#compatibility-notes&quot;&gt;fixed with a bugfix release and un-deprecated&lt;&#x2F;a&gt;. &lt;a href=&quot;#fr-forever-1&quot;&gt;↩&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;&#x2F;section&gt;
</description>
      </item>
      <item>
          <title>C++ to Rust Cheat-Sheet</title>
          <pubDate>Sat, 17 May 2025 00:00:00 +0000</pubDate>
          <author>Matthias Endler</author>
          <link>https://corrode.dev/learn/migration-guides/cpp-to-rust/</link>
          <guid>https://corrode.dev/learn/migration-guides/cpp-to-rust/</guid>
          <description xml:base="https://corrode.dev/learn/migration-guides/cpp-to-rust/">&lt;p&gt;Some people learn new programming languages best by looking at examples for how to do the same thing they know in one language is done in the other.
Below is a syntax comparison table which can serve as a quick reference for common C++ constructs and their equivalents in Rust.
It is not a comprehensive guide, but I hope it helps out a C++ developer looking for a quick reference to Rust syntax.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;comparing-idioms-in-rust-and-c&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#comparing-idioms-in-rust-and-c&quot; aria-label=&quot;Anchor link for: comparing-idioms-in-rust-and-c&quot;&gt;Comparing Idioms in Rust and C++&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Feature&lt;&#x2F;th&gt;
      &lt;th&gt;Rust&lt;&#x2F;th&gt;
      &lt;th&gt;C++&lt;&#x2F;th&gt;
    &lt;&#x2F;tr&gt;
  &lt;&#x2F;thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Immutable Variable Declaration&lt;&#x2F;strong&gt;&lt;&#x2F;td&gt;
      &lt;td&gt;&lt;code&gt;let x: i32 = 5;&lt;&#x2F;code&gt; (immutable by default)&lt;&#x2F;td&gt;
      &lt;td&gt;&lt;code&gt;const int x = 5;&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;
    &lt;&#x2F;tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Mutable Variables&lt;&#x2F;strong&gt;&lt;&#x2F;td&gt;
      &lt;td&gt;&lt;code&gt;let mut x = 5;&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;
      &lt;td&gt;&lt;code&gt;int x = 5;&lt;&#x2F;code&gt; (mutable by default)&lt;&#x2F;td&gt;
    &lt;&#x2F;tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Type Inference&lt;&#x2F;strong&gt;&lt;&#x2F;td&gt;
      &lt;td&gt;&lt;code&gt;let x = 5;&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;
      &lt;td&gt;&lt;code&gt;auto x = 5;&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;
    &lt;&#x2F;tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Constant Declaration&lt;&#x2F;strong&gt;&lt;&#x2F;td&gt;
      &lt;td&gt;&lt;code&gt;const MAX: i32 = 100;&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;
      &lt;td&gt;&lt;code&gt;constexpr int MAX = 100;&lt;&#x2F;code&gt; or&lt;br&gt;&lt;code&gt;consteval int MAX_FN() { return 100; }&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;
    &lt;&#x2F;tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Function Declaration&lt;&#x2F;strong&gt;&lt;&#x2F;td&gt;
      &lt;td&gt;&lt;pre&gt;&lt;code class=&quot;language-rust&quot;&gt;fn add(first: i32, second: i32) -&gt; i32 {
    first + second
}&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;&lt;&#x2F;td&gt;
      &lt;td&gt;&lt;pre&gt;&lt;code class=&quot;language-cpp&quot;&gt;int add(int first, int second) {
    return first + second;
}&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;&lt;&#x2F;td&gt;
    &lt;&#x2F;tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Implicit Return&lt;&#x2F;strong&gt;&lt;&#x2F;td&gt;
      &lt;td&gt;&lt;pre&gt;&lt;code class=&quot;language-rust&quot;&gt;fn add(a: i32, b: i32) -&gt; i32 { a + b }&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;&lt;&#x2F;td&gt;
      &lt;td&gt;&lt;pre&gt;&lt;code class=&quot;language-cpp&quot;&gt;auto add(int a, int b) -&gt; int { return a + b; }&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;&lt;&#x2F;td&gt;
    &lt;&#x2F;tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Immutable Reference&lt;&#x2F;strong&gt;&lt;&#x2F;td&gt;
      &lt;td&gt;&lt;code&gt;&amp;T&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;
      &lt;td&gt;&lt;code&gt;const T&amp;&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;
    &lt;&#x2F;tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Mutable Reference&lt;&#x2F;strong&gt;&lt;&#x2F;td&gt;
      &lt;td&gt;&lt;code&gt;&amp;mut T&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;
      &lt;td&gt;&lt;code&gt;T&amp;&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;
    &lt;&#x2F;tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Raw Pointer&lt;&#x2F;strong&gt;&lt;&#x2F;td&gt;
      &lt;td&gt;&lt;code&gt;*const T&lt;&#x2F;code&gt;&lt;br&gt;&lt;code&gt;*mut T&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;
      &lt;td&gt;&lt;code&gt;const T*&lt;&#x2F;code&gt;&lt;br&gt;&lt;code&gt;T*&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;
    &lt;&#x2F;tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Struct Declaration&lt;&#x2F;strong&gt;&lt;&#x2F;td&gt;
      &lt;td&gt;
        &lt;pre&gt;&lt;code class=&quot;language-rust&quot;&gt;struct Person {
    id: u32,
    health: i32
}&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
      &lt;&#x2F;td&gt;
      &lt;td&gt;
        &lt;pre&gt;&lt;code class=&quot;language-cpp&quot;&gt;struct Person {
    unsigned int id;
    int health;
};&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
      &lt;&#x2F;td&gt;
    &lt;&#x2F;tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Struct Initialization&lt;&#x2F;strong&gt;&lt;&#x2F;td&gt;
      &lt;td&gt;&lt;code&gt;Person { id: uid, health: 100 }&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;
      &lt;td&gt;&lt;code&gt;Person{uid, 100}&lt;&#x2F;code&gt; or &lt;code&gt;Person{.id = uid, .health = 100}&lt;&#x2F;code&gt;&lt;br&gt;
      (multiple initialization styles available in C++)&lt;&#x2F;td&gt;
    &lt;&#x2F;tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Struct Field Access&lt;&#x2F;strong&gt;&lt;&#x2F;td&gt;
      &lt;td&gt;&lt;code&gt;person.id&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;
      &lt;td&gt;&lt;code&gt;person.id&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;
    &lt;&#x2F;tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Class&#x2F;Method Implementation&lt;&#x2F;strong&gt;&lt;&#x2F;td&gt;
      &lt;td&gt;
        &lt;pre&gt;&lt;code class=&quot;language-rust&quot;&gt;impl MyClass {
    fn new(name: &amp;String, data: &amp;Vec&lt;String&gt;) -&gt; Self {
        &#x2F;&#x2F; ...
    }
}&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
      &lt;&#x2F;td&gt;
      &lt;td&gt;
        &lt;pre&gt;&lt;code class=&quot;language-cpp&quot;&gt;&#x2F;&#x2F; Usually split between header (.h) and implementation (.cpp)
&#x2F;&#x2F; Header:
class MyClass {
public:
    MyClass(const string&amp; name, 
            const vector&lt;string&gt;&amp; data);
};
&#x2F;&#x2F; Implementation:
MyClass::MyClass(const string&amp; name, 
                const vector&lt;string&gt;&amp; data) {
    &#x2F;&#x2F; ...
}&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
      &lt;&#x2F;td&gt;
    &lt;&#x2F;tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Method with Self&lt;&#x2F;strong&gt;&lt;&#x2F;td&gt;
      &lt;td&gt;
        &lt;pre&gt;&lt;code class=&quot;language-rust&quot;&gt;fn get_name(&amp;self) -&gt; String {
    self.name.clone()
}&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
      &lt;&#x2F;td&gt;
      &lt;td&gt;
        &lt;pre&gt;&lt;code class=&quot;language-cpp&quot;&gt;string get_name() const {
    return name; &#x2F;&#x2F; &#x27;this&#x27; is implicit in C++
}&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
      &lt;&#x2F;td&gt;
    &lt;&#x2F;tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Static Method&lt;&#x2F;strong&gt;&lt;&#x2F;td&gt;
      &lt;td&gt;&lt;code&gt;fn static_method() { &#x2F;* ... *&#x2F; }&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;
      &lt;td&gt;&lt;code&gt;static void static_method() { &#x2F;* ... *&#x2F; }&lt;&#x2F;code&gt;&lt;br&gt;
      &lt;em&gt;Note: &#x27;static&#x27; in C++ has multiple meanings including file-scope lifetime, class-level function, and non-exported symbols&lt;&#x2F;em&gt;&lt;&#x2F;td&gt;
    &lt;&#x2F;tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Interface&#x2F;Trait&lt;&#x2F;strong&gt;&lt;&#x2F;td&gt;
      &lt;td&gt;
        &lt;pre&gt;&lt;code class=&quot;language-rust&quot;&gt;trait Shape {
    fn get_area(&amp;self) -&gt; f64;
}&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
      &lt;&#x2F;td&gt;
      &lt;td&gt;
        &lt;pre&gt;&lt;code class=&quot;language-cpp&quot;&gt;class Shape {
public:
    virtual double get_area() const = 0;
};&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
      &lt;&#x2F;td&gt;
    &lt;&#x2F;tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Implementing Interface&lt;&#x2F;strong&gt;&lt;&#x2F;td&gt;
      &lt;td&gt;
        &lt;pre&gt;&lt;code class=&quot;language-rust&quot;&gt;impl Shape for Circle {
    fn get_area(&amp;self) -&gt; f64 {
        &#x2F;&#x2F; ...
    }
}&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
      &lt;&#x2F;td&gt;
      &lt;td&gt;
        &lt;pre&gt;&lt;code class=&quot;language-cpp&quot;&gt;class Circle : public Shape {
public:
    double get_area() const override {
        &#x2F;&#x2F; ...
    }
};&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
      &lt;&#x2F;td&gt;
    &lt;&#x2F;tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Generic Function&lt;&#x2F;strong&gt;&lt;&#x2F;td&gt;
      &lt;td&gt;
        &lt;pre&gt;&lt;code class=&quot;language-rust&quot;&gt;fn generic_call&lt;T: Shape&gt;(gen_shape: &amp;T) {
    &#x2F;&#x2F; ...
}&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
      &lt;&#x2F;td&gt;
      &lt;td&gt;
        &lt;pre&gt;&lt;code class=&quot;language-cpp&quot;&gt;template&lt;typename T&gt;
void generic_call(const T&amp; gen_shape) {
    &#x2F;&#x2F; ...
}&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
      &lt;&#x2F;td&gt;
    &lt;&#x2F;tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Associated Types&lt;&#x2F;strong&gt;&lt;&#x2F;td&gt;
      &lt;td&gt;
        &lt;pre&gt;&lt;code class=&quot;language-rust&quot;&gt;trait Shape {
    type InnerType;
    fn make_inner(&amp;self) -&gt; Self::InnerType;
}&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
      &lt;&#x2F;td&gt;
      &lt;td&gt;
        &lt;pre&gt;&lt;code class=&quot;language-cpp&quot;&gt;&#x2F;&#x2F; C++20 concepts approach
template&lt;typename T&gt;
concept Shape = requires(T t) {
    typename T::InnerType;
    { t.make_inner() } -&gt; 
        std::convertible_to&lt;typename T::InnerType&gt;;
};&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
      &lt;&#x2F;td&gt;
    &lt;&#x2F;tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Enums (Tagged Union)&lt;&#x2F;strong&gt;&lt;&#x2F;td&gt;
      &lt;td&gt;
        &lt;pre&gt;&lt;code class=&quot;language-rust&quot;&gt;enum MyShape {
    Circle(f64),
    Rectangle(f64, f64)
}&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
      &lt;&#x2F;td&gt;
      &lt;td&gt;
        &lt;pre&gt;&lt;code class=&quot;language-cpp&quot;&gt;&#x2F;&#x2F; Must specify contained types
std::variant&lt;Circle, Rectangle&gt; my_shape;
&#x2F;&#x2F; Uses integer tags rather than named variants&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
      &lt;&#x2F;td&gt;
    &lt;&#x2F;tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Pattern Matching&lt;&#x2F;strong&gt;&lt;&#x2F;td&gt;
      &lt;td&gt;
        &lt;pre&gt;&lt;code class=&quot;language-rust&quot;&gt;match shape {
    MyShape::Circle(r) =&gt; &#x2F;&#x2F; ...,
    MyShape::Rectangle(w, h) =&gt; &#x2F;&#x2F; ...
}&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
      &lt;&#x2F;td&gt;
      &lt;td&gt;
        &lt;pre&gt;&lt;code class=&quot;language-cpp&quot;&gt;std::visit(overloaded {
    [](const Circle&amp; c) { &#x2F;* ... *&#x2F; },
    [](const Rectangle&amp; r) { &#x2F;* ... *&#x2F; }
}, my_shape);&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
      &lt;&#x2F;td&gt;
    &lt;&#x2F;tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Optional Types&lt;&#x2F;strong&gt;&lt;&#x2F;td&gt;
      &lt;td&gt;&lt;code&gt;Option&amp;lt;T&amp;gt;&lt;&#x2F;code&gt; (Some(T) or None)&lt;&#x2F;td&gt;
      &lt;td&gt;&lt;code&gt;std::optional&amp;lt;T&amp;gt;&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;
    &lt;&#x2F;tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Error Handling&lt;&#x2F;strong&gt;&lt;&#x2F;td&gt;
      &lt;td&gt;&lt;code&gt;Result&amp;lt;T, E&amp;gt;&lt;&#x2F;code&gt; (Ok(T) or Err(E))&lt;&#x2F;td&gt;
      &lt;td&gt;&lt;code&gt;std::expected&amp;lt;T, E&amp;gt;&lt;&#x2F;code&gt; (C++23)&lt;&#x2F;td&gt;
    &lt;&#x2F;tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Error Propagation&lt;&#x2F;strong&gt;&lt;&#x2F;td&gt;
      &lt;td&gt;&lt;code&gt;let file = File::open(&quot;file.txt&quot;)?;&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;
      &lt;td&gt;No direct equivalent; uses exceptions or return codes&lt;&#x2F;td&gt;
    &lt;&#x2F;tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Automatic Trait Implementation&lt;&#x2F;strong&gt;&lt;&#x2F;td&gt;
      &lt;td&gt;&lt;code&gt;#[derive(Debug, Clone, PartialEq)]&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;
      &lt;td&gt;No direct equivalent (may change with C++26 reflection)&lt;&#x2F;td&gt;
    &lt;&#x2F;tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Memory Management&lt;&#x2F;strong&gt;&lt;&#x2F;td&gt;
      &lt;td&gt;
        &lt;pre&gt;&lt;code class=&quot;language-rust&quot;&gt;&#x2F;&#x2F; Manual allocation
let boxed = Box::new(value);
&#x2F;&#x2F; Explicit non-trivial copies
let s = String::from(&quot;text&quot;);
let owned = borrowed.to_owned();
let cloned = original.clone();&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
      &lt;&#x2F;td&gt;
      &lt;td&gt;
        &lt;pre&gt;&lt;code class=&quot;language-cpp&quot;&gt;&#x2F;&#x2F; Manual allocation
auto* ptr = new T();
&#x2F;&#x2F; Smart pointers
auto unique = std::make_unique&lt;T&gt;();
auto shared = std::make_shared&lt;T&gt;();
&#x2F;&#x2F; Implicit non-trivial copies when passing by value
auto copy = original; &#x2F;&#x2F; May implicitly copy&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
      &lt;&#x2F;td&gt;
    &lt;&#x2F;tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Destructors&lt;&#x2F;strong&gt;&lt;&#x2F;td&gt;
      &lt;td&gt;
        &lt;pre&gt;&lt;code class=&quot;language-rust&quot;&gt;impl Drop for MyType {
    fn drop(&amp;mut self) {
        &#x2F;&#x2F; cleanup
    }
}&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
      &lt;&#x2F;td&gt;
      &lt;td&gt;
        &lt;pre&gt;&lt;code class=&quot;language-cpp&quot;&gt;~MyType() {
    &#x2F;&#x2F; cleanup
}&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
      &lt;&#x2F;td&gt;
    &lt;&#x2F;tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Serialization&lt;&#x2F;strong&gt;&lt;&#x2F;td&gt;
      &lt;td&gt;&lt;code&gt;#[derive(Serialize, Deserialize)]&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;
      &lt;td&gt;Requires manual implementation or code generation&lt;br&gt;(may change with C++26 reflection)&lt;&#x2F;td&gt;
    &lt;&#x2F;tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Print to Console&lt;&#x2F;strong&gt;&lt;&#x2F;td&gt;
      &lt;td&gt;&lt;code&gt;println!(&quot;Hello, {name}&quot;);&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;
      &lt;td&gt;&lt;code&gt;std::cout &lt;&lt; &quot;Hello, &quot; &lt;&lt; name &lt;&lt; std::endl;&lt;&#x2F;code&gt;&lt;br&gt;
      &lt;code&gt;std::println(&quot;Hello, {}&quot;, name);&lt;&#x2F;code&gt; (C++23)&lt;&#x2F;td&gt;
    &lt;&#x2F;tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Debug Output&lt;&#x2F;strong&gt;&lt;&#x2F;td&gt;
      &lt;td&gt;&lt;code&gt;println!(&quot;{:?}&quot;, object);&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;
      &lt;td&gt;No direct equivalent; requires custom implementation&lt;&#x2F;td&gt;
    &lt;&#x2F;tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Pretty Debug Output&lt;&#x2F;strong&gt;&lt;&#x2F;td&gt;
      &lt;td&gt;&lt;code&gt;println!(&quot;{:#?}&quot;, object);&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;
      &lt;td&gt;No direct equivalent&lt;&#x2F;td&gt;
    &lt;&#x2F;tr&gt;
  &lt;&#x2F;tbody&gt;
&lt;&#x2F;table&gt;
&lt;h2 id=&quot;rust-vs-c-type-equivalents&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#rust-vs-c-type-equivalents&quot; aria-label=&quot;Anchor link for: rust-vs-c-type-equivalents&quot;&gt;Rust vs C++ Type Equivalents&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;table style=&quot;width:100%&quot;&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Type&lt;&#x2F;th&gt;
      &lt;th&gt;Rust&lt;&#x2F;th&gt;
      &lt;th&gt;C++&lt;&#x2F;th&gt;
    &lt;&#x2F;tr&gt;
  &lt;&#x2F;thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Boolean&lt;&#x2F;strong&gt;&lt;&#x2F;td&gt;
      &lt;td&gt;&lt;code&gt;bool&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;
      &lt;td&gt;&lt;code&gt;bool&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;
    &lt;&#x2F;tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Character&lt;&#x2F;strong&gt;&lt;&#x2F;td&gt;
      &lt;td&gt;&lt;code&gt;char&lt;&#x2F;code&gt; (Unicode scalar value, 4 bytes)&lt;&#x2F;td&gt;
      &lt;td&gt;&lt;code&gt;char32_t&lt;&#x2F;code&gt; (or &lt;code&gt;wchar_t&lt;&#x2F;code&gt; on some platforms)&lt;&#x2F;td&gt;
    &lt;&#x2F;tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Byte (Raw Data)&lt;&#x2F;strong&gt;&lt;&#x2F;td&gt;
      &lt;td&gt;&lt;code&gt;u8&lt;&#x2F;code&gt; (always unsigned)&lt;&#x2F;td&gt;
      &lt;td&gt;&lt;code&gt;uint8_t&lt;&#x2F;code&gt; or &lt;code&gt;unsigned char&lt;&#x2F;code&gt; (for guaranteed unsigned)&lt;&#x2F;td&gt;
    &lt;&#x2F;tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Unsigned Integers&lt;&#x2F;strong&gt;&lt;&#x2F;td&gt;
      &lt;td&gt;
        &lt;pre&gt;&lt;code class=&quot;language-rust&quot;&gt;u8, u16, u32, u64, u128, usize&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
      &lt;&#x2F;td&gt;
      &lt;td&gt;
        &lt;pre&gt;&lt;code class=&quot;language-cpp&quot;&gt;uint8_t, uint16_t, uint32_t, uint64_t, 
__uint128, uintptr_t&#x2F;size_t&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
      &lt;&#x2F;td&gt;
    &lt;&#x2F;tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Signed Integers&lt;&#x2F;strong&gt;&lt;&#x2F;td&gt;
      &lt;td&gt;
        &lt;pre&gt;&lt;code class=&quot;language-rust&quot;&gt;i8, i16, i32, i64, i128, isize&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
      &lt;&#x2F;td&gt;
      &lt;td&gt;
        &lt;pre&gt;&lt;code class=&quot;language-cpp&quot;&gt;int8_t, int16_t, int32_t, int64_t, 
__int128, intptr_t&#x2F;ptrdiff_t&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
      &lt;&#x2F;td&gt;
    &lt;&#x2F;tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Floating Point&lt;&#x2F;strong&gt;&lt;&#x2F;td&gt;
      &lt;td&gt;&lt;code&gt;f32, f64&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;
      &lt;td&gt;&lt;code&gt;float, double&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;
    &lt;&#x2F;tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Unit Type&lt;&#x2F;strong&gt;&lt;&#x2F;td&gt;
      &lt;td&gt;&lt;code&gt;()&lt;&#x2F;code&gt; (unit)&lt;&#x2F;td&gt;
      &lt;td&gt;&lt;code&gt;void&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;
    &lt;&#x2F;tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Never Type&lt;&#x2F;strong&gt;&lt;&#x2F;td&gt;
      &lt;td&gt;&lt;code&gt;!&lt;&#x2F;code&gt; (never)&lt;&#x2F;td&gt;
      &lt;td&gt;&lt;code&gt;[[noreturn]] void&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;
    &lt;&#x2F;tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Immutable Reference&lt;&#x2F;strong&gt;&lt;&#x2F;td&gt;
      &lt;td&gt;&lt;code&gt;&amp;T&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;
      &lt;td&gt;&lt;code&gt;const T&amp;&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;
    &lt;&#x2F;tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Mutable Reference&lt;&#x2F;strong&gt;&lt;&#x2F;td&gt;
      &lt;td&gt;&lt;code&gt;&amp;mut T&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;
      &lt;td&gt;&lt;code&gt;T&amp;&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;
    &lt;&#x2F;tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Raw Pointers&lt;&#x2F;strong&gt;&lt;&#x2F;td&gt;
      &lt;td&gt;&lt;code&gt;*const T&lt;&#x2F;code&gt;, &lt;code&gt;*mut T&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;
      &lt;td&gt;&lt;code&gt;const T*&lt;&#x2F;code&gt;, &lt;code&gt;T*&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;
    &lt;&#x2F;tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Arrays&lt;&#x2F;strong&gt;&lt;&#x2F;td&gt;
      &lt;td&gt;&lt;code&gt;[T; N]&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;
      &lt;td&gt;&lt;code&gt;std::array&amp;lt;T, N&amp;gt;&lt;&#x2F;code&gt; or &lt;code&gt;T[N]&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;
    &lt;&#x2F;tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Slices&lt;&#x2F;strong&gt;&lt;&#x2F;td&gt;
      &lt;td&gt;&lt;code&gt;&amp;[T]&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;
      &lt;td&gt;&lt;code&gt;std::span&amp;lt;T&amp;gt;&lt;&#x2F;code&gt; (C++20)&lt;&#x2F;td&gt;
    &lt;&#x2F;tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Dynamic Array&lt;&#x2F;strong&gt;&lt;&#x2F;td&gt;
      &lt;td&gt;&lt;code&gt;Vec&amp;lt;T&amp;gt;&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;
      &lt;td&gt;&lt;code&gt;std::vector&amp;lt;T&amp;gt;&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;
    &lt;&#x2F;tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;String&lt;&#x2F;strong&gt;&lt;&#x2F;td&gt;
      &lt;td&gt;&lt;code&gt;String&lt;&#x2F;code&gt; (UTF-8 encoded)&lt;&#x2F;td&gt;
      &lt;td&gt;&lt;code&gt;std::string&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;
    &lt;&#x2F;tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;String Slice&lt;&#x2F;strong&gt;&lt;&#x2F;td&gt;
      &lt;td&gt;&lt;code&gt;&amp;str&lt;&#x2F;code&gt; (UTF-8 encoded)&lt;&#x2F;td&gt;
      &lt;td&gt;&lt;code&gt;std::string_view&lt;&#x2F;code&gt; (C++17)&lt;&#x2F;td&gt;
    &lt;&#x2F;tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;C Compatible String&lt;&#x2F;strong&gt;&lt;&#x2F;td&gt;
      &lt;td&gt;&lt;code&gt;CString&lt;&#x2F;code&gt;, &lt;code&gt;&amp;CStr&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;
      &lt;td&gt;&lt;code&gt;std::string&lt;&#x2F;code&gt;, &lt;code&gt;const char*&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;
    &lt;&#x2F;tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Nullable&#x2F;Optional&lt;&#x2F;strong&gt;&lt;&#x2F;td&gt;
      &lt;td&gt;&lt;code&gt;Option&amp;lt;T&amp;gt;&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;
      &lt;td&gt;&lt;code&gt;std::optional&amp;lt;T&amp;gt;&lt;&#x2F;code&gt; (C++17)&lt;&#x2F;td&gt;
    &lt;&#x2F;tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Error Handling&lt;&#x2F;strong&gt;&lt;&#x2F;td&gt;
      &lt;td&gt;&lt;code&gt;Result&amp;lt;T, E&amp;gt;&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;
      &lt;td&gt;&lt;code&gt;std::expected&amp;lt;T, E&amp;gt;&lt;&#x2F;code&gt; (C++23)&lt;&#x2F;td&gt;
    &lt;&#x2F;tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Smart Pointer (Unique)&lt;&#x2F;strong&gt;&lt;&#x2F;td&gt;
      &lt;td&gt;&lt;code&gt;Box&amp;lt;T&amp;gt;&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;
      &lt;td&gt;&lt;code&gt;std::unique_ptr&amp;lt;T&amp;gt;&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;
    &lt;&#x2F;tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Smart Pointer (Shared)&lt;&#x2F;strong&gt;&lt;&#x2F;td&gt;
      &lt;td&gt;&lt;code&gt;Rc&amp;lt;T&amp;gt;&lt;&#x2F;code&gt; (single-threaded)&lt;br&gt;&lt;code&gt;Arc&amp;lt;T&amp;gt;&lt;&#x2F;code&gt; (thread-safe)&lt;&#x2F;td&gt;
      &lt;td&gt;&lt;code&gt;std::shared_ptr&amp;lt;T&amp;gt;&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;
    &lt;&#x2F;tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Weak Pointer&lt;&#x2F;strong&gt;&lt;&#x2F;td&gt;
      &lt;td&gt;&lt;code&gt;Weak&amp;lt;T&amp;gt;&lt;&#x2F;code&gt; (from Rc&#x2F;Arc)&lt;&#x2F;td&gt;
      &lt;td&gt;&lt;code&gt;std::weak_ptr&amp;lt;T&amp;gt;&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;
    &lt;&#x2F;tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Hash Map&lt;&#x2F;strong&gt;&lt;&#x2F;td&gt;
      &lt;td&gt;&lt;code&gt;HashMap&amp;lt;K, V&amp;gt;&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;
      &lt;td&gt;&lt;code&gt;std::unordered_map&amp;lt;K, V&amp;gt;&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;
    &lt;&#x2F;tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Ordered Map&lt;&#x2F;strong&gt;&lt;&#x2F;td&gt;
      &lt;td&gt;&lt;code&gt;BTreeMap&amp;lt;K, V&amp;gt;&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;
      &lt;td&gt;&lt;code&gt;std::map&amp;lt;K, V&amp;gt;&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;
    &lt;&#x2F;tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Hash Set&lt;&#x2F;strong&gt;&lt;&#x2F;td&gt;
      &lt;td&gt;&lt;code&gt;HashSet&amp;lt;T&amp;gt;&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;
      &lt;td&gt;&lt;code&gt;std::unordered_set&amp;lt;T&amp;gt;&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;
    &lt;&#x2F;tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Ordered Set&lt;&#x2F;strong&gt;&lt;&#x2F;td&gt;
      &lt;td&gt;&lt;code&gt;BTreeSet&amp;lt;T&amp;gt;&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;
      &lt;td&gt;&lt;code&gt;std::set&amp;lt;T&amp;gt;&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;
    &lt;&#x2F;tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Double-Ended Queue&lt;&#x2F;strong&gt;&lt;&#x2F;td&gt;
      &lt;td&gt;&lt;code&gt;VecDeque&amp;lt;T&amp;gt;&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;
      &lt;td&gt;&lt;code&gt;std::deque&amp;lt;T&amp;gt;&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;
    &lt;&#x2F;tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Linked List&lt;&#x2F;strong&gt;&lt;&#x2F;td&gt;
      &lt;td&gt;&lt;code&gt;LinkedList&amp;lt;T&amp;gt;&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;
      &lt;td&gt;&lt;code&gt;std::list&amp;lt;T&amp;gt;&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;
    &lt;&#x2F;tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Priority Queue&lt;&#x2F;strong&gt;&lt;&#x2F;td&gt;
      &lt;td&gt;&lt;code&gt;BinaryHeap&amp;lt;T&amp;gt;&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;
      &lt;td&gt;&lt;code&gt;std::priority_queue&amp;lt;T&amp;gt;&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;
    &lt;&#x2F;tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Tuple&lt;&#x2F;strong&gt;&lt;&#x2F;td&gt;
      &lt;td&gt;&lt;code&gt;(T1, T2, ...)&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;
      &lt;td&gt;&lt;code&gt;std::tuple&amp;lt;T1, T2, ...&amp;gt;&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;
    &lt;&#x2F;tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Tagged Union&lt;&#x2F;strong&gt;&lt;&#x2F;td&gt;
      &lt;td&gt;&lt;code&gt;enum Variant { A(T1), B(T2), ... }&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;
      &lt;td&gt;&lt;code&gt;std::variant&amp;lt;T1, T2, ...&amp;gt;&lt;&#x2F;code&gt; (C++17)&lt;&#x2F;td&gt;
    &lt;&#x2F;tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Interior Mutability&lt;&#x2F;strong&gt;&lt;&#x2F;td&gt;
      &lt;td&gt;&lt;code&gt;Cell&amp;lt;T&amp;gt;&lt;&#x2F;code&gt;, &lt;code&gt;RefCell&amp;lt;T&amp;gt;&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;
      &lt;td&gt;&lt;code&gt;mutable&lt;&#x2F;code&gt; keyword&lt;&#x2F;td&gt;
    &lt;&#x2F;tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Thread-Safe Mutability&lt;&#x2F;strong&gt;&lt;&#x2F;td&gt;
      &lt;td&gt;&lt;code&gt;Mutex&amp;lt;T&amp;gt;&lt;&#x2F;code&gt;, &lt;code&gt;RwLock&amp;lt;T&amp;gt;&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;
      &lt;td&gt;&lt;code&gt;std::mutex&lt;&#x2F;code&gt; + &lt;code&gt;T&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;
    &lt;&#x2F;tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Atomic Types&lt;&#x2F;strong&gt;&lt;&#x2F;td&gt;
      &lt;td&gt;&lt;code&gt;AtomicBool&lt;&#x2F;code&gt;, &lt;code&gt;AtomicUsize&lt;&#x2F;code&gt;, etc.&lt;&#x2F;td&gt;
      &lt;td&gt;&lt;code&gt;std::atomic&amp;lt;bool&amp;gt;&lt;&#x2F;code&gt;, &lt;code&gt;std::atomic&amp;lt;size_t&amp;gt;&lt;&#x2F;code&gt;, etc.&lt;&#x2F;td&gt;
    &lt;&#x2F;tr&gt;
  &lt;&#x2F;tbody&gt;
&lt;&#x2F;table&gt;
</description>
      </item>
      <item>
          <title>Astral</title>
          <pubDate>Thu, 15 May 2025 00:00:00 +0000</pubDate>
          <author>Matthias Endler</author>
          <link>https://corrode.dev/podcast/s04e03-astral/</link>
          <guid>https://corrode.dev/podcast/s04e03-astral/</guid>
          <description xml:base="https://corrode.dev/podcast/s04e03-astral/">&lt;div&gt;&lt;script id=&quot;letscast-player-7b80a2f5&quot; src=&quot;https:&#x2F;&#x2F;letscast.fm&#x2F;podcasts&#x2F;rust-in-production-82281512&#x2F;episodes&#x2F;uv-with-charlie-marsh&#x2F;player.js?size=s&quot;&gt;&lt;&#x2F;script&gt;&lt;&#x2F;div&gt;
&lt;p&gt;Up until a few years ago, Python tooling was a nightmare:
basic tasks like installing packages or managing Python versions was a pain.
The tools were brittle and did not work well together,
mired in a swamp of underspecified implementation defined behaviour.&lt;&#x2F;p&gt;
&lt;p&gt;Then, apparently suddenly, but in reality backed by years of ongoing work on formal interoperability specifications,
we saw a renaissance of new ideas in the Python ecosystem.
It started with &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;python-poetry.org&#x2F;&quot;&gt;Poetry&lt;&#x2F;a&gt; and &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;pipx.pypa.io&#x2F;stable&#x2F;&quot;&gt;pipx&lt;&#x2F;a&gt; and
continued with tooling written in Rust like &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;rye.astral.sh&#x2F;&quot;&gt;rye&lt;&#x2F;a&gt;, which later got incorporated into
&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;astral.sh&#x2F;&quot;&gt;Astral&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;Astral in particular contributed a very important piece to the puzzle: &lt;code&gt;uv&lt;&#x2F;code&gt;
– an extremely fast Python package and project manager that supersedes all previous attempts;
For example, it is 10x-100x faster than pip.&lt;&#x2F;p&gt;</description>
      </item>
      <item>
          <title>Flattening Rust&#x27;s Learning Curve</title>
          <pubDate>Mon, 05 May 2025 00:00:00 +0000</pubDate>
          <author>Matthias Endler</author>
          <link>https://corrode.dev/blog/flattening-rusts-learning-curve/</link>
          <guid>https://corrode.dev/blog/flattening-rusts-learning-curve/</guid>
          <description xml:base="https://corrode.dev/blog/flattening-rusts-learning-curve/">&lt;p&gt;I see people make the same mistakes over and over again when learning Rust.
Here are my thoughts (ordered by importance) on how you can ease the learning process.
My goal is to help you save time and frustration.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;let-your-guard-down&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#let-your-guard-down&quot; aria-label=&quot;Anchor link for: let-your-guard-down&quot;&gt;Let Your Guard Down&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;p&gt;Stop resisting. That’s the most important lesson.&lt;&#x2F;p&gt;
&lt;p&gt;Accept that learning Rust requires adopting a completely different mental model than what you’re used to.
There are a ton of new concepts to learn like lifetimes, ownership, and the trait system.
And depending on your background, you’ll need to add generics, pattern matching, or macros to the list.&lt;&#x2F;p&gt;
&lt;p&gt;Your learning pace doesn’t have much to do with whether you’re smart or not or if you have a lot of programming experience.
Instead, what matters more is &lt;strong&gt;your attitude toward the language&lt;&#x2F;strong&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;I have seen junior devs excel at Rust with no prior training and senior engineers struggle for weeks&#x2F;months or even give up entirely. Leave your hubris at home.&lt;&#x2F;p&gt;
&lt;p&gt;Treat the borrow checker as a co-author, not an adversary. This reframes the relationship.
Let the compiler do the teaching: for example, this works great with lifetimes, because the compiler will tell you when a lifetime is ambiguous.
Then just add it but take the time to reason about &lt;em&gt;why&lt;&#x2F;em&gt; the compiler couldn’t figure it out itself.&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;fn&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; longest&lt;&#x2F;span&gt;&lt;span&gt;(x&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;: &amp;amp;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;str&lt;&#x2F;span&gt;&lt;span&gt;, y&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;: &amp;amp;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;str&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; -&amp;gt; &amp;amp;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;str&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    if&lt;&#x2F;span&gt;&lt;span&gt; x&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;len&lt;&#x2F;span&gt;&lt;span&gt;() &amp;gt; y&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;len&lt;&#x2F;span&gt;&lt;span&gt;() {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        x&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    }&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; else&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        y&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;If you try to compile this, the compiler will ask you to add a lifetime parameter.
It provides this helpful suggestion:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt;1&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; | fn&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; longest&lt;&#x2F;span&gt;&lt;span&gt;&amp;lt;&amp;#39;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;a&lt;&#x2F;span&gt;&lt;span&gt;&amp;gt;(x&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;: &amp;amp;&lt;&#x2F;span&gt;&lt;span&gt;&amp;#39;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;a str&lt;&#x2F;span&gt;&lt;span&gt;, y&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;: &amp;amp;&lt;&#x2F;span&gt;&lt;span&gt;&amp;#39;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;a str&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; -&amp;gt; &amp;amp;&lt;&#x2F;span&gt;&lt;span&gt;&amp;#39;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;a str&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;  |           ++++     ++          ++          ++&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;So you don’t have to guess what the compiler wants and can follow its instructions.
But also sit down and wonder &lt;em&gt;why&lt;&#x2F;em&gt; the compiler couldn’t figure it out itself.&lt;&#x2F;p&gt;
&lt;p&gt;Most of the time when fighting the compiler it is actually exposing a design flaw.
Similarly, if your code gets overly verbose or looks ugly, there’s probably a better way.
Declare defeat and learn to do it the Rust way.&lt;&#x2F;p&gt;
&lt;p&gt;If you come from a dynamic language like Python, you’ll find that Rust is more verbose in general.
Most of it just comes from type annotations, though.
Some people might dismiss Rust as being “unelegant” or “ugly”, but the verbosity actually serves a good purpose and is immensely helpful for building large-scale applications:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;First off, you will read the code more often than you write it,
which means type annotations will give you more local context to reason with.&lt;&#x2F;li&gt;
&lt;li&gt;Second, it helps immensely with refactoring because the compiler can check if you broke any code while you move things around.
If your code turns out to look very ugly, take a step back and ask if there’s a simpler solution.
Don’t dismiss the language right away.&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;Turn on all &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;doc.rust-lang.org&#x2F;clippy&#x2F;&quot;&gt;clippy lints&lt;&#x2F;a&gt; on day one – even the pedantic ones.
Run the linter and follow the suggestions religiously.
Don’t skip that step once your program compiles.&lt;&#x2F;p&gt;
&lt;p&gt;Resistance is futile.
The longer you refuse to learn, the longer you will suffer;
but the moment you let your guard down is the moment you’ll start to learn.
Forget what you think you knew about programming and really start to listen to what the compiler, the standard library, and clippy are trying to tell you.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;baby-steps&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#baby-steps&quot; aria-label=&quot;Anchor link for: baby-steps&quot;&gt;Baby Steps&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;p&gt;I certainly tried to run before I could walk.
That alone cost me a lot of precious time.&lt;&#x2F;p&gt;
&lt;p&gt;Don’t make it too hard on yourself in the beginning.
Here are some tips:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;Use &lt;code&gt;String&lt;&#x2F;code&gt; and &lt;code&gt;clone()&lt;&#x2F;code&gt; and &lt;code&gt;unwrap&lt;&#x2F;code&gt; generously; you can always refactor later – and refactoring is the best part about Rust!
I wrote an article on saving yourself time during that phase &lt;a href=&quot;&#x2F;blog&#x2F;prototyping&#x2F;&quot;&gt;here&lt;&#x2F;a&gt;.&lt;&#x2F;li&gt;
&lt;li&gt;Use simple if or match statements before starting to learn some of the more idiomatic &lt;code&gt;.and_then&lt;&#x2F;code&gt; etc. combinators&lt;&#x2F;li&gt;
&lt;li&gt;Avoid async Rust in week 1. The additional rules are a tax on people still learning the core ownership model.&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;Don’t introduce too many new concepts at the same time!
Instead, while you learn about a new concept, have an editor open and write out a few examples.
What helped was to just write some code in the &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;play.rust-lang.org&#x2F;&quot;&gt;Rust playground&lt;&#x2F;a&gt; and try to get it to compile. Write super small snippets (e.g., one &lt;code&gt;main.rs&lt;&#x2F;code&gt; for one concept) instead of using one big “tutorial” repo.
Get into the habit of throwing most of your code away.&lt;&#x2F;p&gt;
&lt;p&gt;I still do that and test out ideas in the playground or when I brainstorm with clients.&lt;&#x2F;p&gt;
&lt;p&gt;For instance, here’s one of my favorite code snippets to explain the concept of ownership:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;fn&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; my_func&lt;&#x2F;span&gt;&lt;span&gt;(v&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; String&lt;&#x2F;span&gt;&lt;span&gt;) {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;    &#x2F;&#x2F; do something with v&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;fn&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; main&lt;&#x2F;span&gt;&lt;span&gt;() {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    let&lt;&#x2F;span&gt;&lt;span&gt; s&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; String&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;from&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt;&amp;quot;hello&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;    my_func&lt;&#x2F;span&gt;&lt;span&gt;(s);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;    my_func&lt;&#x2F;span&gt;&lt;span&gt;(s);&lt;&#x2F;span&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt; &#x2F;&#x2F; error, but why?&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Can you fix it?
Can you explain it?
Ask yourself what would change if &lt;code&gt;v&lt;&#x2F;code&gt; was an &lt;code&gt;i32&lt;&#x2F;code&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;If Rust code looks scary to you, &lt;strong&gt;break it down&lt;&#x2F;strong&gt;.
Write your own, simpler version, then slowly increase the complexity.
Rust is easier to write than to read.
By writing lots of Rust, you will also learn how to read it better as well.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;be-accurate&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#be-accurate&quot; aria-label=&quot;Anchor link for: be-accurate&quot;&gt;Be Accurate&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;blockquote&gt;
&lt;p&gt;How you do anything is how you do everything.
– An ancient Rust proverb&lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
&lt;p&gt;You can be sloppy in other languages, but not in Rust.
That means you have to be accurate while you code or the code just won’t compile.
The expectation is that this approach will save you debugging time in the future.&lt;&#x2F;p&gt;
&lt;p&gt;I found that the people who learn Rust the fastest all have great attention to detail.
If you try to just get things done and move on, you will have a harder time than if you aim to do things right on your first try.
You will have a much better time if you re-read your code to fix stupid typos before pressing “compile.”
Also build a habit of automatically adding &lt;code&gt;&amp;amp;&lt;&#x2F;code&gt; and &lt;code&gt;mut&lt;&#x2F;code&gt; where necessary as you go.&lt;&#x2F;p&gt;
&lt;p&gt;A good example of someone who thinks about these details while coding is
Tsoding. For example, watch &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.youtube.com&#x2F;watch?v=b0KIDIOL_i4&quot;&gt;this stream where he builds a search engine in Rust from scratch&lt;&#x2F;a&gt; to see what I mean.
I think you can learn this skill as long as you’re putting in your best effort and give it some time.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;don-t-cheat&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#don-t-cheat&quot; aria-label=&quot;Anchor link for: don-t-cheat&quot;&gt;Don’t Cheat&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;p&gt;With today’s tooling it is very easy to offload the bulk of the work to the computer.
Initially, it will feel like you’re making quick progress, but in reality, you just strengthen bad habits in your workflow.
If you can’t explain what you wrote to someone else or if you don’t know about the tradeoffs&#x2F;assumptions a part of your code makes,
you took it too far.&lt;&#x2F;p&gt;
&lt;p&gt;Often, this approach stems from a fear that you’re not making progress fast enough.
But you don’t have to prove to someone else that you’re clever enough to pick up Rust very quickly.&lt;&#x2F;p&gt;
&lt;h4 id=&quot;walk-the-walk&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#walk-the-walk&quot; aria-label=&quot;Anchor link for: walk-the-walk&quot;&gt;Walk the Walk&lt;&#x2F;a&gt;&lt;&#x2F;h4&gt;
&lt;p&gt;To properly learn Rust you actually have to write a lot of code by hand.
Don’t be a lurker on Reddit, reading through other people’s success stories.
Have some skin in the game!
Put in the hours because there is no silver bullet.
Once it works, consider open sourcing your code even if you know it’s not perfect.&lt;&#x2F;p&gt;
&lt;h4 id=&quot;don-t-go-on-auto-pilot&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#don-t-go-on-auto-pilot&quot; aria-label=&quot;Anchor link for: don-t-go-on-auto-pilot&quot;&gt;Don’t Go on Auto-Pilot&lt;&#x2F;a&gt;&lt;&#x2F;h4&gt;
&lt;p&gt;LLMs are like driving a car on auto-pilot.
It’s comfortable at first, but you won’t feel in control and slowly, that uneasy feeling will creep in.
Turn off the autopilot while learning.&lt;&#x2F;p&gt;
&lt;p&gt;A quick way to set you up for success is to learn by writing code in the Rust Playground first.
Don’t use LLMs or code completion. Just type it out!
If you can’t, that means you haven’t fully internalized a concept yet.
That’s fine!
Go to the standard library and read the docs.
Take however long it takes and then come back and try again.&lt;&#x2F;p&gt;
&lt;p&gt;Slow is steady and steady is fast.&lt;&#x2F;p&gt;
&lt;h4 id=&quot;build-muscle-memory&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#build-muscle-memory&quot; aria-label=&quot;Anchor link for: build-muscle-memory&quot;&gt;Build Muscle Memory&lt;&#x2F;a&gt;&lt;&#x2F;h4&gt;
&lt;p&gt;Muscle memory in programming is highly underrated.
People will tell you that this is what code completion is for, but I believe it’s a requirement to reach a state of flow:
if you constantly blunder over syntax errors or, worse, just wait for the next auto-completion to make progress,
that is a terrible developer experience.&lt;&#x2F;p&gt;
&lt;p&gt;When writing manually, you will make more mistakes.
Embrace them!
These mistakes will help you learn to understand the compiler output.
You will get a “feeling” for how the output looks in different error scenarios.
Don’t gloss over these errors.
Over time you will develop an intuition about what feels “rustic.”&lt;&#x2F;p&gt;
&lt;h4 id=&quot;predict-the-output&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#predict-the-output&quot; aria-label=&quot;Anchor link for: predict-the-output&quot;&gt;Predict The Output&lt;&#x2F;a&gt;&lt;&#x2F;h4&gt;
&lt;p&gt;Another thing I like to do is to run “prediction exercises” where I guess if code will compile before running it.
This builds intuition.
Try to make every program free of syntax errors before you run it.
Don’t be sloppy.
Of course, you won’t always succeed, but you will get much better at it over time.&lt;&#x2F;p&gt;
&lt;h4 id=&quot;try-to-solve-problems-yourself-only-then-look-up-the-solution&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#try-to-solve-problems-yourself-only-then-look-up-the-solution&quot; aria-label=&quot;Anchor link for: try-to-solve-problems-yourself-only-then-look-up-the-solution&quot;&gt;Try To Solve Problems Yourself, Only &lt;em&gt;Then&lt;&#x2F;em&gt; Look Up The Solution.&lt;&#x2F;a&gt;&lt;&#x2F;h4&gt;
&lt;p&gt;Read lots of other people’s code. I recommend &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;BurntSushi&#x2F;ripgrep&quot;&gt;&lt;code&gt;ripgrep&lt;&#x2F;code&gt;&lt;&#x2F;a&gt;, for example,
which is some of the best Rust code out there.&lt;&#x2F;p&gt;
&lt;h4 id=&quot;develop-a-healthy-share-of-reading-writing-code&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#develop-a-healthy-share-of-reading-writing-code&quot; aria-label=&quot;Anchor link for: develop-a-healthy-share-of-reading-writing-code&quot;&gt;Develop A Healthy Share Of Reading&#x2F;Writing Code.&lt;&#x2F;a&gt;&lt;&#x2F;h4&gt;
&lt;p&gt;Don’t be afraid to get your hands dirty.
Which areas of Rust do you avoid?
What do you run away from?
Focus on that.
Tackle your blind spots.
Track your common “escape hatches” (unsafe, clone, etc.) to identify your current weaknesses.
For example, if you are scared of proc macros, write a bunch of them.&lt;&#x2F;p&gt;
&lt;h4 id=&quot;break-your-code&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#break-your-code&quot; aria-label=&quot;Anchor link for: break-your-code&quot;&gt;Break Your Code&lt;&#x2F;a&gt;&lt;&#x2F;h4&gt;
&lt;p&gt;After you’re done with an exercise, break it! See what the compiler says.
See if you can explain what happens.&lt;&#x2F;p&gt;
&lt;h4 id=&quot;don-t-use-other-people-s-crates-while-learning&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#don-t-use-other-people-s-crates-while-learning&quot; aria-label=&quot;Anchor link for: don-t-use-other-people-s-crates-while-learning&quot;&gt;Don’t Use Other People’s Crates While Learning&lt;&#x2F;a&gt;&lt;&#x2F;h4&gt;
&lt;p&gt;A poor personal version is better than a perfect external crate (at least while learning).
Write some small library code yourself as an exercise.
Notable exceptions are probably &lt;code&gt;serde&lt;&#x2F;code&gt; and &lt;code&gt;anyhow&lt;&#x2F;code&gt;, which can save you time dealing with JSON inputs and setting up error handling that you can spend on other tasks
as long as you know how they work.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;build-good-intuitions&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#build-good-intuitions&quot; aria-label=&quot;Anchor link for: build-good-intuitions&quot;&gt;Build Good Intuitions&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;p&gt;Concepts like lifetimes are hard to grasp.
Sometimes it helps to draw how data moves through your system.
Develop a habit to explain concepts to yourself and others through drawing.
I’m not sure, but I think this works best for “visual”&#x2F;creative people (in comparison to highly analytical people).&lt;&#x2F;p&gt;
&lt;p&gt;I personally use &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;excalidraw.com&#x2F;&quot;&gt;excalidraw&lt;&#x2F;a&gt; for drawing.
It has a “comicy” feel, which takes the edge off a bit.
The implication is that it doesn’t feel highly accurate, but rather serves as a rough sketch.
Many good engineers (as well as great Mathematicians and Physicists) are able to visualize concepts with sketches.&lt;&#x2F;p&gt;
&lt;p&gt;In Rust, sketches can help to visualize lifetimes and ownership of data or for architecture diagrams.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;build-on-top-of-what-you-already-know&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#build-on-top-of-what-you-already-know&quot; aria-label=&quot;Anchor link for: build-on-top-of-what-you-already-know&quot;&gt;Build On Top Of What You Already Know&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;p&gt;Earlier I said you should forget everything you know about programming.
How can I claim now that you should build on top of what you already know?&lt;&#x2F;p&gt;
&lt;p&gt;What I meant is that Rust is the most different in familiar areas like control flow handling and value passing.
E.g., mutability is very explicit in Rust and calling a function typically “moves” its arguments.
That’s where you have to accept that Rust is just &lt;em&gt;different&lt;&#x2F;em&gt; and learn from &lt;em&gt;first principles&lt;&#x2F;em&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;However, it is okay to map Rust concepts to other languages you already know.
For instance, “a trait is a bit like an interface” is wrong, but it is a good starting point
to understand the concept.&lt;&#x2F;p&gt;
&lt;p&gt;Here are a few more examples:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;“A struct is like a class (minus the inheritance)”&lt;&#x2F;li&gt;
&lt;li&gt;“A closure is like a lambda function (but it can capture variables)”&lt;&#x2F;li&gt;
&lt;li&gt;“A module is like a namespace (but more powerful)”&lt;&#x2F;li&gt;
&lt;li&gt;“A borrow is like a pointer (but with single owner).”&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;And if you have a functional background, it might be:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;“&lt;code&gt;Option&lt;&#x2F;code&gt; is like the &lt;code&gt;Maybe&lt;&#x2F;code&gt; monad”&lt;&#x2F;li&gt;
&lt;li&gt;“Traits are like type-classes”&lt;&#x2F;li&gt;
&lt;li&gt;“Enums are algebraic data types”&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;The idea is that mapping concepts helps fill in the gaps more quickly.&lt;&#x2F;p&gt;
&lt;p&gt;Map what you already know from another language (e.g., Python, TypeScript) to Rust concepts.
As long as you know that there are subtle differences, I think it’s helpful.&lt;&#x2F;p&gt;
&lt;p&gt;I don’t see people mention this a lot, but I believe that &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;rosettacode.org&#x2F;wiki&#x2F;Rosetta_Code&quot;&gt;Rosetta Code&lt;&#x2F;a&gt; is a great resource for that.
You basically browse their list of tasks, pick one you like and start comparing the Rust solution with the language you’re strongest in.&lt;&#x2F;p&gt;
&lt;p&gt;Also, port code from a language you know to Rust.
This way, you don’t have to learn a new domain at the same time as you learn Rust.
You can build on your existing knowledge and experience.&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;Translate common language idioms from your strongest language to Rust. E.g., how would you convert a list comprehension from Python to Rust?
Try it first, then look for resources, which explain the concept in Rust. For instance, &lt;a href=&quot;&#x2F;blog&#x2F;iterators&quot;&gt;I wrote one&lt;&#x2F;a&gt; on this topic specifically.&lt;&#x2F;li&gt;
&lt;li&gt;I know people who have a few standard exercises that they port to every new language they learn.
For example, that could be a ray-tracer, a sorting algorithm, or a small web app.&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;Finally, find other people who come from the same background as you.
Read their blogs where they talk about their experiences learning Rust.
Write down your experiences as well.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;don-t-guess&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#don-t-guess&quot; aria-label=&quot;Anchor link for: don-t-guess&quot;&gt;Don’t Guess&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;p&gt;I find that people who tend to &lt;em&gt;guess&lt;&#x2F;em&gt; their way through challenges
often have the hardest time learning Rust.&lt;&#x2F;p&gt;
&lt;p&gt;In Rust, the details are everything.
Don’t gloss over details, because they always reveal some wisdom about the task at hand.
Even if you don’t care about the details, they will come back to bite you later.&lt;&#x2F;p&gt;
&lt;p&gt;For instance, why do you have to call &lt;code&gt;to_string()&lt;&#x2F;code&gt; on a thing that’s already a string?&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;my_func&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt;&amp;quot;hello&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;to_string&lt;&#x2F;span&gt;&lt;span&gt;())&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Those stumbling blocks are learning opportunities.
It might look like a waste of time to ask these questions and means that it will take longer to finish a task,
but it will pay off in the long run.&lt;&#x2F;p&gt;
&lt;p&gt;Reeeeeally read the error messages the compiler prints.
Everyone thinks they do this, but time and again I see people look confused while the solution is right there in their terminal.
There are &lt;code&gt;hints&lt;&#x2F;code&gt; as well; don’t ignore those.
This alone will save you sooo much time.
Thank me later.&lt;&#x2F;p&gt;
&lt;p&gt;You might say that is true for every language, and you’d be right.
But in Rust, the error messages are actually worth your time.
Some of them are like small meditations: opportunities to think about the problem at a deeper level.&lt;&#x2F;p&gt;
&lt;p&gt;If you get any borrow-checker errors, refuse the urge to guess what’s going on.
Instead of guessing, &lt;em&gt;walk through the data flow by hand&lt;&#x2F;em&gt; (who owns what and when).
Try to think it through for yourself and only try to compile again once you understand the problem.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;lean-on-type-driven-development&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#lean-on-type-driven-development&quot; aria-label=&quot;Anchor link for: lean-on-type-driven-development&quot;&gt;Lean on Type-Driven Development&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;p&gt;The key to good Rust code is through its type system.&lt;&#x2F;p&gt;
&lt;p&gt;It’s &lt;strong&gt;all&lt;&#x2F;strong&gt; in the type system.
Everything you need is hidden in plain sight.
But often, people skip too much of the documentation and just look at the examples.&lt;&#x2F;p&gt;
&lt;p&gt;What few people do is &lt;em&gt;read the actual function documentation&lt;&#x2F;em&gt;.
You can even click through the standard library all the way to the source code to read the thing they are using.
There is no magic (and that’s what’s so magical about it).&lt;&#x2F;p&gt;
&lt;p&gt;You can do that in Rust much better than in most other languages.
That’s because Python for example is written in C, which requires you to cross that language boundary to learn what’s going on.
Similarly, the C++ standard library isn’t a single, standardized implementation, but rather has several different implementations maintained by different organizations.
That makes it super hard to know &lt;em&gt;what exactly is going on&lt;&#x2F;em&gt;.
In Rust, the source code is available right inside the documentation. Make good use of that!&lt;&#x2F;p&gt;
&lt;p&gt;Function signatures tell a lot!
The sooner you will embrace this additional information, the quicker you will be off to the races with Rust.
If you have the time, read interesting parts of the standard library docs.
Even after years, I always learn something when I do.&lt;&#x2F;p&gt;
&lt;p&gt;Try to model your own projects with types first.
This is when you start to have way more fun with the language.
It feels like you have a conversation with the compiler about the problem you’re trying to solve.&lt;&#x2F;p&gt;
&lt;p&gt;For example, once you learn how concepts like expressions, iterators and traits fit together,
you can write more concise, readable code.&lt;&#x2F;p&gt;
&lt;p&gt;Once you learn how to encode invariants in types, you can write more correct code
that you don’t have to run to test. Instead, you can’t compile incorrect code in the first place.&lt;&#x2F;p&gt;
&lt;p&gt;Learn Rust through “type-driven development” and let the compiler errors guide your design.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;invest-time-in-finding-good-learning-resources&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#invest-time-in-finding-good-learning-resources&quot; aria-label=&quot;Anchor link for: invest-time-in-finding-good-learning-resources&quot;&gt;Invest Time In Finding Good Learning Resources&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;p&gt;Before you start, shop around for resources that fit your personal learning style.
To be honest, there is not that much good stuff out there yet.
On the plus side, it doesn’t take too long to go through the list of resources
&lt;em&gt;before&lt;&#x2F;em&gt; settling on one specific platform&#x2F;book&#x2F;course.
The right resource depends on what learner you are.
In the long run, finding the right resource saves you time because you will learn quicker.&lt;&#x2F;p&gt;
&lt;p&gt;I personally don’t like doing toy exercises that others have built out for me.
That’s why I don’t like Rustlings too much; the exercises are not “fun” and too theoretical. I want more practical exercises.
I found that &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;projecteuler.net&#x2F;&quot;&gt;Project Euler&lt;&#x2F;a&gt; or &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;adventofcode.com&#x2F;&quot;&gt;Advent of Code&lt;&#x2F;a&gt; work way better for me.
The question comes up quite often, so I wrote a blog post about &lt;a href=&quot;&#x2F;blog&#x2F;rust-learning-resources-2026&#x2F;&quot;&gt;my favorite Rust learning resources&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;h4 id=&quot;don-t-just-watch-youtube&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#don-t-just-watch-youtube&quot; aria-label=&quot;Anchor link for: don-t-just-watch-youtube&quot;&gt;Don’t Just Watch YouTube&lt;&#x2F;a&gt;&lt;&#x2F;h4&gt;
&lt;p&gt;I like to watch YouTube, but exclusively for recreational purposes.
In my opinion, watching &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.youtube.com&#x2F;c&#x2F;theprimeagen&quot;&gt;ThePrimeagen&lt;&#x2F;a&gt; is for entertainment only.
He’s an amazing programmer, but trying to learn how to program by watching someone else do it is like trying to learn how to become a great athlete by watching the Olympics.
Similarly, I think we all can agree that &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.youtube.com&#x2F;c&#x2F;JonGjengset&quot;&gt;Jon Gjengset&lt;&#x2F;a&gt; is an exceptional programmer and teacher, but watching him might be overwhelming
if you’re just starting out. (Love the content though!)&lt;&#x2F;p&gt;
&lt;p&gt;Same goes for conference talks or podcasts: they are great for context, and for soft-skills, but not for learning Rust.&lt;&#x2F;p&gt;
&lt;p&gt;Instead, invest in a good book if you can.
Books are not yet outdated and you can read them offline, add personal notes, type out the code yourself and get a
“spatial overview” of the depth of the content by flipping through the pages.&lt;&#x2F;p&gt;
&lt;p&gt;Similarly, if you’re serious about using Rust professionally, buy a course or get your boss to invest in a trainer.
Of course, I’m super biased here as I run a Rust consultancy, but I truly believe that it will save you and your company countless
hours and will set you up for long-term success. Think about it: you will work with this codebase for years to come. Better make that experience a pleasant one.
A good trainer, just like a good teacher, will not go through the Rust book with you, but watch you program Rust in the wild and give you personalized feedback about your weak spots.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;find-a-coding-buddy&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#find-a-coding-buddy&quot; aria-label=&quot;Anchor link for: find-a-coding-buddy&quot;&gt;Find A Coding Buddy&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;p&gt;“Shadow” more experienced team members or friends.&lt;&#x2F;p&gt;
&lt;p&gt;Don’t be afraid to ask for a code review on Mastodon or the &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;users.rust-lang.org&#x2F;&quot;&gt;Rust forum&lt;&#x2F;a&gt; and return the favor and do code reviews there yourself.
Take on opportunities for pair programming.&lt;&#x2F;p&gt;
&lt;h4 id=&quot;explain-rust-code-to-non-rust-developers&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#explain-rust-code-to-non-rust-developers&quot; aria-label=&quot;Anchor link for: explain-rust-code-to-non-rust-developers&quot;&gt;Explain Rust Code To Non-Rust Developers&lt;&#x2F;a&gt;&lt;&#x2F;h4&gt;
&lt;p&gt;This is such a great way to see if you truly understood a concept.
Don’t be afraid to say “I don’t know.”
Then go and explore the answer together by going straight to the docs.
It’s way more rewarding and honest.&lt;&#x2F;p&gt;
&lt;p&gt;Help out with OSS code that is abandoned.
If you put in a solid effort to fix an unmaintained codebase, you will help others while learning how to work with other people’s Rust code.&lt;&#x2F;p&gt;
&lt;p&gt;Read code out loud and explain it.
There’s no shame in that!
It helps you “serialize” your thoughts and avoid skipping important details.&lt;&#x2F;p&gt;
&lt;p&gt;Take notes.
Write your own little “Rust glossary” that maps Rust terminology to concepts in your business domain.
It doesn’t have to be complete and just has to serve your needs.&lt;&#x2F;p&gt;
&lt;p&gt;Write down things you found hard and things you learned.
If you find a great learning resource, share it!&lt;&#x2F;p&gt;
&lt;h2 id=&quot;believe-in-the-long-term-benefit&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#believe-in-the-long-term-benefit&quot; aria-label=&quot;Anchor link for: believe-in-the-long-term-benefit&quot;&gt;Believe In The Long-Term Benefit&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;p&gt;If you learn Rust because you want to put it on your CV, stop.
Learn something else instead.&lt;&#x2F;p&gt;
&lt;p&gt;I think you have to actually &lt;em&gt;like&lt;&#x2F;em&gt; programming (and not just the idea of it) to enjoy Rust.&lt;&#x2F;p&gt;
&lt;p&gt;If you want to be successful with Rust, you have to be in it for the long run.
Set realistic expectations: You won’t be a “Rust grandmaster” in a week but you can achieve a lot in a month of focused effort.
There is no silver bullet, but if you avoid the most common ways to shoot yourself in the foot, you pick up the language much faster.
Rust is a day 2 language. You won’t “feel” as productive as in your first week of Go or Python, but stick it out and it will pay off.
Good luck and have fun!&lt;&#x2F;p&gt;
</description>
      </item>
      <item>
          <title>Svix</title>
          <pubDate>Thu, 01 May 2025 00:00:00 +0000</pubDate>
          <author>Matthias Endler</author>
          <link>https://corrode.dev/podcast/s04e02-svix/</link>
          <guid>https://corrode.dev/podcast/s04e02-svix/</guid>
          <description xml:base="https://corrode.dev/podcast/s04e02-svix/">&lt;div&gt;&lt;script id=&quot;letscast-player-db5e5052&quot; src=&quot;https:&#x2F;&#x2F;letscast.fm&#x2F;podcasts&#x2F;rust-in-production-82281512&#x2F;episodes&#x2F;svix-with-tom-hacohen&#x2F;player.js?size=s&quot;&gt;&lt;&#x2F;script&gt;&lt;&#x2F;div&gt;
&lt;p&gt;We don’t usually think much about Webhooks – at least I don’t.
It’s just web requests after all, right?
In reality, there is a lot of complexity behind routing webhook requests through the internet.&lt;&#x2F;p&gt;
&lt;p&gt;What if a webhook request gets lost?
How do you know it was received in the first place?
Can it be a security issue if a webhook gets handled twice? (Spoiler alert: yes)&lt;&#x2F;p&gt;</description>
      </item>
      <item>
          <title>Microsoft</title>
          <pubDate>Thu, 17 Apr 2025 00:00:00 +0000</pubDate>
          <author>Matthias Endler</author>
          <link>https://corrode.dev/podcast/s04e01-microsoft/</link>
          <guid>https://corrode.dev/podcast/s04e01-microsoft/</guid>
          <description xml:base="https://corrode.dev/podcast/s04e01-microsoft/">&lt;div&gt;&lt;script id=&quot;letscast-player-ec2b56fd&quot; src=&quot;https:&#x2F;&#x2F;letscast.fm&#x2F;podcasts&#x2F;rust-in-production-82281512&#x2F;episodes&#x2F;microsoft-with-victor-ciura&#x2F;player.js?size=s&quot;&gt;&lt;&#x2F;script&gt;&lt;&#x2F;div&gt;
&lt;p&gt;Victor Ciura is a veteran C++ developer who worked on Visual C++ and the Clang Power Tools.
In this first episode of season 4, we talk to him about large-scale Rust adoption at Microsoft.&lt;&#x2F;p&gt;</description>
      </item>
      <item>
          <title>Pitfalls of Safe Rust</title>
          <pubDate>Tue, 01 Apr 2025 00:00:00 +0000</pubDate>
          <author>Matthias Endler</author>
          <link>https://corrode.dev/blog/pitfalls-of-safe-rust/</link>
          <guid>https://corrode.dev/blog/pitfalls-of-safe-rust/</guid>
          <description xml:base="https://corrode.dev/blog/pitfalls-of-safe-rust/">&lt;p&gt;When people say Rust is a “safe language”, they often mean memory safety.
And while memory safety is a great start, it’s far from all it takes to build robust applications.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;strong&gt;Memory safety is necessary but not sufficient for overall reliability.&lt;&#x2F;strong&gt;&lt;&#x2F;p&gt;
&lt;p&gt;In this article, I want to show you a few common gotchas in safe Rust that the compiler doesn’t detect and how to avoid them.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;why-rust-can-t-always-help&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#why-rust-can-t-always-help&quot; aria-label=&quot;Anchor link for: why-rust-can-t-always-help&quot;&gt;Why Rust Can’t Always Help&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;p&gt;Even in safe Rust code, you still need to handle various risks and edge cases.
You need to address aspects like input validation and making sure that your business logic is correct.&lt;&#x2F;p&gt;
&lt;p&gt;Here are just a few categories of bugs that Rust &lt;strong&gt;doesn’t&lt;&#x2F;strong&gt; protect you from:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;Type casting mistakes (e.g. overflows)&lt;&#x2F;li&gt;
&lt;li&gt;Logic bugs&lt;&#x2F;li&gt;
&lt;li&gt;Panics because of using &lt;code&gt;unwrap&lt;&#x2F;code&gt; or &lt;code&gt;expect&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;Malicious or incorrect &lt;code&gt;build.rs&lt;&#x2F;code&gt; scripts in third-party crates&lt;&#x2F;li&gt;
&lt;li&gt;Incorrect unsafe code in third-party libraries&lt;&#x2F;li&gt;
&lt;li&gt;Race conditions&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;Let’s look at ways to avoid some of the more common problems.
The tips are roughly ordered by how likely you are to encounter them.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;table-of-contents&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#table-of-contents&quot; aria-label=&quot;Anchor link for: table-of-contents&quot;&gt;Table of Contents&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;details class=&quot;toc&quot;&gt;
&lt;summary&gt;
Click here to expand the table of contents.
&lt;&#x2F;summary&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;https:&#x2F;&#x2F;corrode.dev&#x2F;blog&#x2F;pitfalls-of-safe-rust&#x2F;#protect-against-integer-overflow&quot;&gt;Protect Against Integer Overflow&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a href=&quot;https:&#x2F;&#x2F;corrode.dev&#x2F;blog&#x2F;pitfalls-of-safe-rust&#x2F;#avoid-as-for-numeric-conversions&quot;&gt;Avoid &lt;code&gt;as&lt;&#x2F;code&gt; For Numeric Conversions&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a href=&quot;https:&#x2F;&#x2F;corrode.dev&#x2F;blog&#x2F;pitfalls-of-safe-rust&#x2F;#use-bounded-types-for-numeric-values&quot;&gt;Use Bounded Types for Numeric Values&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a href=&quot;https:&#x2F;&#x2F;corrode.dev&#x2F;blog&#x2F;pitfalls-of-safe-rust&#x2F;#don-t-index-into-arrays-without-bounds-checking&quot;&gt;Don’t Index Into Arrays Without Bounds Checking&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a href=&quot;https:&#x2F;&#x2F;corrode.dev&#x2F;blog&#x2F;pitfalls-of-safe-rust&#x2F;#use-split-at-checked-instead-of-split-at&quot;&gt;Use &lt;code&gt;split_at_checked&lt;&#x2F;code&gt; Instead Of &lt;code&gt;split_at&lt;&#x2F;code&gt;&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a href=&quot;https:&#x2F;&#x2F;corrode.dev&#x2F;blog&#x2F;pitfalls-of-safe-rust&#x2F;#make-invalid-states-unrepresentable&quot;&gt;Make Invalid States Unrepresentable&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a href=&quot;https:&#x2F;&#x2F;corrode.dev&#x2F;blog&#x2F;pitfalls-of-safe-rust&#x2F;#avoid-primitive-types-for-business-logic&quot;&gt;Avoid Primitive Types For Business Logic&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a href=&quot;https:&#x2F;&#x2F;corrode.dev&#x2F;blog&#x2F;pitfalls-of-safe-rust&#x2F;#handle-default-values-carefully&quot;&gt;Handle Default Values Carefully&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a href=&quot;https:&#x2F;&#x2F;corrode.dev&#x2F;blog&#x2F;pitfalls-of-safe-rust&#x2F;#implement-debug-safely&quot;&gt;Implement &lt;code&gt;Debug&lt;&#x2F;code&gt; Safely&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a href=&quot;https:&#x2F;&#x2F;corrode.dev&#x2F;blog&#x2F;pitfalls-of-safe-rust&#x2F;#careful-with-serialization&quot;&gt;Careful With Serialization&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a href=&quot;https:&#x2F;&#x2F;corrode.dev&#x2F;blog&#x2F;pitfalls-of-safe-rust&#x2F;#protect-against-time-of-check-to-time-of-use-toctou&quot;&gt;Protect Against Time-of-Check to Time-of-Use (TOCTOU)&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a href=&quot;https:&#x2F;&#x2F;corrode.dev&#x2F;blog&#x2F;pitfalls-of-safe-rust&#x2F;#use-constant-time-comparison-for-sensitive-data&quot;&gt;Use Constant-Time Comparison for Sensitive Data&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a href=&quot;https:&#x2F;&#x2F;corrode.dev&#x2F;blog&#x2F;pitfalls-of-safe-rust&#x2F;#don-t-accept-unbounded-input&quot;&gt;Don’t Accept Unbounded Input&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a href=&quot;https:&#x2F;&#x2F;corrode.dev&#x2F;blog&#x2F;pitfalls-of-safe-rust&#x2F;#surprising-behavior-of-path-join-with-absolute-paths&quot;&gt;Surprising Behavior of &lt;code&gt;Path::join&lt;&#x2F;code&gt; With Absolute Paths&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a href=&quot;https:&#x2F;&#x2F;corrode.dev&#x2F;blog&#x2F;pitfalls-of-safe-rust&#x2F;#check-for-unsafe-code-in-your-dependencies-with-cargo-geiger&quot;&gt;Check For Unsafe Code In Your Dependencies With &lt;code&gt;cargo-geiger&lt;&#x2F;code&gt;&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a href=&quot;https:&#x2F;&#x2F;corrode.dev&#x2F;blog&#x2F;pitfalls-of-safe-rust&#x2F;#conclusion&quot;&gt;Conclusion&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;details&gt;
&lt;h2 id=&quot;protect-against-integer-overflow&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#protect-against-integer-overflow&quot; aria-label=&quot;Anchor link for: protect-against-integer-overflow&quot;&gt;Protect Against Integer Overflow&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;p&gt;Overflow errors can happen pretty easily:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;&#x2F;&#x2F; DON&amp;#39;T: Use unchecked arithmetic&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;fn&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; calculate_total&lt;&#x2F;span&gt;&lt;span&gt;(price&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; u32&lt;&#x2F;span&gt;&lt;span&gt;, quantity&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; u32&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; -&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; u32&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    price&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; *&lt;&#x2F;span&gt;&lt;span&gt; quantity&lt;&#x2F;span&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;  &#x2F;&#x2F; Could overflow!&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;If &lt;code&gt;price&lt;&#x2F;code&gt; and &lt;code&gt;quantity&lt;&#x2F;code&gt; are large enough, the result will overflow.
Rust will panic in debug mode, but in release mode, it will silently wrap around.&lt;&#x2F;p&gt;
&lt;p&gt;To avoid this, use checked arithmetic operations:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;&#x2F;&#x2F; DO: Use checked arithmetic operations&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;fn&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; calculate_total&lt;&#x2F;span&gt;&lt;span&gt;(price&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; u32&lt;&#x2F;span&gt;&lt;span&gt;, quantity&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; u32&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; -&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Result&lt;&#x2F;span&gt;&lt;span&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;u32&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; ArithmeticError&lt;&#x2F;span&gt;&lt;span&gt;&amp;gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    price&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;checked_mul&lt;&#x2F;span&gt;&lt;span&gt;(quantity)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;        .&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;ok_or&lt;&#x2F;span&gt;&lt;span&gt;(ArithmeticError&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;Overflow&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Static checks are not removed since they don’t affect the performance of generated code.
So if the compiler is able to detect the problem at compile time, it will do so:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;fn&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; main&lt;&#x2F;span&gt;&lt;span&gt;() {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    let&lt;&#x2F;span&gt;&lt;span&gt; x&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; u8&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt; 2&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    let&lt;&#x2F;span&gt;&lt;span&gt; y&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; u8&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt; 128&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    let&lt;&#x2F;span&gt;&lt;span&gt; z&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; x&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; *&lt;&#x2F;span&gt;&lt;span&gt; y;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;  &#x2F;&#x2F; Compile-time error!&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;The error message will be:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;error&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span&gt; this arithmetic operation will overflow&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; --&amp;gt;&lt;&#x2F;span&gt;&lt;span&gt; src&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;&#x2F;&lt;&#x2F;span&gt;&lt;span&gt;main&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span&gt;rs&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt;4&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt;13&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;  |&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt;4&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; |     let&lt;&#x2F;span&gt;&lt;span&gt; z&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; x&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; *&lt;&#x2F;span&gt;&lt;span&gt; y;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;  &#x2F;&#x2F; Compile-time error!&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;  |             ^^^^^&lt;&#x2F;span&gt;&lt;span&gt; attempt to compute `&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt;2_&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;u8&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; *&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt; 128_&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;u8&lt;&#x2F;span&gt;&lt;span&gt;`, which would overflow&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;  |&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;  =&lt;&#x2F;span&gt;&lt;span&gt; note&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span&gt; `#[deny(arithmetic_overflow)]` on by default&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;For all other cases, use &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;docs.rs&#x2F;num&#x2F;latest&#x2F;num&#x2F;trait.CheckedAdd.html&quot;&gt;&lt;code&gt;checked_add&lt;&#x2F;code&gt;&lt;&#x2F;a&gt;, &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;docs.rs&#x2F;num&#x2F;latest&#x2F;num&#x2F;trait.CheckedSub.html&quot;&gt;&lt;code&gt;checked_sub&lt;&#x2F;code&gt;&lt;&#x2F;a&gt;, &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;docs.rs&#x2F;num&#x2F;latest&#x2F;num&#x2F;trait.CheckedMul.html&quot;&gt;&lt;code&gt;checked_mul&lt;&#x2F;code&gt;&lt;&#x2F;a&gt;, and &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;docs.rs&#x2F;num&#x2F;latest&#x2F;num&#x2F;trait.CheckedDiv.html&quot;&gt;&lt;code&gt;checked_div&lt;&#x2F;code&gt;&lt;&#x2F;a&gt;, which return &lt;code&gt;None&lt;&#x2F;code&gt; instead of wrapping around on underflow or overflow. &lt;sup class=&quot;footnote-reference&quot; id=&quot;fr-intrinsics_docs-1&quot;&gt;&lt;a href=&quot;#fn-intrinsics_docs&quot;&gt;1&lt;&#x2F;a&gt;&lt;&#x2F;sup&gt;&lt;&#x2F;p&gt;
&lt;div class=&quot;info&quot;&gt;
  
  &lt;div class=&quot;info-header&quot;&gt;
    
      &lt;span class=&quot;icon icon-info&quot;&gt;&lt;&#x2F;span&gt;
    
    &lt;h4&gt;&lt;p&gt;Quick Tip: Enable Overflow Checks In Release Mode&lt;&#x2F;p&gt;
&lt;&#x2F;h4&gt;
  &lt;&#x2F;div&gt;
  
  &lt;p&gt;Rust carefully balances performance and safety.
In scenarios where a performance hit is acceptable, memory safety takes precedence. &lt;sup class=&quot;footnote-reference&quot; id=&quot;fr-memory_safety-1&quot;&gt;&lt;a href=&quot;#fn-memory_safety&quot;&gt;1&lt;&#x2F;a&gt;&lt;&#x2F;sup&gt;&lt;&#x2F;p&gt;
&lt;p&gt;Integer overflows can lead to unexpected results, but they are not inherently unsafe.
On top of that, overflow checks can be expensive, which is why Rust disables them in release mode. &lt;sup class=&quot;footnote-reference&quot; id=&quot;fr-overflow-1&quot;&gt;&lt;a href=&quot;#fn-overflow&quot;&gt;2&lt;&#x2F;a&gt;&lt;&#x2F;sup&gt;&lt;&#x2F;p&gt;
&lt;p&gt;However, you can re-enable them in case your application can trade the last 1%
of performance for better overflow detection.&lt;&#x2F;p&gt;
&lt;p&gt;Put this into your &lt;code&gt;Cargo.toml&lt;&#x2F;code&gt;:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;toml&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;[&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;&quot;&gt;profile&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;&quot;&gt;release&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #8BE9FD;&quot;&gt;overflow-checks&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt; true&lt;&#x2F;span&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt; # Enable integer overflow checks in release mode&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;This will enable overflow checks in release mode. As a consequence,
the code will panic if an overflow occurs.&lt;&#x2F;p&gt;
&lt;p&gt;See &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;doc.rust-lang.org&#x2F;cargo&#x2F;reference&#x2F;profiles.html#release&quot;&gt;the docs&lt;&#x2F;a&gt;
for more details.&lt;&#x2F;p&gt;
&lt;section class=&quot;footnotes&quot;&gt;
&lt;ol class=&quot;footnotes-list&quot;&gt;
&lt;li id=&quot;fn-memory_safety&quot;&gt;
&lt;p&gt;One example where Rust accepts a performance cost for safety would be checked array indexing, which prevents buffer overflows at runtime. Another is when the Rust maintainers &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;internals.rust-lang.org&#x2F;t&#x2F;help-us-benchmark-saturating-float-casts&#x2F;6231&quot;&gt;fixed float casting&lt;&#x2F;a&gt; because the previous implementation could cause undefined behavior when casting certain floating point values to integers. &lt;a href=&quot;#fr-memory_safety-1&quot;&gt;↩&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;&#x2F;li&gt;
&lt;li id=&quot;fn-overflow&quot;&gt;
&lt;p&gt;According to some benchmarks, overflow checks cost a few percent of performance on typical integer-heavy workloads. See Dan Luu’s analysis &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;danluu.com&#x2F;integer-overflow&#x2F;&quot;&gt;here&lt;&#x2F;a&gt; &lt;a href=&quot;#fr-overflow-1&quot;&gt;↩&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;&#x2F;section&gt;

&lt;&#x2F;div&gt;
&lt;h2 id=&quot;avoid-as-for-numeric-conversions&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#avoid-as-for-numeric-conversions&quot; aria-label=&quot;Anchor link for: avoid-as-for-numeric-conversions&quot;&gt;Avoid &lt;code&gt;as&lt;&#x2F;code&gt; For Numeric Conversions&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;p&gt;While we’re on the topic of integer arithmetic, let’s talk about type conversions.
Casting values with &lt;code&gt;as&lt;&#x2F;code&gt; is convenient but risky unless you know exactly what you are doing.&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;let&lt;&#x2F;span&gt;&lt;span&gt; x&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; i32&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt; 42&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;let&lt;&#x2F;span&gt;&lt;span&gt; y&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; i8&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; x&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; as&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; i8&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;  &#x2F;&#x2F; Can overflow!&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;There are three main ways to convert between numeric types in Rust:&lt;&#x2F;p&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;⚠️ Using the &lt;code&gt;as&lt;&#x2F;code&gt; keyword: This approach works for both lossless and lossy conversions. In cases where data loss might occur (like converting from &lt;code&gt;i64&lt;&#x2F;code&gt; to &lt;code&gt;i32&lt;&#x2F;code&gt;), &lt;strong&gt;it will simply truncate the value&lt;&#x2F;strong&gt;.&lt;&#x2F;p&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;
&lt;p&gt;Using &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;doc.rust-lang.org&#x2F;std&#x2F;convert&#x2F;trait.From.html&quot;&gt;&lt;code&gt;From::from()&lt;&#x2F;code&gt;&lt;&#x2F;a&gt;: This method only allows &lt;strong&gt;lossless conversions&lt;&#x2F;strong&gt;. For example, you can convert from &lt;code&gt;i32&lt;&#x2F;code&gt; to &lt;code&gt;i64&lt;&#x2F;code&gt; since all 32-bit integers can fit within 64 bits. However, you cannot convert from &lt;code&gt;i64&lt;&#x2F;code&gt; to &lt;code&gt;i32&lt;&#x2F;code&gt; using this method since it could potentially lose data.&lt;&#x2F;p&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;
&lt;p&gt;Using &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;doc.rust-lang.org&#x2F;std&#x2F;convert&#x2F;trait.TryFrom.html&quot;&gt;&lt;code&gt;TryFrom&lt;&#x2F;code&gt;&lt;&#x2F;a&gt;: This method is similar to &lt;code&gt;From::from()&lt;&#x2F;code&gt; but returns a &lt;code&gt;Result&lt;&#x2F;code&gt; instead of panicking. This is useful when you want to handle potential data loss gracefully.&lt;&#x2F;p&gt;
&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;div class=&quot;info&quot;&gt;
  
  &lt;div class=&quot;info-header&quot;&gt;
    
      &lt;span class=&quot;icon icon-info&quot;&gt;&lt;&#x2F;span&gt;
    
    &lt;h4&gt;&lt;p&gt;Quick Tip: Safe Numeric Conversions&lt;&#x2F;p&gt;
&lt;&#x2F;h4&gt;
  &lt;&#x2F;div&gt;
  
  &lt;p&gt;&lt;strong&gt;If in doubt, prefer &lt;code&gt;From::from()&lt;&#x2F;code&gt; and &lt;code&gt;TryFrom&lt;&#x2F;code&gt; over &lt;code&gt;as&lt;&#x2F;code&gt;.&lt;&#x2F;strong&gt;&lt;&#x2F;p&gt;
&lt;ol&gt;
&lt;li&gt;use &lt;code&gt;From::from()&lt;&#x2F;code&gt; when you can guarantee no data loss.&lt;&#x2F;li&gt;
&lt;li&gt;use &lt;code&gt;TryFrom&lt;&#x2F;code&gt; when you need to handle potential data loss gracefully.&lt;&#x2F;li&gt;
&lt;li&gt;only use &lt;code&gt;as&lt;&#x2F;code&gt; when you’re comfortable with potential truncation or know the values will fit within the target type’s range and when performance is absolutely critical.&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;p&gt;(&lt;em&gt;Adapted from &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;stackoverflow.com&#x2F;a&#x2F;28280042&#x2F;270334&quot;&gt;StackOverflow answer by delnan&lt;&#x2F;a&gt; and &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;stackoverflow.com&#x2F;a&#x2F;48795524&#x2F;270334&quot;&gt;additional context&lt;&#x2F;a&gt;.&lt;&#x2F;em&gt;)&lt;&#x2F;p&gt;

&lt;&#x2F;div&gt;
&lt;p&gt;The &lt;code&gt;as&lt;&#x2F;code&gt; operator is &lt;strong&gt;not safe for narrowing conversions&lt;&#x2F;strong&gt;.
It will silently truncate the value, leading to unexpected results.&lt;&#x2F;p&gt;
&lt;p&gt;What is a “narrowing conversion”?
It’s when you convert a larger type to a smaller type, e.g. &lt;code&gt;i32&lt;&#x2F;code&gt; to &lt;code&gt;i8&lt;&#x2F;code&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;For example, see how &lt;code&gt;as&lt;&#x2F;code&gt; chops off the high bits from our value:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;fn&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; main&lt;&#x2F;span&gt;&lt;span&gt;() {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    let&lt;&#x2F;span&gt;&lt;span&gt; a&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; u16&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt; 0x1234&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    let&lt;&#x2F;span&gt;&lt;span&gt; b&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; u8&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; a&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; as&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; u8&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;    println!&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt;&amp;quot;0x{:04x}, 0x{:02x}&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;, a, b);&lt;&#x2F;span&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt; &#x2F;&#x2F; 0x1234, 0x34&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;So, coming back to our first example above, instead of writing&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;let&lt;&#x2F;span&gt;&lt;span&gt; x&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; i32&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt; 42&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;let&lt;&#x2F;span&gt;&lt;span&gt; y&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; i8&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; x&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; as&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; i8&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;  &#x2F;&#x2F; Can overflow!&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;use &lt;code&gt;TryFrom&lt;&#x2F;code&gt; instead and handle the error gracefully:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;let&lt;&#x2F;span&gt;&lt;span&gt; y&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; i8&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;try_from&lt;&#x2F;span&gt;&lt;span&gt;(x)&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;ok_or&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt;&amp;quot;Number is too big to be used here&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;?&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;&lt;h2 id=&quot;use-bounded-types-for-numeric-values&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#use-bounded-types-for-numeric-values&quot; aria-label=&quot;Anchor link for: use-bounded-types-for-numeric-values&quot;&gt;Use Bounded Types for Numeric Values&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;p&gt;Bounded types make it easier to express invariants and avoid invalid states.
E.g. if you have a numeric type and 0 is &lt;em&gt;never&lt;&#x2F;em&gt; a correct value, use &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;doc.rust-lang.org&#x2F;std&#x2F;num&#x2F;type.NonZeroUsize.html&quot;&gt;&lt;code&gt;std::num::NonZeroUsize&lt;&#x2F;code&gt;&lt;&#x2F;a&gt; instead.&lt;&#x2F;p&gt;
&lt;p&gt;You can also create your own bounded types:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;&#x2F;&#x2F; DON&amp;#39;T: Use raw numeric types for domain values&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;struct&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Measurement&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    distance&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; f64&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;  &#x2F;&#x2F; Could be negative!&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;&#x2F;&#x2F; DO: Create bounded types&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;#[derive(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;Debug&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Clone&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Copy&lt;&#x2F;span&gt;&lt;span&gt;)]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;struct&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Distance&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;f64&lt;&#x2F;span&gt;&lt;span&gt;);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;impl&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Distance&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    pub fn&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; new&lt;&#x2F;span&gt;&lt;span&gt;(value&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; f64&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; -&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Result&lt;&#x2F;span&gt;&lt;span&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;font-style: italic;&quot;&gt;Self&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; DistanceError&lt;&#x2F;span&gt;&lt;span&gt;&amp;gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;        if&lt;&#x2F;span&gt;&lt;span&gt; value&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; &amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt; 0.0&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; || !&lt;&#x2F;span&gt;&lt;span&gt;value&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;is_finite&lt;&#x2F;span&gt;&lt;span&gt;() {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;            return&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Err&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;DistanceError&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;Invalid&lt;&#x2F;span&gt;&lt;span&gt;);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;        Ok&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;Distance&lt;&#x2F;span&gt;&lt;span&gt;(value))&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;struct&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Measurement&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    distance&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Distance&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;(&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;play.rust-lang.org&#x2F;?version=stable&amp;amp;mode=debug&amp;amp;edition=2024&amp;amp;gist=a9157c58ada88e85b82d835a5eceac66&quot;&gt;Rust Playground&lt;&#x2F;a&gt;)&lt;&#x2F;p&gt;
&lt;h2 id=&quot;don-t-index-into-arrays-without-bounds-checking&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#don-t-index-into-arrays-without-bounds-checking&quot; aria-label=&quot;Anchor link for: don-t-index-into-arrays-without-bounds-checking&quot;&gt;Don’t Index Into Arrays Without Bounds Checking&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;p&gt;Whenever I see the following, I get goosebumps 😨:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;let&lt;&#x2F;span&gt;&lt;span&gt; arr&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; [&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt;1&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt; 2&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt; 3&lt;&#x2F;span&gt;&lt;span&gt;];&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;let&lt;&#x2F;span&gt;&lt;span&gt; elem&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; arr[&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt;3&lt;&#x2F;span&gt;&lt;span&gt;];&lt;&#x2F;span&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;  &#x2F;&#x2F; uh-oh!&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;That’s a common source of bugs.
Unlike C, Rust &lt;em&gt;does&lt;&#x2F;em&gt; check array bounds and prevents a security vulnerability,
but &lt;strong&gt;it still panics at runtime&lt;&#x2F;strong&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;Instead, use the &lt;code&gt;get&lt;&#x2F;code&gt; method:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;let&lt;&#x2F;span&gt;&lt;span&gt; elem&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; arr&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;get&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt;3&lt;&#x2F;span&gt;&lt;span&gt;);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;It returns an &lt;code&gt;Option&lt;&#x2F;code&gt; which you can now handle gracefully.
See &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;shnatsel.medium.com&#x2F;how-to-avoid-bounds-checks-in-rust-without-unsafe-f65e618b4c1e&quot;&gt;this blog post&lt;&#x2F;a&gt; for more info on the topic.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;use-split-at-checked-instead-of-split-at&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#use-split-at-checked-instead-of-split-at&quot; aria-label=&quot;Anchor link for: use-split-at-checked-instead-of-split-at&quot;&gt;Use &lt;code&gt;split_at_checked&lt;&#x2F;code&gt; Instead Of &lt;code&gt;split_at&lt;&#x2F;code&gt;&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;p&gt;This issue is related to the previous one.
Say you have a slice and you want to split it at a certain index.&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;let&lt;&#x2F;span&gt;&lt;span&gt; mid&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt; 4&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;let&lt;&#x2F;span&gt;&lt;span&gt; arr&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; [&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt;1&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt; 2&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt; 3&lt;&#x2F;span&gt;&lt;span&gt;];&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;let&lt;&#x2F;span&gt;&lt;span&gt; (left, right)&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; arr&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;split_at&lt;&#x2F;span&gt;&lt;span&gt;(mid);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;You might expect that this returns a tuple of slices where the first slice contains all elements
and the second slice is empty.&lt;&#x2F;p&gt;
&lt;p&gt;⚠️ &lt;strong&gt;Instead, the above code will panic because the mid index is out of bounds!&lt;&#x2F;strong&gt;&lt;&#x2F;p&gt;
&lt;p&gt;To handle that more gracefully, use &lt;code&gt;split_at_checked&lt;&#x2F;code&gt; instead:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;let&lt;&#x2F;span&gt;&lt;span&gt; arr&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; [&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt;1&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt; 2&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt; 3&lt;&#x2F;span&gt;&lt;span&gt;];&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;&#x2F;&#x2F; This returns an Option&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;match&lt;&#x2F;span&gt;&lt;span&gt; arr&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;split_at_checked&lt;&#x2F;span&gt;&lt;span&gt;(mid) {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;    Some&lt;&#x2F;span&gt;&lt;span&gt;((left, right))&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&amp;gt;&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;        &#x2F;&#x2F; Do something with left and right&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;    None&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&amp;gt;&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;        &#x2F;&#x2F; Handle the error&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;This returns an &lt;code&gt;Option&lt;&#x2F;code&gt; which allows you to handle the error case.
(&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;play.rust-lang.org&#x2F;?version=stable&amp;amp;mode=debug&amp;amp;edition=2024&amp;amp;gist=8208b1a16e73e63d37799fed27cd1e49&quot;&gt;Rust Playground&lt;&#x2F;a&gt;)&lt;&#x2F;p&gt;
&lt;p&gt;More info about &lt;code&gt;split_at_checked&lt;&#x2F;code&gt; &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;doc.rust-lang.org&#x2F;std&#x2F;primitive.slice.html#method.split_at_checked&quot;&gt;here&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;avoid-primitive-types-for-business-logic&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#avoid-primitive-types-for-business-logic&quot; aria-label=&quot;Anchor link for: avoid-primitive-types-for-business-logic&quot;&gt;Avoid Primitive Types For Business Logic&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;p&gt;It’s very tempting to use primitive types for everything.
Especially Rust beginners fall into this trap.&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;&#x2F;&#x2F; DON&amp;#39;T: Use primitive types for usernames&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;fn&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; authenticate_user&lt;&#x2F;span&gt;&lt;span&gt;(username&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; String&lt;&#x2F;span&gt;&lt;span&gt;) {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;    &#x2F;&#x2F; Raw String could be anything - empty, too long, or contain invalid characters&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;However, do you really accept &lt;em&gt;any&lt;&#x2F;em&gt; string as a valid username?
What if it’s empty? What if it contains emojis or special characters?
That would likely be unexpected.&lt;&#x2F;p&gt;
&lt;p&gt;Instead, you can create a custom type for your domain:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;#[derive(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;Debug&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Clone&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; PartialEq&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Eq&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Hash&lt;&#x2F;span&gt;&lt;span&gt;)]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;struct&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Username&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;String&lt;&#x2F;span&gt;&lt;span&gt;);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;impl&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Username&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    pub fn&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; new&lt;&#x2F;span&gt;&lt;span&gt;(name&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;: &amp;amp;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;str&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; -&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Result&lt;&#x2F;span&gt;&lt;span&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;font-style: italic;&quot;&gt;Self&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; UsernameError&lt;&#x2F;span&gt;&lt;span&gt;&amp;gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;        &#x2F;&#x2F; Check for empty username&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;        if&lt;&#x2F;span&gt;&lt;span&gt; name&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;is_empty&lt;&#x2F;span&gt;&lt;span&gt;() {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;            return&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Err&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;UsernameError&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;Empty&lt;&#x2F;span&gt;&lt;span&gt;);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;        &#x2F;&#x2F; Check length (for example, max 30 characters)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;        if&lt;&#x2F;span&gt;&lt;span&gt; name&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;len&lt;&#x2F;span&gt;&lt;span&gt;() &amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt; 30&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;            return&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Err&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;UsernameError&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;TooLong&lt;&#x2F;span&gt;&lt;span&gt;);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;        &#x2F;&#x2F; Only allow alphanumeric characters and underscores&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;        if !&lt;&#x2F;span&gt;&lt;span&gt;name&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;chars&lt;&#x2F;span&gt;&lt;span&gt;()&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;all&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;|&lt;&#x2F;span&gt;&lt;span&gt;c&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;|&lt;&#x2F;span&gt;&lt;span&gt; c&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;is_alphanumeric&lt;&#x2F;span&gt;&lt;span&gt;()&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; ||&lt;&#x2F;span&gt;&lt;span&gt; c&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; ==&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt; &amp;#39;_&amp;#39;&lt;&#x2F;span&gt;&lt;span&gt;) {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;            return&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Err&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;UsernameError&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;InvalidCharacters&lt;&#x2F;span&gt;&lt;span&gt;);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;        Ok&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;Username&lt;&#x2F;span&gt;&lt;span&gt;(name&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;to_string&lt;&#x2F;span&gt;&lt;span&gt;()))&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;    &#x2F;&#x2F;&#x2F; Allow to get a reference to the inner string&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    pub fn&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; as_str&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;&amp;amp;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;font-style: italic;&quot;&gt;self&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; -&amp;gt; &amp;amp;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;str&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;        &amp;amp;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;font-style: italic;&quot;&gt;self&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt;0&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;fn&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; authenticate_user&lt;&#x2F;span&gt;&lt;span&gt;(username&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Username&lt;&#x2F;span&gt;&lt;span&gt;) {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;    &#x2F;&#x2F; We know this is always a valid username!&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;    &#x2F;&#x2F; No empty strings, no emojis, no spaces, etc.&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;(&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;play.rust-lang.org&#x2F;?version=stable&amp;amp;mode=debug&amp;amp;edition=2024&amp;amp;gist=fe47108e246366718d7759eb7abf02f3&quot;&gt;Rust playground&lt;&#x2F;a&gt;)&lt;&#x2F;p&gt;
&lt;h2 id=&quot;make-invalid-states-unrepresentable&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#make-invalid-states-unrepresentable&quot; aria-label=&quot;Anchor link for: make-invalid-states-unrepresentable&quot;&gt;Make Invalid States Unrepresentable&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;p&gt;Can you spot the bug in the following code?&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;&#x2F;&#x2F; DON&amp;#39;T: Allow invalid combinations&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;struct&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Configuration&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    port&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; u16&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    host&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; String&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    ssl&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; bool&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    ssl_cert&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Option&lt;&#x2F;span&gt;&lt;span&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;String&lt;&#x2F;span&gt;&lt;span&gt;&amp;gt;, &lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;The problem is that you can have &lt;code&gt;ssl&lt;&#x2F;code&gt; set to &lt;code&gt;true&lt;&#x2F;code&gt; but &lt;code&gt;ssl_cert&lt;&#x2F;code&gt; set to &lt;code&gt;None&lt;&#x2F;code&gt;.
That’s an invalid state! If you try to use the SSL connection, you can’t because there’s no certificate.&lt;&#x2F;p&gt;
&lt;p&gt;This issue can be detected at compile-time by using types to enforce valid states.
First, let’s define the possible states for the connection:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;enum&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; ConnectionSecurity&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;    Insecure&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;    &#x2F;&#x2F; We can&amp;#39;t have an SSL connection&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;    &#x2F;&#x2F; without a certificate!&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;    Ssl&lt;&#x2F;span&gt;&lt;span&gt; { cert_path&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; String&lt;&#x2F;span&gt;&lt;span&gt; },&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Now we can’t have an invalid state!
Either we have an SSL connection with a certificate or we don’t have SSL at all.&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;struct&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Configuration&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    port&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; u16&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    host&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; String&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    security&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; ConnectionSecurity&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt; &#x2F;&#x2F; All possible states are valid! &lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;In comparison to the previous section, the bug was caused by an &lt;em&gt;invalid combination of closely related fields&lt;&#x2F;em&gt;.
To prevent that, clearly map out all possible states and transitions between them.
A simple way is to define an enum with optional metadata for each state.&lt;&#x2F;p&gt;
&lt;p&gt;The learning here is that Rust can’t protect you from logic bugs.
If you’re curious to learn more, here is a more in-depth &lt;a href=&quot;&#x2F;blog&#x2F;illegal-state&#x2F;&quot;&gt;blog post on the topic&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;handle-default-values-carefully&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#handle-default-values-carefully&quot; aria-label=&quot;Anchor link for: handle-default-values-carefully&quot;&gt;Handle Default Values Carefully&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;p&gt;It’s quite common to add a blanket &lt;code&gt;Default&lt;&#x2F;code&gt; implementation to your types without thinking twice about it.
But that can lead to unforeseen issues.&lt;&#x2F;p&gt;
&lt;p&gt;For example, here’s a case where the port is set to 0 by default, which is not a valid port number.&lt;sup class=&quot;footnote-reference&quot; id=&quot;fr-port-1&quot;&gt;&lt;a href=&quot;#fn-port&quot;&gt;2&lt;&#x2F;a&gt;&lt;&#x2F;sup&gt;&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;&#x2F;&#x2F; DON&amp;#39;T: Implement `Default` without consideration&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;#[derive(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;Default&lt;&#x2F;span&gt;&lt;span&gt;)]&lt;&#x2F;span&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;  &#x2F;&#x2F; Might create invalid states!&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;struct&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; ServerConfig&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    port&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; u16&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;      &#x2F;&#x2F; Will be 0, which might be unexpected &lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    max_connections&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; usize&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    timeout_seconds&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; u64&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Instead, consider if a default value makes sense for your type.
If there is no sane default, don’t implement &lt;code&gt;Default&lt;&#x2F;code&gt; at all and let the user be explicit.&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;&#x2F;&#x2F; DO: Make Default meaningful or don&amp;#39;t implement it&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;struct&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; ServerConfig&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    port&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Port&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    max_connections&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; NonZeroUsize&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    timeout_seconds&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Duration&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;impl&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; ServerConfig&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    pub fn&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; new&lt;&#x2F;span&gt;&lt;span&gt;(port&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Port&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; -&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;font-style: italic;&quot;&gt; Self&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #BD93F9;font-style: italic;&quot;&gt;        Self&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            port,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            max_connections&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; NonZeroUsize&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;new&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt;100&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;unwrap&lt;&#x2F;span&gt;&lt;span&gt;(),&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            timeout_seconds&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Duration&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;from_secs&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt;30&lt;&#x2F;span&gt;&lt;span&gt;),&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;&lt;h2 id=&quot;implement-debug-safely&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#implement-debug-safely&quot; aria-label=&quot;Anchor link for: implement-debug-safely&quot;&gt;Implement &lt;code&gt;Debug&lt;&#x2F;code&gt; Safely&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;p&gt;A related issue is the &lt;code&gt;Debug&lt;&#x2F;code&gt; trait.
One might assume that &lt;code&gt;Debug&lt;&#x2F;code&gt; is only used for “debugging purposes” and is therefore harmless, but if you blindly derive &lt;code&gt;Debug&lt;&#x2F;code&gt; for all types, you might expose sensitive data.
That’s because &lt;code&gt;Debug&lt;&#x2F;code&gt; is often used in logging and error messages, even in production code.
Instead, implement &lt;code&gt;Debug&lt;&#x2F;code&gt; manually for types that contain sensitive information.&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;&#x2F;&#x2F; This would expose sensitive data in logs!&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;#[derive(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;Debug&lt;&#x2F;span&gt;&lt;span&gt;)]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;struct&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; User&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    username&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; String&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    password&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; String&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;  &#x2F;&#x2F; Will be printed as plain text!&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Instead, you could write:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;#[derive(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;Debug&lt;&#x2F;span&gt;&lt;span&gt;)]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;struct&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; User&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    username&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; String&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    password&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Password&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;struct&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Password&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;String&lt;&#x2F;span&gt;&lt;span&gt;);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;&#x2F;&#x2F; Here we implement Debug manually to redact the password&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;impl&lt;&#x2F;span&gt;&lt;span&gt; std&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span&gt;fmt&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;Debug&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; for&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Password&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    fn&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; fmt&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;&amp;amp;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;font-style: italic;&quot;&gt;self&lt;&#x2F;span&gt;&lt;span&gt;, f&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;: &amp;amp;mut&lt;&#x2F;span&gt;&lt;span&gt; std&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span&gt;fmt&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;Formatter&lt;&#x2F;span&gt;&lt;span&gt;&amp;lt;&amp;#39;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;_&lt;&#x2F;span&gt;&lt;span&gt;&amp;gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; -&amp;gt;&lt;&#x2F;span&gt;&lt;span&gt; std&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span&gt;fmt&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;Result&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        f&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;write_str&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt;&amp;quot;[REDACTED]&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Let’s say we were to print a &lt;code&gt;User&lt;&#x2F;code&gt; instance:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;let&lt;&#x2F;span&gt;&lt;span&gt; user&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; User&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    username&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; String&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;from&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt;&amp;quot;ferris&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;),&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    password&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; Password&lt;&#x2F;span&gt;&lt;span&gt;(String&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;from&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt;&amp;quot;supersecret&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;)),&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;};&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;println!&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt;&amp;quot;{user:#?}&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;The output would be:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;User&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    username&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt; &amp;quot;ferris&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    password&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span&gt; [&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt;REDACTED&lt;&#x2F;span&gt;&lt;span&gt;],&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;(&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;play.rust-lang.org&#x2F;?version=stable&amp;amp;mode=debug&amp;amp;edition=2024&amp;amp;gist=8fd18d9e13f60193bc14e97ea258707e&quot;&gt;Rust playground&lt;&#x2F;a&gt;)&lt;&#x2F;p&gt;
&lt;p&gt;For production code, use a crate like &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;crates.io&#x2F;crates&#x2F;secrecy&quot;&gt;&lt;code&gt;secrecy&lt;&#x2F;code&gt;&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;However, it’s not black and white either:
If you implement &lt;code&gt;Debug&lt;&#x2F;code&gt; manually, you might forget to update the implementation when your struct changes.
A common pattern is to destructure the struct in the &lt;code&gt;Debug&lt;&#x2F;code&gt; implementation to catch such errors.&lt;&#x2F;p&gt;
&lt;p&gt;Instead of this:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;&#x2F;&#x2F; don&amp;#39;t&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;impl&lt;&#x2F;span&gt;&lt;span&gt; std&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span&gt;fmt&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;Debug&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; for&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; DatabaseURI&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    fn&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; fmt&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;&amp;amp;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;font-style: italic;&quot;&gt;self&lt;&#x2F;span&gt;&lt;span&gt;, f&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;: &amp;amp;mut&lt;&#x2F;span&gt;&lt;span&gt; std&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span&gt;fmt&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;Formatter&lt;&#x2F;span&gt;&lt;span&gt;&amp;lt;&amp;#39;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;_&lt;&#x2F;span&gt;&lt;span&gt;&amp;gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; -&amp;gt;&lt;&#x2F;span&gt;&lt;span&gt; std&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span&gt;fmt&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;Result&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;        write!&lt;&#x2F;span&gt;&lt;span&gt;(f,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt; &amp;quot;{}:&#x2F;&#x2F;{}:[REDACTED]@{}&#x2F;{}&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;font-style: italic;&quot;&gt; self&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span&gt;scheme,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;font-style: italic;&quot;&gt; self&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span&gt;user,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;font-style: italic;&quot;&gt; self&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span&gt;host,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;font-style: italic;&quot;&gt; self&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span&gt;database)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;How about destructuring the struct to catch changes?&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;&#x2F;&#x2F; do&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;impl&lt;&#x2F;span&gt;&lt;span&gt; std&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span&gt;fmt&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;Debug&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; for&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; DatabaseURI&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    fn&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; fmt&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;&amp;amp;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;font-style: italic;&quot;&gt;self&lt;&#x2F;span&gt;&lt;span&gt;, f&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;: &amp;amp;mut&lt;&#x2F;span&gt;&lt;span&gt; std&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span&gt;fmt&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;Formatter&lt;&#x2F;span&gt;&lt;span&gt;&amp;lt;&amp;#39;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;_&lt;&#x2F;span&gt;&lt;span&gt;&amp;gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; -&amp;gt;&lt;&#x2F;span&gt;&lt;span&gt; std&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span&gt;fmt&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;Result&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;       &#x2F;&#x2F; Destructure the struct to catch changes&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;       &#x2F;&#x2F; This way, the compiler will warn you if you add a new field&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;       &#x2F;&#x2F; and forget to update the Debug implementation&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;        let&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; DatabaseURI&lt;&#x2F;span&gt;&lt;span&gt; { scheme, user, password&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span&gt; _, host, database, }&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;font-style: italic;&quot;&gt; self&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;        write!&lt;&#x2F;span&gt;&lt;span&gt;(f,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt; &amp;quot;{scheme}:&#x2F;&#x2F;{user}:[REDACTED]@{host}&#x2F;{database}&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;?&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;        &#x2F;&#x2F; -- or --&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;        &#x2F;&#x2F; f.debug_struct(&amp;quot;DatabaseURI&amp;quot;)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;        &#x2F;&#x2F;     .field(&amp;quot;scheme&amp;quot;, scheme)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;        &#x2F;&#x2F;     .field(&amp;quot;user&amp;quot;, user)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;        &#x2F;&#x2F;     .field(&amp;quot;password&amp;quot;, &amp;amp;&amp;quot;***&amp;quot;)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;        &#x2F;&#x2F;     .field(&amp;quot;host&amp;quot;, host)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;        &#x2F;&#x2F;     .field(&amp;quot;database&amp;quot;, database)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;        &#x2F;&#x2F;     .finish()&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;        Ok&lt;&#x2F;span&gt;&lt;span&gt;(())&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;(&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;play.rust-lang.org&#x2F;?version=stable&amp;amp;mode=debug&amp;amp;edition=2024&amp;amp;gist=a2facbaa5290f9518072ac214df370aa&quot;&gt;Rust playground&lt;&#x2F;a&gt;)&lt;&#x2F;p&gt;
&lt;p&gt;Thanks to &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.wezm.net&quot;&gt;Wesley Moore (wezm)&lt;&#x2F;a&gt; for the hint and to &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;M3t0r&quot;&gt;Simon Brüggen (m3t0r)&lt;&#x2F;a&gt; for the example.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;careful-with-serialization&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#careful-with-serialization&quot; aria-label=&quot;Anchor link for: careful-with-serialization&quot;&gt;Careful With Serialization&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;p&gt;Don’t blindly derive &lt;code&gt;Serialize&lt;&#x2F;code&gt; and &lt;code&gt;Deserialize&lt;&#x2F;code&gt; either, especially for sensitive data.
The values you read&#x2F;write might not be what you expect!&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;#[derive(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;Serialize&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Deserialize&lt;&#x2F;span&gt;&lt;span&gt;)]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;struct&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; UserCredentials&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    #[serde(default)]&lt;&#x2F;span&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;  &#x2F;&#x2F; ⚠️ Accepts empty strings when deserializing!&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    username&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; String&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    #[serde(default)]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    password&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; String&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt; &#x2F;&#x2F; ⚠️ Leaks the password when serialized!&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;When deserializing, the fields might be empty.
Empty credentials could potentially pass validation checks if not properly handled.&lt;&#x2F;p&gt;
&lt;p&gt;On top of that, the serialization behavior could also leak sensitive data.
By default, &lt;code&gt;Serialize&lt;&#x2F;code&gt; will include the password field in the serialized output, which could expose sensitive credentials in logs, API responses, or debug output.&lt;&#x2F;p&gt;
&lt;p&gt;A common fix is to implement your own custom serialization and deserialization methods by using &lt;code&gt;impl&amp;lt;&#x27;de&amp;gt; Deserialize&amp;lt;&#x27;de&amp;gt; for UserCredentials&lt;&#x2F;code&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;The advantage is that you have full control over input validation.
However, the disadvantage is that you need to implement all the logic yourself.&lt;&#x2F;p&gt;
&lt;p&gt;An alternative strategy is to use the &lt;code&gt;#[serde(try_from = &quot;FromType&quot;)]&lt;&#x2F;code&gt; attribute.&lt;&#x2F;p&gt;
&lt;p&gt;Let’s take the &lt;code&gt;Password&lt;&#x2F;code&gt; field as an example.
Start by using the newtype pattern to wrap the standard types and add custom validation:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;#[derive(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;Deserialize&lt;&#x2F;span&gt;&lt;span&gt;)]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;&#x2F;&#x2F; Tell serde to call `Password::try_from` with a `String`&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;#[serde(try_from &lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;=&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt; &amp;quot;String&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;)]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;pub struct&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Password&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;String&lt;&#x2F;span&gt;&lt;span&gt;);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Now implement &lt;code&gt;TryFrom&lt;&#x2F;code&gt; for &lt;code&gt;Password&lt;&#x2F;code&gt;:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;impl&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; TryFrom&lt;&#x2F;span&gt;&lt;span&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;String&lt;&#x2F;span&gt;&lt;span&gt;&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; for&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Password&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    type&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Error&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; PasswordError&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;    &#x2F;&#x2F;&#x2F; Create a new password&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;    &#x2F;&#x2F;&#x2F;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;    &#x2F;&#x2F;&#x2F; Throws an error if the password is too short.&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;    &#x2F;&#x2F;&#x2F; You can add more checks here.&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    fn&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; try_from&lt;&#x2F;span&gt;&lt;span&gt;(value&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; String&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; -&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Result&lt;&#x2F;span&gt;&lt;span&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;font-style: italic;&quot;&gt;Self&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;font-style: italic;&quot;&gt; Self&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;Error&lt;&#x2F;span&gt;&lt;span&gt;&amp;gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;        &#x2F;&#x2F; Validate the password&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;        if&lt;&#x2F;span&gt;&lt;span&gt; value&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;len&lt;&#x2F;span&gt;&lt;span&gt;() &amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt; 8&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;            return&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Err&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;PasswordError&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;TooShort&lt;&#x2F;span&gt;&lt;span&gt;);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;        Ok&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;Password&lt;&#x2F;span&gt;&lt;span&gt;(value))&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;With this trick, you can no longer deserialize invalid passwords:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;&#x2F;&#x2F; Panic: password too short!&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;let&lt;&#x2F;span&gt;&lt;span&gt; password&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Password&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; serde_json&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;from_str&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt;r#&amp;quot;&amp;quot;pass&amp;quot;&amp;quot;#&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;unwrap&lt;&#x2F;span&gt;&lt;span&gt;();&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;(Try it on the &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;play.rust-lang.org&#x2F;?version=stable&amp;amp;mode=debug&amp;amp;edition=2021&amp;amp;gist=ba0f1a45d5ac982b00a5b5f68a1a0d9e&quot;&gt;Rust Playground&lt;&#x2F;a&gt;)&lt;&#x2F;p&gt;
&lt;p&gt;Credits go to &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;dev.to&#x2F;equalma&#x2F;validate-fields-and-types-in-serde-with-tryfrom-c2n&quot;&gt;EqualMa’s article on dev.to&lt;&#x2F;a&gt; and to &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;durka&quot;&gt;Alex Burka (durka)&lt;&#x2F;a&gt; for the hint.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;protect-against-time-of-check-to-time-of-use-toctou&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#protect-against-time-of-check-to-time-of-use-toctou&quot; aria-label=&quot;Anchor link for: protect-against-time-of-check-to-time-of-use-toctou&quot;&gt;Protect Against Time-of-Check to Time-of-Use (TOCTOU)&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;p&gt;This is a more advanced topic, but it’s important to be aware of it.
TOCTOU (time-of-check to time-of-use) is a class of software bugs caused by changes that happen between when you check a condition and when you use a resource.&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;&#x2F;&#x2F; DON&amp;#39;T: Vulnerable approach with separate check and use&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;fn&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; remove_dir&lt;&#x2F;span&gt;&lt;span&gt;(path&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;: &amp;amp;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;Path&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; -&amp;gt;&lt;&#x2F;span&gt;&lt;span&gt; io&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;Result&lt;&#x2F;span&gt;&lt;span&gt;&amp;lt;()&amp;gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;    &#x2F;&#x2F; First check if it&amp;#39;s a directory&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    if !&lt;&#x2F;span&gt;&lt;span&gt;path&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;is_dir&lt;&#x2F;span&gt;&lt;span&gt;() {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;        return&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Err&lt;&#x2F;span&gt;&lt;span&gt;(io&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;Error&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;new&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            io&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span&gt;ErrorKind&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;NotADirectory&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt;            &amp;quot;not a directory&amp;quot;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        ));&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;    &#x2F;&#x2F; TOCTOU vulnerability: Between the check above and the use below,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;    &#x2F;&#x2F; the path could be replaced with a symlink to a directory we shouldn&amp;#39;t access!&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;    remove_dir_impl&lt;&#x2F;span&gt;&lt;span&gt;(path)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;(&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;play.rust-lang.org&#x2F;?version=stable&amp;amp;mode=debug&amp;amp;edition=2024&amp;amp;gist=fb208eb58e49ce70bde77a48b9b102d1&quot;&gt;Rust playground&lt;&#x2F;a&gt;)&lt;&#x2F;p&gt;
&lt;p&gt;The safer approach opens the directory first, ensuring we operate on what we checked:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;&#x2F;&#x2F; DO: Safer approach that opens first, then checks&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;fn&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; remove_dir&lt;&#x2F;span&gt;&lt;span&gt;(path&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;: &amp;amp;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;Path&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; -&amp;gt;&lt;&#x2F;span&gt;&lt;span&gt; io&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;Result&lt;&#x2F;span&gt;&lt;span&gt;&amp;lt;()&amp;gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;    &#x2F;&#x2F; Open the directory WITHOUT following symlinks&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    let&lt;&#x2F;span&gt;&lt;span&gt; handle&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; OpenOptions&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;new&lt;&#x2F;span&gt;&lt;span&gt;()&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;        .&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;read&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt;true&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;        &#x2F;&#x2F; Fails if not a directory or is a symlink&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;        .&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;custom_flags&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;O_NOFOLLOW&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; |&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; O_DIRECTORY&lt;&#x2F;span&gt;&lt;span&gt;) &lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;        .&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;open&lt;&#x2F;span&gt;&lt;span&gt;(path)&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;?&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;    &#x2F;&#x2F; We can now safely remove the directory contents using the open handle&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;    remove_dir_impl&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;&amp;amp;&lt;&#x2F;span&gt;&lt;span&gt;handle)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;(&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;play.rust-lang.org&#x2F;?version=stable&amp;amp;mode=debug&amp;amp;edition=2024&amp;amp;gist=08a3a0a030a1878171e7eb76adb6ffb8&quot;&gt;Rust playground&lt;&#x2F;a&gt;)&lt;&#x2F;p&gt;
&lt;p&gt;Here’s why it’s safer:
while we hold the handle, the directory can’t be replaced with a symlink.
This way, the directory we’re working with is the same as the one we checked.
Any attempt to replace it won’t affect us because the handle is already open.&lt;&#x2F;p&gt;
&lt;p&gt;You’d be forgiven if you overlooked this issue before.
In fact, even the Rust core team missed it in the standard library.
What you saw is a simplified version of an actual bug in the &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;doc.rust-lang.org&#x2F;std&#x2F;fs&#x2F;fn.remove_dir_all.html&quot;&gt;&lt;code&gt;std::fs::remove_dir_all&lt;&#x2F;code&gt;&lt;&#x2F;a&gt; function.
Read more about it in &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;blog.rust-lang.org&#x2F;2022&#x2F;01&#x2F;20&#x2F;cve-2022-21658.html&quot;&gt;this blog post about CVE-2022-21658&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;use-constant-time-comparison-for-sensitive-data&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#use-constant-time-comparison-for-sensitive-data&quot; aria-label=&quot;Anchor link for: use-constant-time-comparison-for-sensitive-data&quot;&gt;Use Constant-Time Comparison for Sensitive Data&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;p&gt;Timing attacks are a nifty way to extract information from your application.
The idea is that the time it takes to compare two values can leak information about them.
For example, the time it takes to compare two strings can reveal how many characters are correct.
Therefore, for production code, be careful with regular equality checks when handling sensitive data like passwords.&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;&#x2F;&#x2F; DON&amp;#39;T: Use regular equality for sensitive comparisons&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;fn&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; verify_password&lt;&#x2F;span&gt;&lt;span&gt;(stored&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;: &amp;amp;&lt;&#x2F;span&gt;&lt;span&gt;[&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;u8&lt;&#x2F;span&gt;&lt;span&gt;], provided&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;: &amp;amp;&lt;&#x2F;span&gt;&lt;span&gt;[&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;u8&lt;&#x2F;span&gt;&lt;span&gt;])&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; -&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; bool&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    stored&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; ==&lt;&#x2F;span&gt;&lt;span&gt; provided&lt;&#x2F;span&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;  &#x2F;&#x2F; Vulnerable to timing attacks!&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;&#x2F;&#x2F; DO: Use constant-time comparison&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;use&lt;&#x2F;span&gt;&lt;span&gt; subtle&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span&gt;{&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;ConstantTimeEq&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Choice&lt;&#x2F;span&gt;&lt;span&gt;};&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;fn&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; verify_password&lt;&#x2F;span&gt;&lt;span&gt;(stored&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;: &amp;amp;&lt;&#x2F;span&gt;&lt;span&gt;[&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;u8&lt;&#x2F;span&gt;&lt;span&gt;], provided&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;: &amp;amp;&lt;&#x2F;span&gt;&lt;span&gt;[&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;u8&lt;&#x2F;span&gt;&lt;span&gt;])&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; -&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; bool&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    stored&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;ct_eq&lt;&#x2F;span&gt;&lt;span&gt;(provided)&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;unwrap_u8&lt;&#x2F;span&gt;&lt;span&gt;()&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; ==&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt; 1&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;&lt;h2 id=&quot;don-t-accept-unbounded-input&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#don-t-accept-unbounded-input&quot; aria-label=&quot;Anchor link for: don-t-accept-unbounded-input&quot;&gt;Don’t Accept Unbounded Input&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;p&gt;Protect Against Denial-of-Service Attacks with Resource Limits.
These happen when you accept unbounded input, e.g. a huge request body
which might not fit into memory.&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;&#x2F;&#x2F; DON&amp;#39;T: Accept unbounded input&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;fn&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; process_request&lt;&#x2F;span&gt;&lt;span&gt;(data&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;: &amp;amp;&lt;&#x2F;span&gt;&lt;span&gt;[&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;u8&lt;&#x2F;span&gt;&lt;span&gt;])&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; -&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Result&lt;&#x2F;span&gt;&lt;span&gt;&amp;lt;(),&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Error&lt;&#x2F;span&gt;&lt;span&gt;&amp;gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    let&lt;&#x2F;span&gt;&lt;span&gt; decoded&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; decode_data&lt;&#x2F;span&gt;&lt;span&gt;(data)&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;?&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;  &#x2F;&#x2F; Could be enormous!&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;    &#x2F;&#x2F; Process decoded data&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;    Ok&lt;&#x2F;span&gt;&lt;span&gt;(())&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Instead, set explicit limits for your accepted payloads:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;const&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt; MAX_REQUEST_SIZE&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; usize&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt; 1024&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; *&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt; 1024&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;  &#x2F;&#x2F; 1MiB&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;fn&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; process_request&lt;&#x2F;span&gt;&lt;span&gt;(data&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;: &amp;amp;&lt;&#x2F;span&gt;&lt;span&gt;[&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;u8&lt;&#x2F;span&gt;&lt;span&gt;])&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; -&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Result&lt;&#x2F;span&gt;&lt;span&gt;&amp;lt;(),&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Error&lt;&#x2F;span&gt;&lt;span&gt;&amp;gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    if&lt;&#x2F;span&gt;&lt;span&gt; data&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;len&lt;&#x2F;span&gt;&lt;span&gt;() &amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt; MAX_REQUEST_SIZE&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;        return&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Err&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;Error&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;RequestTooLarge&lt;&#x2F;span&gt;&lt;span&gt;);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    let&lt;&#x2F;span&gt;&lt;span&gt; decoded&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; decode_data&lt;&#x2F;span&gt;&lt;span&gt;(data)&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;?&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;    &#x2F;&#x2F; Process decoded data&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;    Ok&lt;&#x2F;span&gt;&lt;span&gt;(())&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;&lt;h2 id=&quot;surprising-behavior-of-path-join-with-absolute-paths&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#surprising-behavior-of-path-join-with-absolute-paths&quot; aria-label=&quot;Anchor link for: surprising-behavior-of-path-join-with-absolute-paths&quot;&gt;Surprising Behavior of &lt;code&gt;Path::join&lt;&#x2F;code&gt; With Absolute Paths&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;p&gt;If you use &lt;code&gt;Path::join&lt;&#x2F;code&gt; to join a relative path with an absolute path, it will silently replace the relative path with the absolute path.&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;use&lt;&#x2F;span&gt;&lt;span&gt; std&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span&gt;path&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;Path&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;fn&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; main&lt;&#x2F;span&gt;&lt;span&gt;() {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    let&lt;&#x2F;span&gt;&lt;span&gt; path&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Path&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;new&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt;&amp;quot;&#x2F;usr&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;join&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt;&amp;quot;&#x2F;local&#x2F;bin&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;    println!&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt;&amp;quot;{path:?}&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;);&lt;&#x2F;span&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt; &#x2F;&#x2F; Prints &amp;quot;&#x2F;local&#x2F;bin&amp;quot; &lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;This is because &lt;code&gt;Path::join&lt;&#x2F;code&gt; will return the second path if it is absolute.&lt;&#x2F;p&gt;
&lt;p&gt;I was not the only one who was confused by this behavior.
Here’s a &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;users.rust-lang.org&#x2F;t&#x2F;rationale-behind-replacing-paths-while-joining&#x2F;104288&quot;&gt;thread on the topic&lt;&#x2F;a&gt;, which also includes an answer by &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;users.rust-lang.org&#x2F;u&#x2F;jdahlstrom&#x2F;summary&quot;&gt;Johannes Dahlström&lt;&#x2F;a&gt;:&lt;&#x2F;p&gt;
&lt;blockquote&gt;
&lt;p&gt;The behavior is useful because a caller […] can choose whether it wants to
use a relative or absolute path, and the callee can then simply absolutize it by
adding its own prefix and the absolute path is unaffected which is probably what
the caller wanted. The callee doesn’t have to separately check whether the path
is absolute or not.&lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
&lt;p&gt;And yet, I still think it’s a footgun.
It’s easy to overlook this behavior when you use user-provided paths.
Perhaps &lt;code&gt;join&lt;&#x2F;code&gt; should return a &lt;code&gt;Result&lt;&#x2F;code&gt; instead?
In any case, be aware of this behavior.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;check-for-unsafe-code-in-your-dependencies-with-cargo-geiger&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#check-for-unsafe-code-in-your-dependencies-with-cargo-geiger&quot; aria-label=&quot;Anchor link for: check-for-unsafe-code-in-your-dependencies-with-cargo-geiger&quot;&gt;Check For Unsafe Code In Your Dependencies With &lt;code&gt;cargo-geiger&lt;&#x2F;code&gt;&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;p&gt;So far, we’ve only covered issues with your own code.
For production code, you also need to check your dependencies.
Especially unsafe code would be a concern.
This can be quite challenging, especially if you have a lot of dependencies.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;geiger-rs&#x2F;cargo-geiger&quot;&gt;cargo-geiger&lt;&#x2F;a&gt; is a neat tool that checks your dependencies for unsafe code.
It can help you identify potential security risks in your project.&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;shellscript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;cargo&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt; install cargo-geiger&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;cargo&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt; geiger&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;This will give you a report of how many unsafe functions are in your dependencies.
Based on this, you can decide if you want to keep a dependency or not.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;clippy-can-prevent-many-of-these-issues&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#clippy-can-prevent-many-of-these-issues&quot; aria-label=&quot;Anchor link for: clippy-can-prevent-many-of-these-issues&quot;&gt;Clippy Can Prevent Many Of These Issues&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;p&gt;Here is a set of clippy lints that can help you catch these issues at compile time.
See for yourself in the &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;play.rust-lang.org&#x2F;?version=stable&amp;amp;mode=debug&amp;amp;edition=2024&amp;amp;gist=26fffd0b9c89822295c4225182238c8c&quot;&gt;Rust playground&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;Here’s the gist:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;cargo check&lt;&#x2F;code&gt; will &lt;strong&gt;not&lt;&#x2F;strong&gt; report any issues.&lt;&#x2F;li&gt;
&lt;li&gt;&lt;code&gt;cargo run&lt;&#x2F;code&gt; will &lt;strong&gt;panic&lt;&#x2F;strong&gt; or silently fail at runtime.&lt;&#x2F;li&gt;
&lt;li&gt;&lt;code&gt;cargo clippy&lt;&#x2F;code&gt; will &lt;strong&gt;catch&lt;&#x2F;strong&gt; all issues at &lt;em&gt;compile time&lt;&#x2F;em&gt; (!) 😎&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;&#x2F;&#x2F; Arithmetic&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;#![deny(arithmetic_overflow)]&lt;&#x2F;span&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt; &#x2F;&#x2F; Prevent operations that would cause integer overflow&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;#![deny(clippy&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span&gt;checked_conversions)]&lt;&#x2F;span&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt; &#x2F;&#x2F; Suggest using checked conversions between numeric types&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;#![deny(clippy&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span&gt;cast_possible_truncation)]&lt;&#x2F;span&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt; &#x2F;&#x2F; Detect when casting might truncate a value&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;#![deny(clippy&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span&gt;cast_sign_loss)]&lt;&#x2F;span&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt; &#x2F;&#x2F; Detect when casting might lose sign information&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;#![deny(clippy&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span&gt;cast_possible_wrap)]&lt;&#x2F;span&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt; &#x2F;&#x2F; Detect when casting might cause value to wrap around&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;#![deny(clippy&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span&gt;cast_precision_loss)]&lt;&#x2F;span&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt; &#x2F;&#x2F; Detect when casting might lose precision&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;#![deny(clippy&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span&gt;integer_division)]&lt;&#x2F;span&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt; &#x2F;&#x2F; Highlight potential bugs from integer division truncation&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;#![deny(clippy&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span&gt;arithmetic_side_effects)]&lt;&#x2F;span&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt; &#x2F;&#x2F; Detect arithmetic operations with potential side effects&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;#![deny(clippy&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span&gt;unchecked_duration_subtraction)]&lt;&#x2F;span&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt; &#x2F;&#x2F; Ensure duration subtraction won&amp;#39;t cause underflow&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;&#x2F;&#x2F; Unwraps&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;#![warn(clippy&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span&gt;unwrap_used)]&lt;&#x2F;span&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt; &#x2F;&#x2F; Discourage using .unwrap() which can cause panics&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;#![warn(clippy&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span&gt;expect_used)]&lt;&#x2F;span&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt; &#x2F;&#x2F; Discourage using .expect() which can cause panics&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;#![deny(clippy&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span&gt;panicking_unwrap)]&lt;&#x2F;span&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt; &#x2F;&#x2F; Prevent unwrap on values known to cause panics&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;#![deny(clippy&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span&gt;option_env_unwrap)]&lt;&#x2F;span&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt; &#x2F;&#x2F; Prevent unwrapping environment variables which might be absent&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;&#x2F;&#x2F; Array indexing&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;#![deny(clippy&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span&gt;indexing_slicing)]&lt;&#x2F;span&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt; &#x2F;&#x2F; Avoid direct array indexing and use safer methods like .get()&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;&#x2F;&#x2F; Path handling&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;#![deny(clippy&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span&gt;join_absolute_paths)]&lt;&#x2F;span&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt; &#x2F;&#x2F; Prevent issues when joining paths with absolute paths&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;&#x2F;&#x2F; Serialization issues&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;#![deny(clippy&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span&gt;serde_api_misuse)]&lt;&#x2F;span&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt; &#x2F;&#x2F; Prevent incorrect usage of Serde&amp;#39;s serialization&#x2F;deserialization API&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;&#x2F;&#x2F; Unbounded input&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;#![deny(clippy&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span&gt;uninit_vec)]&lt;&#x2F;span&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt; &#x2F;&#x2F; Prevent creating uninitialized vectors which is unsafe&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;&#x2F;&#x2F; Unsafe code detection&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;#![deny(clippy&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span&gt;transmute_int_to_char)]&lt;&#x2F;span&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt; &#x2F;&#x2F; Prevent unsafe transmutation from integers to characters&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;#![deny(clippy&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span&gt;transmute_int_to_float)]&lt;&#x2F;span&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt; &#x2F;&#x2F; Prevent unsafe transmutation from integers to floats&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;#![deny(clippy&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span&gt;transmute_ptr_to_ref)]&lt;&#x2F;span&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt; &#x2F;&#x2F; Prevent unsafe transmutation from pointers to references&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;#![deny(clippy&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span&gt;transmute_undefined_repr)]&lt;&#x2F;span&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt; &#x2F;&#x2F; Detect transmutes with potentially undefined representations&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;use&lt;&#x2F;span&gt;&lt;span&gt; std&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span&gt;path&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;Path&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;use&lt;&#x2F;span&gt;&lt;span&gt; std&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span&gt;time&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;Duration&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;fn&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; main&lt;&#x2F;span&gt;&lt;span&gt;() {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;    &#x2F;&#x2F; ARITHMETIC ISSUES&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;    &#x2F;&#x2F; Integer overflow: This would panic in debug mode and silently wrap in release&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    let&lt;&#x2F;span&gt;&lt;span&gt; a&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; u8&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt; 255&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    let&lt;&#x2F;span&gt;&lt;span&gt; _b&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; a&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; +&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt; 1&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;    &#x2F;&#x2F; Unsafe casting: Could truncate the value&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    let&lt;&#x2F;span&gt;&lt;span&gt; large_number&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; i64&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt; 1_000_000_000_000&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    let&lt;&#x2F;span&gt;&lt;span&gt; _small_number&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; i32&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; large_number&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; as&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; i32&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;    &#x2F;&#x2F; Sign loss when casting&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    let&lt;&#x2F;span&gt;&lt;span&gt; negative&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; i32&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; = -&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt;5&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    let&lt;&#x2F;span&gt;&lt;span&gt; _unsigned&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; u32&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; negative&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; as&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; u32&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;    &#x2F;&#x2F; Integer division can truncate results&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    let&lt;&#x2F;span&gt;&lt;span&gt; _result&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt; 5&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; &#x2F;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt; 2&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt; &#x2F;&#x2F; Results in 2, not 2.5&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;    &#x2F;&#x2F; Duration subtraction can underflow&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    let&lt;&#x2F;span&gt;&lt;span&gt; short&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Duration&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;from_secs&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt;1&lt;&#x2F;span&gt;&lt;span&gt;);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    let&lt;&#x2F;span&gt;&lt;span&gt; long&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Duration&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;from_secs&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt;2&lt;&#x2F;span&gt;&lt;span&gt;);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    let&lt;&#x2F;span&gt;&lt;span&gt; _negative&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; short&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; -&lt;&#x2F;span&gt;&lt;span&gt; long;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt; &#x2F;&#x2F; This would underflow&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;    &#x2F;&#x2F; UNWRAP ISSUES&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;    &#x2F;&#x2F; Using unwrap on Option that could be None&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    let&lt;&#x2F;span&gt;&lt;span&gt; data&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Option&lt;&#x2F;span&gt;&lt;span&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;i32&lt;&#x2F;span&gt;&lt;span&gt;&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; None&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    let&lt;&#x2F;span&gt;&lt;span&gt; _value&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; data&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;unwrap&lt;&#x2F;span&gt;&lt;span&gt;();&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;    &#x2F;&#x2F; Using expect on Result that could be Err&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    let&lt;&#x2F;span&gt;&lt;span&gt; result&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Result&lt;&#x2F;span&gt;&lt;span&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;i32&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; &amp;amp;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;str&lt;&#x2F;span&gt;&lt;span&gt;&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Err&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt;&amp;quot;error occurred&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    let&lt;&#x2F;span&gt;&lt;span&gt; _value&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; result&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;expect&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt;&amp;quot;This will panic&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;    &#x2F;&#x2F; Trying to get environment variable that might not exist&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    let&lt;&#x2F;span&gt;&lt;span&gt; _api_key&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; std&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span&gt;env&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;var&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt;&amp;quot;API_KEY&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;unwrap&lt;&#x2F;span&gt;&lt;span&gt;();&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;    &#x2F;&#x2F; ARRAY INDEXING ISSUES&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;    &#x2F;&#x2F; Direct indexing without bounds checking&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    let&lt;&#x2F;span&gt;&lt;span&gt; numbers&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; vec!&lt;&#x2F;span&gt;&lt;span&gt;[&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt;1&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt; 2&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt; 3&lt;&#x2F;span&gt;&lt;span&gt;];&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    let&lt;&#x2F;span&gt;&lt;span&gt; _fourth&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; numbers[&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt;3&lt;&#x2F;span&gt;&lt;span&gt;];&lt;&#x2F;span&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt; &#x2F;&#x2F; This would panic&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;    &#x2F;&#x2F; Safe alternative with .get()&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    if let&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Some&lt;&#x2F;span&gt;&lt;span&gt;(fourth)&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; numbers&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;get&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt;3&lt;&#x2F;span&gt;&lt;span&gt;) {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;        println!&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt;&amp;quot;{fourth}&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;    &#x2F;&#x2F; PATH HANDLING ISSUES&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;    &#x2F;&#x2F; Joining with absolute path discards the base path&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    let&lt;&#x2F;span&gt;&lt;span&gt; base&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Path&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;new&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt;&amp;quot;&#x2F;home&#x2F;user&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    let&lt;&#x2F;span&gt;&lt;span&gt; _full_path&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; base&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;join&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt;&amp;quot;&#x2F;etc&#x2F;config&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;);&lt;&#x2F;span&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt; &#x2F;&#x2F; Results in &amp;quot;&#x2F;etc&#x2F;config&amp;quot;, base is ignored&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;    &#x2F;&#x2F; Safe alternative&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    let&lt;&#x2F;span&gt;&lt;span&gt; base&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Path&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;new&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt;&amp;quot;&#x2F;home&#x2F;user&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    let&lt;&#x2F;span&gt;&lt;span&gt; relative&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Path&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;new&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt;&amp;quot;config&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    let&lt;&#x2F;span&gt;&lt;span&gt; full_path&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; base&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;join&lt;&#x2F;span&gt;&lt;span&gt;(relative);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;    println!&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt;&amp;quot;Safe path joining: {:?}&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;, full_path);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;    &#x2F;&#x2F; UNSAFE CODE ISSUES&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;    &#x2F;&#x2F; Creating uninitialized vectors (could cause undefined behavior)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    let mut&lt;&#x2F;span&gt;&lt;span&gt; vec&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Vec&lt;&#x2F;span&gt;&lt;span&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;String&lt;&#x2F;span&gt;&lt;span&gt;&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Vec&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;with_capacity&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt;10&lt;&#x2F;span&gt;&lt;span&gt;);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    unsafe&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        vec&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;set_len&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt;10&lt;&#x2F;span&gt;&lt;span&gt;);&lt;&#x2F;span&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt; &#x2F;&#x2F; This is UB as Strings aren&amp;#39;t initialized&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;&lt;h2 id=&quot;conclusion&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#conclusion&quot; aria-label=&quot;Anchor link for: conclusion&quot;&gt;Conclusion&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;p&gt;Phew, that was a lot of pitfalls!
How many of them did you know about?&lt;&#x2F;p&gt;
&lt;p&gt;Even if Rust is a great language for writing safe, reliable code, developers still need to be disciplined to avoid bugs.&lt;&#x2F;p&gt;
&lt;p&gt;A lot of the common mistakes we saw have to do with Rust being a systems programming language:
In computing systems, a lot of operations are performance critical and inherently unsafe.
We are dealing with external systems outside of our control, such as the operating system, hardware, or the network.
The goal is to build safe abstractions on top of an unsafe world.&lt;&#x2F;p&gt;
&lt;p&gt;Rust shares an FFI interface with C, which means that it can do anything C can do.
So, while some operations that Rust allows are theoretically possible, they might lead to unexpected results.&lt;&#x2F;p&gt;
&lt;p&gt;But not all is lost!
If you are aware of these pitfalls, you can avoid them, and with the above clippy lints, you can catch most of them at compile time.&lt;&#x2F;p&gt;
&lt;p&gt;That’s why testing, linting, and fuzzing are still important in Rust.&lt;&#x2F;p&gt;
&lt;p&gt;For maximum robustness, combine Rust’s safety guarantees with strict checks and
strong verification methods.&lt;&#x2F;p&gt;
&lt;div class=&quot;info&quot;&gt;
  
  &lt;div class=&quot;info-header&quot;&gt;
    
      &lt;span class=&quot;icon icon-crab&quot;&gt;&lt;&#x2F;span&gt;
    
    &lt;h4&gt;&lt;p&gt;Let an Expert Review Your Rust Code&lt;&#x2F;p&gt;
&lt;&#x2F;h4&gt;
  &lt;&#x2F;div&gt;
  
  &lt;p&gt;I hope you found this article helpful!
If you want to take your Rust code to the next level, consider a code review by an expert.
I offer code reviews for Rust projects of all sizes. &lt;a href=&quot;&#x2F;services&#x2F;&quot;&gt;Get in touch&lt;&#x2F;a&gt; to learn more.&lt;&#x2F;p&gt;

&lt;&#x2F;div&gt;
&lt;section class=&quot;footnotes&quot;&gt;
&lt;ol class=&quot;footnotes-list&quot;&gt;
&lt;li id=&quot;fn-intrinsics_docs&quot;&gt;
&lt;p&gt;There’s also methods for wrapping and saturating arithmetic, which might be useful in some cases.
It’s worth it to check out the &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;doc.rust-lang.org&#x2F;std&#x2F;intrinsics&#x2F;index.html&quot;&gt;&lt;code&gt;std::intrinsics&lt;&#x2F;code&gt;&lt;&#x2F;a&gt; documentation to learn more. &lt;a href=&quot;#fr-intrinsics_docs-1&quot;&gt;↩&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;&#x2F;li&gt;
&lt;li id=&quot;fn-port&quot;&gt;
&lt;p&gt;Port 0 usually means that the OS will assign a random port for you.
So, &lt;code&gt;TcpListener::bind(&quot;127.0.0.1:0&quot;).unwrap()&lt;&#x2F;code&gt; is valid, but it might not be supported on all operating systems or it might not be what you expect. See the &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;doc.rust-lang.org&#x2F;std&#x2F;net&#x2F;struct.TcpListener.html#method.bind&quot;&gt;&lt;code&gt;TcpListener::bind&lt;&#x2F;code&gt;&lt;&#x2F;a&gt; docs for more info. &lt;a href=&quot;#fr-port-1&quot;&gt;↩&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;&#x2F;section&gt;
</description>
      </item>
      <item>
          <title>Rust Learning Resources 2026</title>
          <pubDate>Thu, 06 Mar 2025 00:00:00 +0000</pubDate>
          <author>Matthias Endler</author>
          <link>https://corrode.dev/blog/rust-learning-resources-2026/</link>
          <guid>https://corrode.dev/blog/rust-learning-resources-2026/</guid>
          <description xml:base="https://corrode.dev/blog/rust-learning-resources-2026/">&lt;p&gt;Want to finally learn Rust?&lt;&#x2F;p&gt;
&lt;p&gt;When I ask developers what they look for in a Rust learning resource, I tend to get the same answers:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;They want &lt;strong&gt;hands-on&lt;&#x2F;strong&gt; learning experiences&lt;&#x2F;li&gt;
&lt;li&gt;They need content that’s &lt;strong&gt;applicable to their work&lt;&#x2F;strong&gt;&lt;&#x2F;li&gt;
&lt;li&gt;They look for &lt;strong&gt;up-to-date material&lt;&#x2F;strong&gt; from &lt;strong&gt;experienced developers&lt;&#x2F;strong&gt;&lt;&#x2F;li&gt;
&lt;li&gt;They prefer to use &lt;strong&gt;their own development environment&lt;&#x2F;strong&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;All of the above are valid points, especially for learning Rust, a language known for its notoriously &lt;a href=&quot;&#x2F;blog&#x2F;flattening-rusts-learning-curve&quot;&gt;steep learning curve&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;If you’ve been thinking about learning Rust for a while now and perhaps you’ve already started dabbling with it, now’s the time to fully commit. I’ve put together my favorite Rust learning resources for 2026 to help you jumpstart your Rust journey.
I made sure to include a healthy mix of self-paced resources, interactive exercises, and hands-on workshops.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;rustlings&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#rustlings&quot; aria-label=&quot;Anchor link for: rustlings&quot;&gt;Rustlings&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;p&gt;&lt;img src=&quot;https:&#x2F;&#x2F;corrode.dev&#x2F;blog&#x2F;rust-learning-resources-2026&#x2F;.&#x2F;rustlings.png&quot; alt=&quot;Rustlings on the terminal&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;p&gt;Key Points:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Level&lt;&#x2F;strong&gt;: Beginner to Intermediate&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Focus&lt;&#x2F;strong&gt;: Small exercises &#x2F; Rust basics&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Time&lt;&#x2F;strong&gt;: A few minutes to a few hours&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;The classic Rust learning resource. If it was a cocktail, it would be an &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Old_fashioned_(cocktail)&quot;&gt;Old Fashioned&lt;&#x2F;a&gt;. Rustlings works great for beginners and for anyone wanting a quick refresher on specific Rust concepts.&lt;&#x2F;p&gt;
&lt;p&gt;You can run Rustlings from your command line, and it guides you through a series of exercises.
All it takes is running a few commands in your terminal:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;shellscript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;cargo&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt; install rustlings&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;rustlings&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt; init&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #8BE9FD;&quot;&gt;cd&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt; rustlings&#x2F;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;rustlings&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Go to the &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;rust-lang&#x2F;rustlings&quot;&gt;official Rustlings repository&lt;&#x2F;a&gt; to learn more.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;rustfinity&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#rustfinity&quot; aria-label=&quot;Anchor link for: rustfinity&quot;&gt;Rustfinity&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;p&gt;&lt;img src=&quot;https:&#x2F;&#x2F;corrode.dev&#x2F;blog&#x2F;rust-learning-resources-2026&#x2F;.&#x2F;rustfinity.jpg&quot; alt=&quot;Rustfinity Homepage&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;p&gt;Key Points:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Level&lt;&#x2F;strong&gt;: Beginner to Intermediate&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Focus&lt;&#x2F;strong&gt;: Small exercises &#x2F; Rust basics&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Time&lt;&#x2F;strong&gt;: A few minutes to a few hours&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;Rustfinity is a bit like Rustlings, but more modern and structured. It gives you a browser interface that guides you through each exercise and runs tests to check your solutions. No need to set up anything locally, which makes it great for workshops or learning on the go.&lt;&#x2F;p&gt;
&lt;p&gt;You start with “Hello, World!” and work your way up to more complex exercises. It’s a relatively new resource, but I’ve tried several exercises myself and enjoyed the experience.&lt;&#x2F;p&gt;
&lt;p&gt;They also host “Advent of Rust” events with some more challenging problems available &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.rustfinity.com&#x2F;advent-of-rust&quot;&gt;here&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;Learn more at the &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.rustfinity.com&#x2F;&quot;&gt;Rustfinity website&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;100-exercises-to-learn-rust&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#100-exercises-to-learn-rust&quot; aria-label=&quot;Anchor link for: 100-exercises-to-learn-rust&quot;&gt;100 Exercises To Learn Rust&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;p&gt;&lt;img src=&quot;https:&#x2F;&#x2F;corrode.dev&#x2F;blog&#x2F;rust-learning-resources-2026&#x2F;.&#x2F;100-exercises.jpg&quot; alt=&quot;100 Exercises To Learn Rust&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;p&gt;Key Points:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Level&lt;&#x2F;strong&gt;: Beginner to Intermediate&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Focus&lt;&#x2F;strong&gt;: Small exercises &#x2F; Rust basics&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Time&lt;&#x2F;strong&gt;: A few minutes to a few hours&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;This is another relatively new resource by Luca Palmieri, who is the author of the popular &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.zero2prod.com&quot;&gt;“Zero To Production”&lt;&#x2F;a&gt; book.
It’s a collection of 100 exercises that help you learn Rust. The course is based on the “learning by doing” principle and designed to be interactive and hands-on.&lt;&#x2F;p&gt;
&lt;p&gt;You can work through the material in your browser, or download a PDF or buy a printed copy for offline reading. The course comes with a local CLI tool called &lt;code&gt;wr&lt;&#x2F;code&gt; that verifies your solutions.&lt;&#x2F;p&gt;
&lt;p&gt;You can learn more about the course &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;rust-exercises.com&#x2F;100-exercises&#x2F;&quot;&gt;here&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;codecrafters&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#codecrafters&quot; aria-label=&quot;Anchor link for: codecrafters&quot;&gt;CodeCrafters&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;div style=&quot;position: relative; padding-bottom: 56.25%; height: 0; overflow: hidden;&quot;&gt;
  &lt;iframe style=&quot;position: absolute; top: 0; left: 0; width: 100%; height: 100%;&quot; src=&quot;https:&#x2F;&#x2F;www.youtube-nocookie.com&#x2F;embed&#x2F;aZ5sfhGmEVU&quot; title=&quot;YouTube video player&quot; frameborder=&quot;0&quot; allow=&quot;accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share&quot; referrerpolicy=&quot;strict-origin-when-cross-origin&quot; allowfullscreen&gt;&lt;&#x2F;iframe&gt;
&lt;&#x2F;div&gt;
&lt;p&gt;Key Points:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Level&lt;&#x2F;strong&gt;: Intermediate to Advanced&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Focus&lt;&#x2F;strong&gt;: Real-world projects &#x2F; Systems programming&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Time&lt;&#x2F;strong&gt;: A few days to a few weeks per project (depending on your experience)&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;If you already know how to code some Rust and want to take it one step further, CodeCrafters is currently the best resource for learning advanced Rust concepts in your own time.
I like that they focus on real-world systems programming projects, which is where Rust is really strong.&lt;&#x2F;p&gt;
&lt;p&gt;You’ll learn how to build your own shell, HTTP server, Redis, Kafka, Git, SQLite, or DNS server from scratch.&lt;&#x2F;p&gt;
&lt;p&gt;Most people work on the projects on evenings and weekends, and it takes a few days or weeks to complete a challenge,
but the sense of accomplishment when you finish is incredible: you’ll complete a project that teaches you both Rust and the inner workings of systems you use daily.&lt;&#x2F;p&gt;
&lt;p&gt;If you got curious, the video above is my full walkthrough of the “Build your own HTTP server” challenge.&lt;&#x2F;p&gt;
&lt;div class=&quot;info&quot;&gt;
  
  &lt;div class=&quot;info-header&quot;&gt;
    
      &lt;span class=&quot;icon icon-crab&quot;&gt;&lt;&#x2F;span&gt;
    
    &lt;h4&gt;&lt;p&gt;Try CodeCrafters For Free&lt;&#x2F;p&gt;
&lt;&#x2F;h4&gt;
  &lt;&#x2F;div&gt;
  
  &lt;p&gt;CodeCrafters is the platform I genuinely recommend to friends after they’ve learned the basics of Rust.
It’s the next best thing after a personal mentor or workshop.&lt;&#x2F;p&gt;
&lt;p&gt;You can &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;app.codecrafters.io&#x2F;join?via=mre&quot;&gt;try CodeCrafters for free here&lt;&#x2F;a&gt; and get 40% off if you upgrade to a paid plan later. Full disclosure: I receive a commission for new subscriptions, but I would recommend CodeCrafters even if I didn’t.&lt;&#x2F;p&gt;
&lt;p&gt;On top of that, most companies will reimburse educational resources through their L&amp;amp;D budget, so check with your manager about getting reimbursed.&lt;&#x2F;p&gt;

&lt;&#x2F;div&gt;
&lt;h2 id=&quot;workshops&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#workshops&quot; aria-label=&quot;Anchor link for: workshops&quot;&gt;Workshops&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;p&gt;&lt;img src=&quot;https:&#x2F;&#x2F;corrode.dev&#x2F;blog&#x2F;rust-learning-resources-2026&#x2F;.&#x2F;write-yourself-a-shell.jpg&quot; alt=&quot;Write Yourself a Shell Workshop&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;p&gt;Key Points:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Level&lt;&#x2F;strong&gt;: Beginner to Intermediate&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Focus&lt;&#x2F;strong&gt;: Focused exercises and small projects&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Time&lt;&#x2F;strong&gt;: A few days of focused effort&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;I’m biased here, but nothing beats a hands-on workshop with a Rust expert.
Learning from experienced Rust developers is probably the quickest way to get up to speed with Rust
– especially if you plan to use Rust at work.
That’s because trainers can provide you with personalized feedback and guidance, and help you avoid common pitfalls.
It’s like having a personal trainer for your Rust learning journey.&lt;&#x2F;p&gt;
&lt;p&gt;My workshops are designed to be hands-on and tailored to the needs of the participants.
I want people to walk away with a finished project they can extend.&lt;&#x2F;p&gt;
&lt;p&gt;All course material is open source and freely available on GitHub:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;corrode&#x2F;write-yourself-a-cli&quot;&gt;Write Yourself a CLI&lt;&#x2F;a&gt; - Create a tool to find files on your system&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;corrode&#x2F;write-yourself-a-web-app&quot;&gt;Write Yourself a Web App&lt;&#x2F;a&gt; - Build a small web app that shows weather data&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;corrode&#x2F;write-yourself-a-shell&quot;&gt;Write Yourself a Shell&lt;&#x2F;a&gt; - Build a small but fully functional shell from scratch&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;You can go through the material on your own to see if it fits your needs.
Once you’re ready, feel free to reach out about tailoring the content for you and your team.&lt;&#x2F;p&gt;
&lt;div class=&quot;info&quot;&gt;
  
  &lt;div class=&quot;info-header&quot;&gt;
    
      &lt;span class=&quot;icon icon-crab&quot;&gt;&lt;&#x2F;span&gt;
    
    &lt;h4&gt;&lt;p&gt;Speed Up Your Learning Process&lt;&#x2F;p&gt;
&lt;&#x2F;h4&gt;
  &lt;&#x2F;div&gt;
  
  &lt;p&gt;Is your company considering a switch to Rust?&lt;&#x2F;p&gt;
&lt;p&gt;Rust is known for its steep learning curve, but with the right resources and guidance, you can become proficient in a matter of weeks. I offer hands-on workshops and training for teams and individuals who want to accelerate their learning process.&lt;&#x2F;p&gt;
&lt;p&gt;Check out my &lt;a href=&quot;&#x2F;services&quot;&gt;services page&lt;&#x2F;a&gt; or &lt;a href=&quot;mailto:hi@corrode.dev?subject=Rust%20Workshops&quot;&gt;send me an email&lt;&#x2F;a&gt; to learn more.&lt;&#x2F;p&gt;

&lt;&#x2F;div&gt;
</description>
      </item>
      <item>
          <title>Season 3 - Finale</title>
          <pubDate>Thu, 06 Feb 2025 00:00:00 +0000</pubDate>
          <author>Matthias Endler</author>
          <link>https://corrode.dev/podcast/s03e09-season-finale/</link>
          <guid>https://corrode.dev/podcast/s03e09-season-finale/</guid>
          <description xml:base="https://corrode.dev/podcast/s03e09-season-finale/">&lt;div&gt;&lt;script id=&quot;letscast-player-4cc795a6&quot; src=&quot;https:&#x2F;&#x2F;letscast.fm&#x2F;podcasts&#x2F;rust-in-production-82281512&#x2F;episodes&#x2F;season-3-finale&#x2F;player.js?size=s&quot;&gt;&lt;&#x2F;script&gt;&lt;&#x2F;div&gt;
&lt;p&gt;You know the drill by now. It’s time for another recap!&lt;&#x2F;p&gt;
&lt;p&gt;Sit back, get a warm beverage and look back at the highlights of Season 3 with us.&lt;&#x2F;p&gt;
&lt;p&gt;We’ve been at this for a while now (three seasons, one year, and 24 episodes to be exact).
We had guests from a wide range of industries:
from automotive to CAD software, and from developer tooling to systems programming.&lt;&#x2F;p&gt;
&lt;p&gt;Our focus this time around was on the technical details of Rust in production,
especially integration of Rust into existing codebases and ecosystem deep dives.
Thanks to everyone who participated in the survey last season, which helped us dial in our content.
Let us know if we hit the mark or missed it!&lt;&#x2F;p&gt;</description>
      </item>
      <item>
          <title>Tips for Faster Rust CI Builds</title>
          <pubDate>Tue, 28 Jan 2025 00:00:00 +0000</pubDate>
          <author>Matthias Endler</author>
          <link>https://corrode.dev/blog/tips-for-faster-ci-builds/</link>
          <guid>https://corrode.dev/blog/tips-for-faster-ci-builds/</guid>
          <description xml:base="https://corrode.dev/blog/tips-for-faster-ci-builds/">&lt;p&gt;I’ve been working with many clients lately who host their Rust projects on GitHub.
CI is typically a bottleneck in the development process since it can significantly slow down feedback loops.
However, there are several effective ways to speed up your GitHub Actions workflows!&lt;&#x2F;p&gt;
&lt;div class=&quot;info&quot;&gt;
  
  &lt;div class=&quot;info-header&quot;&gt;
    
      &lt;span class=&quot;icon icon-crab&quot;&gt;&lt;&#x2F;span&gt;
    
    &lt;h4&gt;&lt;p&gt;Want a Real-World Example?&lt;&#x2F;p&gt;
&lt;&#x2F;h4&gt;
  &lt;&#x2F;div&gt;
  
  &lt;p&gt;Check out this production-ready GitHub Actions workflow that implements all the tips from this article:
&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;lycheeverse&#x2F;lychee&#x2F;blob&#x2F;master&#x2F;.github&#x2F;workflows&#x2F;ci.yml&quot;&gt;click here&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;Also see Arpad Borsos’ &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;Swatinem&#x2F;rust-gha-workflows&quot;&gt;workflow templates&lt;&#x2F;a&gt; for Rust projects.&lt;&#x2F;p&gt;

&lt;&#x2F;div&gt;
&lt;h2 id=&quot;use-swatinem-s-cache-action&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#use-swatinem-s-cache-action&quot; aria-label=&quot;Anchor link for: use-swatinem-s-cache-action&quot;&gt;Use Swatinem’s cache action&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;p&gt;This is easily my most important recommendation on this list.&lt;&#x2F;p&gt;
&lt;p&gt;My friend &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;swatinem&quot;&gt;Arpad Borsos&lt;&#x2F;a&gt;, also known as Swatinem, has created a cache action specifically tailored for Rust projects.
It’s an excellent way to speed up any Rust CI build and requires no code changes to your project.&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;yaml&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #8BE9FD;&quot;&gt;name&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt; CI&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt;on&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span&gt; &lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #8BE9FD;&quot;&gt;  push&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #8BE9FD;&quot;&gt;    branches&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;      -&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt; main&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #8BE9FD;&quot;&gt;  pull_request&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #8BE9FD;&quot;&gt;jobs&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #8BE9FD;&quot;&gt;  build&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #8BE9FD;&quot;&gt;    runs-on&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt; ubuntu-latest-arm64&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #8BE9FD;&quot;&gt;    env&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #8BE9FD;&quot;&gt;      CARGO_TERM_COLOR&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt; always&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #8BE9FD;&quot;&gt;    steps&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;      -&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;&quot;&gt; uses&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt; actions&#x2F;checkout@v4&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;      -&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;&quot;&gt; uses&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt; dtolnay&#x2F;rust-toolchain@stable&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;      # The secret sauce!&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;      -&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;&quot;&gt; uses&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt; Swatinem&#x2F;rust-cache@v2&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;      -&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;&quot;&gt; run&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;: |&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt;          cargo check&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt;          cargo test&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt;          cargo build --release&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;The action requires no additional configuration and works out of the box.
There’s no need for a separate step to store the cache — this happens automatically through a post-action.
This approach ensures that broken builds aren’t cached, and for subsequent builds, you can save several minutes of build time.&lt;&#x2F;p&gt;
&lt;p&gt;Here’s the &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;Swatinem&#x2F;rust-cache&quot;&gt;documentation&lt;&#x2F;a&gt; where you can learn more.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;use-the-locked-flag&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#use-the-locked-flag&quot; aria-label=&quot;Anchor link for: use-the-locked-flag&quot;&gt;Use the &lt;code&gt;--locked&lt;&#x2F;code&gt; flag&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;p&gt;When running &lt;code&gt;cargo build&lt;&#x2F;code&gt;, &lt;code&gt;cargo test&lt;&#x2F;code&gt;, or &lt;code&gt;cargo check&lt;&#x2F;code&gt;, you can pass the &lt;code&gt;--locked&lt;&#x2F;code&gt; flag to prevent Cargo from updating the &lt;code&gt;Cargo.lock&lt;&#x2F;code&gt; file.&lt;&#x2F;p&gt;
&lt;p&gt;This is particularly useful for CI operations since you save the time to update dependencies.
Typically you want to test the exact dependency versions specified in your lock file anyway.&lt;&#x2F;p&gt;
&lt;p&gt;On top of that, it ensures reproducible builds, which is crucial for CI.
From the &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;doc.rust-lang.org&#x2F;cargo&#x2F;commands&#x2F;cargo-install.html&quot;&gt;Cargo documentation&lt;&#x2F;a&gt;:&lt;&#x2F;p&gt;
&lt;blockquote&gt;
&lt;p&gt;The &lt;code&gt;--locked&lt;&#x2F;code&gt; flag can be used to force Cargo to use the packaged &lt;code&gt;Cargo.lock&lt;&#x2F;code&gt; file if it is available. This may be useful for ensuring reproducible builds, to use the exact same set of dependencies that were available when the package was published.&lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
&lt;p&gt;Here’s how you can use it in your GitHub Actions workflow:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;yaml&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;-&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;&quot;&gt; run&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt; cargo check --locked&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;-&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;&quot;&gt; run&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt; cargo test --locked&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;&lt;h2 id=&quot;use-cargo-chef-for-docker-builds&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#use-cargo-chef-for-docker-builds&quot; aria-label=&quot;Anchor link for: use-cargo-chef-for-docker-builds&quot;&gt;Use &lt;code&gt;cargo-chef&lt;&#x2F;code&gt; For Docker Builds&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;p&gt;For Rust Docker images, &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;LukeMathWalker&#x2F;cargo-chef&quot;&gt;&lt;code&gt;cargo-chef&lt;&#x2F;code&gt;&lt;&#x2F;a&gt; can significantly speed up the build process by leveraging Docker’s layer caching:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;docker&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;FROM&lt;&#x2F;span&gt;&lt;span&gt; lukemathwalker&#x2F;cargo-chef:latest-rust-1 &lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;AS&lt;&#x2F;span&gt;&lt;span&gt; chef&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;WORKDIR&lt;&#x2F;span&gt;&lt;span&gt; &#x2F;app&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;FROM&lt;&#x2F;span&gt;&lt;span&gt; chef &lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;AS&lt;&#x2F;span&gt;&lt;span&gt; planner&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;COPY&lt;&#x2F;span&gt;&lt;span&gt; . .&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;RUN&lt;&#x2F;span&gt;&lt;span&gt; cargo chef prepare --recipe-path recipe.json&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;FROM&lt;&#x2F;span&gt;&lt;span&gt; chef &lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;AS&lt;&#x2F;span&gt;&lt;span&gt; builder &lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;COPY&lt;&#x2F;span&gt;&lt;span&gt; --from=planner &#x2F;app&#x2F;recipe.json recipe.json&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;# Build dependencies - this is the caching Docker layer!&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;RUN&lt;&#x2F;span&gt;&lt;span&gt; cargo chef cook --release --recipe-path recipe.json&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;# Build application&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;COPY&lt;&#x2F;span&gt;&lt;span&gt; . .&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;RUN&lt;&#x2F;span&gt;&lt;span&gt; cargo build --release --bin app&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;# We do not need the Rust toolchain to run the binary!&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;FROM&lt;&#x2F;span&gt;&lt;span&gt; debian:bookworm-slim &lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;AS&lt;&#x2F;span&gt;&lt;span&gt; runtime&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;WORKDIR&lt;&#x2F;span&gt;&lt;span&gt; &#x2F;app&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;COPY&lt;&#x2F;span&gt;&lt;span&gt; --from=builder &#x2F;app&#x2F;target&#x2F;release&#x2F;app &#x2F;usr&#x2F;local&#x2F;bin&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;ENTRYPOINT&lt;&#x2F;span&gt;&lt;span&gt; [&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt;&amp;quot;&#x2F;usr&#x2F;local&#x2F;bin&#x2F;app&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Alternatively, if you don’t mind a little extra typing, you can write your own Dockerfile without &lt;code&gt;cargo-chef&lt;&#x2F;code&gt;:&lt;&#x2F;p&gt;
&lt;details&gt;
&lt;summary&gt;Click to expand&lt;&#x2F;summary&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;docker&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;FROM&lt;&#x2F;span&gt;&lt;span&gt; rust:1.81-slim-bookworm &lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;AS&lt;&#x2F;span&gt;&lt;span&gt; builder&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;WORKDIR&lt;&#x2F;span&gt;&lt;span&gt; &#x2F;usr&#x2F;src&#x2F;app&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;# Copy the Cargo files to cache dependencies&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;COPY&lt;&#x2F;span&gt;&lt;span&gt; Cargo.toml Cargo.lock .&#x2F;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;# Create a dummy main.rs to build dependencies&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;RUN&lt;&#x2F;span&gt;&lt;span&gt; mkdir src &amp;amp;&amp;amp; \&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    echo &lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt;&amp;#39;fn main() { println!(&amp;quot;Dummy&amp;quot;) }&amp;#39;&lt;&#x2F;span&gt;&lt;span&gt; &amp;gt; src&#x2F;main.rs &amp;amp;&amp;amp; \&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    cargo build --release &amp;amp;&amp;amp; \&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    rm src&#x2F;main.rs&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;# Now copy the actual source code&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;COPY&lt;&#x2F;span&gt;&lt;span&gt; src .&#x2F;src&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;# Build for release&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;RUN&lt;&#x2F;span&gt;&lt;span&gt; touch src&#x2F;main.rs &amp;amp;&amp;amp; cargo build --release&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;# Runtime stage&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;FROM&lt;&#x2F;span&gt;&lt;span&gt; debian:bookworm-slim&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;# Install minimal runtime dependencies&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;RUN&lt;&#x2F;span&gt;&lt;span&gt; apt-get update &amp;amp;&amp;amp; apt-get install -y --no-install-recommends ca-certificates &amp;amp;&amp;amp; rm -rf &#x2F;var&#x2F;lib&#x2F;apt&#x2F;lists&#x2F;*&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;# Copy the build artifact from the build stage&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;COPY&lt;&#x2F;span&gt;&lt;span&gt; --from=builder &#x2F;usr&#x2F;src&#x2F;app&#x2F;target&#x2F;release&#x2F;your-app &#x2F;usr&#x2F;local&#x2F;bin&#x2F;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;# Set the startup command to run our binary&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;CMD&lt;&#x2F;span&gt;&lt;span&gt; [&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt;&amp;quot;your-app&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;&lt;&#x2F;details&gt;
&lt;h2 id=&quot;environment-flags-to-disable-incremental-compilation&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#environment-flags-to-disable-incremental-compilation&quot; aria-label=&quot;Anchor link for: environment-flags-to-disable-incremental-compilation&quot;&gt;Environment Flags To Disable Incremental Compilation&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;p&gt;Rust provides environment flags to disable incremental compilation.
While incremental compilation speeds up local development builds, in CI it can actually slow down the process due to dependency tracking overhead and negatively impact caching.
So it’s better to switch it off:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;yaml&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #8BE9FD;&quot;&gt;name&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt; Build&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt;on&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #8BE9FD;&quot;&gt;  pull_request&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #8BE9FD;&quot;&gt;  push&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #8BE9FD;&quot;&gt;    branches&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;      -&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt; main&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #8BE9FD;&quot;&gt;env&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;  # Disable incremental compilation for faster from-scratch builds&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #8BE9FD;&quot;&gt;  CARGO_INCREMENTAL&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt; 0&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #8BE9FD;&quot;&gt;jobs&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #8BE9FD;&quot;&gt;  build&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #8BE9FD;&quot;&gt;    runs-on&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt; ...&lt;&#x2F;span&gt;&lt;span&gt; &lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #8BE9FD;&quot;&gt;    steps&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt;      ...&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;&lt;h2 id=&quot;disable-debug-info&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#disable-debug-info&quot; aria-label=&quot;Anchor link for: disable-debug-info&quot;&gt;Disable Debug Info&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;p&gt;While debug info is valuable for debugging, it significantly increases the size of the &lt;code&gt;.&#x2F;target&lt;&#x2F;code&gt; directory, which can harm caching efficiency.
It’s easy to switch off:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;yaml&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #8BE9FD;&quot;&gt;env&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #8BE9FD;&quot;&gt;  CARGO_PROFILE_TEST_DEBUG&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt; 0&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;&lt;h2 id=&quot;use-cargo-nextest&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#use-cargo-nextest&quot; aria-label=&quot;Anchor link for: use-cargo-nextest&quot;&gt;Use &lt;code&gt;cargo nextest&lt;&#x2F;code&gt;&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;p&gt;&lt;code&gt;cargo nextest&lt;&#x2F;code&gt; enables parallel test execution, which can substantially speed up your CI process.
While they claim a 3x speedup over &lt;code&gt;cargo test&lt;&#x2F;code&gt;, in CI environments I typically observe around 40%
because the runners don’t have as many cores as a developer machine.
It’s still a nice speedup.&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;yaml&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #8BE9FD;&quot;&gt;jobs&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #8BE9FD;&quot;&gt;  test&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #8BE9FD;&quot;&gt;    runs-on&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt; ubuntu-latest&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #8BE9FD;&quot;&gt;    steps&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;      -&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;&quot;&gt; uses&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt; actions&#x2F;checkout@v4&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;      -&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;&quot;&gt; uses&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt; dtolnay&#x2F;rust-toolchain@stable&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;      -&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;&quot;&gt; uses&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt; taiki-e&#x2F;install-action@nextest&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;      -&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;&quot;&gt; uses&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt; Swatinem&#x2F;rust-cache@v2&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;      -&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;&quot;&gt; name&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt; Compile&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #8BE9FD;&quot;&gt;        run&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt; cargo check --locked&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;      -&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;&quot;&gt; name&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt; Test&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #8BE9FD;&quot;&gt;        run&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt; cargo nextest&lt;&#x2F;span&gt;&lt;span&gt; &lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;&lt;h2 id=&quot;cargo-toml-settings&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#cargo-toml-settings&quot; aria-label=&quot;Anchor link for: cargo-toml-settings&quot;&gt;&lt;code&gt;Cargo.toml&lt;&#x2F;code&gt; Settings&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;p&gt;These release profile settings can significantly improve build times and binary size:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;toml&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;[&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;&quot;&gt;profile&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;&quot;&gt;release&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #8BE9FD;&quot;&gt;lto&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt; true&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #8BE9FD;&quot;&gt;codegen-units&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt; 1&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;ul&gt;
&lt;li&gt;LTO (Link Time Optimization) performs optimizations across module boundaries, which can reduce binary size and improve runtime performance.&lt;&#x2F;li&gt;
&lt;li&gt;Setting &lt;code&gt;codegen-units = 1&lt;&#x2F;code&gt; trades parallel compilation for better optimization opportunities. While this might make local builds slower, it often speeds up CI builds by reducing memory pressure on resource-constrained runners.&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;If you only want to apply these settings in CI, you can use the &lt;code&gt;CARGO_PROFILE_RELEASE_LTO&lt;&#x2F;code&gt; and &lt;code&gt;CARGO_PROFILE_RELEASE_CODEGEN_UNITS&lt;&#x2F;code&gt; environment variables:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;yaml&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #8BE9FD;&quot;&gt;jobs&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #8BE9FD;&quot;&gt;  build&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #8BE9FD;&quot;&gt;    runs-on&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt; ubuntu-latest&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #8BE9FD;&quot;&gt;    env&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #8BE9FD;&quot;&gt;      CARGO_PROFILE_RELEASE_LTO&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt; true&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #8BE9FD;&quot;&gt;      CARGO_PROFILE_RELEASE_CODEGEN_UNITS&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt; 1&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #8BE9FD;&quot;&gt;    steps&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;      -&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;&quot;&gt; uses&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt; actions&#x2F;checkout@v4&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;      -&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;&quot;&gt; name&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt; Build&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #8BE9FD;&quot;&gt;        run&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt; cargo build --release --locked&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;&lt;h2 id=&quot;use-beefier-runners&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#use-beefier-runners&quot; aria-label=&quot;Anchor link for: use-beefier-runners&quot;&gt;Use Beefier Runners&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;p&gt;GitHub Actions has recently announced that
Linux ARM64 hosted runners are now available for free in public repositories.
&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.blog&#x2F;changelog&#x2F;2025-01-16-linux-arm64-hosted-runners-now-available-for-free-in-public-repositories-public-preview&#x2F;&quot;&gt;Here’s&lt;&#x2F;a&gt; the announcement.&lt;&#x2F;p&gt;
&lt;p&gt;Switching to ARM64 provides up to 40% performance improvement and is straightforward. Simply replace &lt;code&gt;ubuntu-latest&lt;&#x2F;code&gt; with &lt;code&gt;ubuntu-latest-arm64&lt;&#x2F;code&gt; in your workflow file:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;yaml&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #8BE9FD;&quot;&gt;jobs&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #8BE9FD;&quot;&gt;  test&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #8BE9FD;&quot;&gt;    runs-on&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt; ubuntu-latest-arm64&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;However, in my &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;lycheeverse&#x2F;lychee&#x2F;pull&#x2F;1614&quot;&gt;tests&lt;&#x2F;a&gt;, the downside was that it took a long time until a runner was allocated to the job. The waiting time dwarfed the actual build time. I assume GitHub will add more runners in the future to mitigate this issue.&lt;&#x2F;p&gt;
&lt;p&gt;If you are using Rust for production workloads, it’s worth looking into dedicated VMs.
These are not free, but in comparison to the small GitHub runners, you can get a significant uplift on build times.&lt;&#x2F;p&gt;
&lt;p&gt;Any provider will do, as long as you get a VM with a decent amount of CPU cores (16+ is recommended)
and a good amount of RAM (32GB+).
Hetzner Cloud is a popular choice for this purpose because of its competitive pricing.
&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;cloud.google.com&#x2F;solutions&#x2F;spot-vms&quot;&gt;Spot instances&lt;&#x2F;a&gt; or &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.hetzner.com&#x2F;sb&#x2F;&quot;&gt;server auctions&lt;&#x2F;a&gt; can be a good way to save money.
Here are some setup resources to get you started:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;jonico&#x2F;awesome-runners&quot;&gt;Awesome Runners&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;altinity.com&#x2F;blog&#x2F;slash-ci-cd-bills-part-2-using-hetzner-cloud-github-runners-for-your-repository&quot;&gt;Using Hetzner Cloud GitHub Runners for Your Repository&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;runs-on.com&#x2F;&quot;&gt;Runs-on, a Github Actions hoster&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.blacksmith.sh&#x2F;&quot;&gt;Blacksmith&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;hetznercloud&#x2F;awesome-hcloud&quot;&gt;Awesome HCloud Repo&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;Cyclenerd&#x2F;hcloud-github-runner&quot;&gt;HCloud Runner&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;There are services like &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;depot.dev&#x2F;&quot;&gt;Depot&lt;&#x2F;a&gt;, which host runners for you.
They promise large speedups for Rust builds, but I haven’t tested them myself.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;automate-dependency-updates&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#automate-dependency-updates&quot; aria-label=&quot;Anchor link for: automate-dependency-updates&quot;&gt;Automate Dependency Updates&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;p&gt;Implement &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;docs.github.com&#x2F;en&#x2F;code-security&#x2F;getting-started&#x2F;dependabot-quickstart-guide&quot;&gt;dependabot&lt;&#x2F;a&gt; or &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;docs.renovatebot.com&#x2F;&quot;&gt;Renovate&lt;&#x2F;a&gt;
to automate dependency updates.
Instead of manually creating PRs for updates and waiting for CI, these bots handle this automatically, creating PRs that you can merge when ready.&lt;&#x2F;p&gt;
&lt;p&gt;Renovate has a bit of an edge over dependabot in terms of configurability and features.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;streamline-release-creation&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#streamline-release-creation&quot; aria-label=&quot;Anchor link for: streamline-release-creation&quot;&gt;Streamline Release Creation&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;p&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;release-plz.ieni.dev&#x2F;&quot;&gt;&lt;code&gt;release-plz&lt;&#x2F;code&gt;&lt;&#x2F;a&gt; automates release creation when PRs are merged.
This GitHub action eliminates the manual work of creating releases and is highly recommended for maintaining a smooth workflow.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;img src=&quot;https:&#x2F;&#x2F;corrode.dev&#x2F;blog&#x2F;tips-for-faster-ci-builds&#x2F;release-plz.jpg&quot; alt=&quot;release-plz website screenshot&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;h2 id=&quot;optimize-your-rust-code&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#optimize-your-rust-code&quot; aria-label=&quot;Anchor link for: optimize-your-rust-code&quot;&gt;Optimize Your Rust Code&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;p&gt;If you’ve implemented all these optimizations and your builds are still slow, it’s time to optimize the Rust code itself. I’ve compiled many tips in my other blog post &lt;a href=&quot;&#x2F;blog&#x2F;tips-for-faster-rust-compile-times&#x2F;&quot;&gt;here&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;conclusion&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#conclusion&quot; aria-label=&quot;Anchor link for: conclusion&quot;&gt;Conclusion&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;p&gt;Remember that each project is unique.
Start with the easier wins like Swatinem’s cache action and &lt;code&gt;--locked&lt;&#x2F;code&gt; flag, then progressively implement more advanced optimizations as needed. Monitor your CI metrics to ensure the changes are having the desired effect.&lt;&#x2F;p&gt;
&lt;div class=&quot;info&quot;&gt;
  
  &lt;div class=&quot;info-header&quot;&gt;
    
      &lt;span class=&quot;icon icon-crab&quot;&gt;&lt;&#x2F;span&gt;
    
    &lt;h4&gt;&lt;p&gt;Need Professional Support?&lt;&#x2F;p&gt;
&lt;&#x2F;h4&gt;
  &lt;&#x2F;div&gt;
  
  &lt;p&gt;Is your Rust CI still too slow despite implementing these optimizations?
I can help you identify and fix performance bottlenecks in your build pipeline.
&lt;a href=&quot;&#x2F;services&quot;&gt;Book a free consultation&lt;&#x2F;a&gt; to discuss your specific needs.&lt;&#x2F;p&gt;

&lt;&#x2F;div&gt;
</description>
      </item>
      <item>
          <title>Hubstaff - From Rails to Rust</title>
          <pubDate>Mon, 27 Jan 2025 00:00:00 +0000</pubDate>
          <author>Matthias Endler</author>
          <link>https://corrode.dev/learn/case-studies/hubstaff/</link>
          <guid>https://corrode.dev/learn/case-studies/hubstaff/</guid>
          <description xml:base="https://corrode.dev/learn/case-studies/hubstaff/">&lt;p&gt;It’s 2019, and &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;hubstaff.com&#x2F;&quot;&gt;Hubstaff&lt;&#x2F;a&gt;’s engineering team is sketching out plans for their new webhook system.
The new system needs to handle millions of events and work reliably at scale.
The safe choice would be to stick with their trusty Ruby on Rails stack – after all, it had served them well so far.
But that’s not the path they chose.&lt;&#x2F;p&gt;
&lt;div class=&quot;info&quot;&gt;
  
  &lt;div class=&quot;info-header&quot;&gt;
    
      &lt;span class=&quot;icon icon-info&quot;&gt;&lt;&#x2F;span&gt;
    
    &lt;h4&gt;&lt;p&gt;About Hubstaff&lt;&#x2F;p&gt;
&lt;&#x2F;h4&gt;
  &lt;&#x2F;div&gt;
  
  &lt;p&gt;Hubstaff helps distributed teams track time and manage their workforce. With 500,000+ active users across 112,000+ businesses, they needed their systems to scale reliably. As a remote-first company with 120 team members, they understand the importance of robust, efficient software.&lt;&#x2F;p&gt;

&lt;&#x2F;div&gt;
&lt;h2 id=&quot;why-hubstaff-chose-rust-when-rails-was-working-fine&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#why-hubstaff-chose-rust-when-rails-was-working-fine&quot; aria-label=&quot;Anchor link for: why-hubstaff-chose-rust-when-rails-was-working-fine&quot;&gt;Why Hubstaff Chose Rust When Rails Was Working Fine&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;p&gt;When I sat down with Alex, Hubstaff’s CTO, he painted a vivid picture of that moment. “Our entire application stack was powered by Ruby and JavaScript,” he told me. “It worked, but we knew we needed something different for this new challenge.”&lt;&#x2F;p&gt;
&lt;p&gt;The team stood at a crossroads. Go, with its simplicity and familiar patterns, felt like as a safe harbor.
But there was another path – one less traveled at the time:&lt;&#x2F;p&gt;
&lt;blockquote&gt;
&lt;p&gt;“We chose to proceed with Rust,” Alex recalled. “Not just because it was efficient, but because it would push us to &lt;strong&gt;think in fundamentally different ways&lt;&#x2F;strong&gt;.”&lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
&lt;figure&gt;
  &lt;img src=&quot;alex.jpg&quot; alt=&quot;Alex Yarotsky, CTO at Hubstaff&quot;&gt;
  &lt;figcaption&gt;Alex Yarotsky, CTO at Hubstaff&lt;&#x2F;figcaption&gt;
&lt;&#x2F;figure&gt;
&lt;h2 id=&quot;a-webhook-system-that-scaled-10x&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#a-webhook-system-that-scaled-10x&quot; aria-label=&quot;Anchor link for: a-webhook-system-that-scaled-10x&quot;&gt;A Webhook System That Scaled 10x&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;p&gt;Fast-forward to today.&lt;&#x2F;p&gt;
&lt;p&gt;The webhook system is processing ten times the initial load without breaking a sweat.
Of course, the team had to make adjustments along the way, not to their Rust code, but to their SQL queries.&lt;&#x2F;p&gt;
&lt;blockquote&gt;
&lt;p&gt;“Since its launch, we’ve had to optimize SQL queries multiple times to keep up with demand,” Alex shared, “but we’ve never faced any issues with the app’s memory or CPU consumption. Not once.”&lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
&lt;p&gt;Over time, more and more microservices got ported to Rust.&lt;&#x2F;p&gt;
&lt;figure&gt;
  &lt;img src=&quot;screenshot.png&quot; alt=&quot;Hubstaff&#x27;s Webhook System&quot;&gt;
  &lt;figcaption&gt;A screenshot of Hubstaff&#x27;s Webhook System&lt;&#x2F;figcaption&gt;
&lt;&#x2F;figure&gt;
&lt;h2 id=&quot;when-to-use-rust-and-when-to-stick-with-rails&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#when-to-use-rust-and-when-to-stick-with-rails&quot; aria-label=&quot;Anchor link for: when-to-use-rust-and-when-to-stick-with-rails&quot;&gt;When to Use Rust And When to Stick With Rails&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;p&gt;Instead of going all-in on Rust, Hubstaff found wisdom in balance.&lt;&#x2F;p&gt;
&lt;p&gt;Here’s their reasoning:&lt;&#x2F;p&gt;
&lt;ol&gt;
&lt;li&gt;High-Load Operations → Rust&lt;&#x2F;li&gt;
&lt;li&gt;Lightweight APIs and Dashboard Backend → Rails&lt;&#x2F;li&gt;
&lt;li&gt;Communication through standardized APIs and message queues&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;p&gt;But what about Rust’s infamous learning curve?&lt;&#x2F;p&gt;
&lt;p&gt;“Once developers are up to speed,” Alex noted, “there’s no noticeable slowdown in development. The Rust ecosystem has matured to the point where we’re not constantly reinventing the wheel.”&lt;&#x2F;p&gt;
&lt;h2 id=&quot;from-server-to-desktop&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#from-server-to-desktop&quot; aria-label=&quot;Anchor link for: from-server-to-desktop&quot;&gt;From Server to Desktop&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;p&gt;Once the team gained enough confidence in Rust, they started rewriting their desktop application. This was an area of the business, that was traditionally governed by C++, but the team was already sold on the idea:&lt;&#x2F;p&gt;
&lt;blockquote&gt;
&lt;p&gt;The transition to Rust was surprisingly smooth. I think a big reason for that was the collective frustration with our existing C++ codebase. Rust felt like a breath of fresh air, and the idea naturally resonated with the team.&lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
&lt;p&gt;This quote is from Artur Jakubiec, Technical Lead at Hubstaff, who was leading the desktop app migration.&lt;&#x2F;p&gt;
&lt;figure&gt;
  &lt;img src=&quot;artur.jpeg&quot; alt=&quot;Artur Jakubiec, Technical Lead at Hubstaff&quot;&gt;
  &lt;figcaption&gt;Artur Jakubiec, Technical Lead at Hubstaff&lt;&#x2F;figcaption&gt;
&lt;&#x2F;figure&gt;
&lt;p&gt;But Rust wasn’t an obvious choice for their desktop app. The easy path would have been Electron – the tried-and-true choice for companies looking to provide a desktop client from their web app.
However, Hubstaff had learned to trust that Rust would get the job done.&lt;&#x2F;p&gt;
&lt;blockquote&gt;
&lt;p&gt;“&lt;strong&gt;Electron simply wasn’t an option,&lt;&#x2F;strong&gt;” Artur stated firmly. “We needed something lightweight, something that could bridge our future with our past. That’s why we chose &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;tauri.app&#x2F;&quot;&gt;Tauri&lt;&#x2F;a&gt;.”&lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
&lt;blockquote&gt;
&lt;p&gt;“It’s still early days for this approach, as we’re currently in the process of migrating our desktop app. However, we’re already envisioning some compelling synergies emerging from this setup. For example, many of the APIs used by our desktop and mobile apps are high-load systems, and following our strategy, they’re slated to be migrated to Rust soon. &lt;strong&gt;With the desktop team already familiarizing themselves with Rust during this transition, they’ll be better equipped to make contributions or changes to these APIs, which will reduce reliance on the server team.&lt;&#x2F;strong&gt;” added Alex.&lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
&lt;h2 id=&quot;the-current-architecture&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#the-current-architecture&quot; aria-label=&quot;Anchor link for: the-current-architecture&quot;&gt;The Current Architecture&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;p&gt;Today, Hubstaff’s architecture is a mix of Ruby on Rails, Rust, and JavaScript.
Their webhooks system, backend services, and desktop app are all powered by Rust
and they keep expanding their Rust footprint across the stack for heavy-load operations.&lt;&#x2F;p&gt;
&lt;figure&gt;
  &lt;figure&gt;
    &lt;img class=&quot;centered&quot; src=&quot;architecture.svg&quot; alt=&quot;Hubstaff&#x27;s Architecture&quot;&gt;
    &lt;figcaption&gt;Simplified Overview of Hubstaff&#x27;s Current Architecture&lt;&#x2F;figcaption&gt;
  &lt;&#x2F;figure&gt;
&lt;&#x2F;figure&gt;
&lt;h2 id=&quot;was-it-all-flowers-and-sunshine&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#was-it-all-flowers-and-sunshine&quot; aria-label=&quot;Anchor link for: was-it-all-flowers-and-sunshine&quot;&gt;Was It All Flowers And Sunshine?&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;p&gt;Of course, there were moments of doubt.
Adding a new language to an already complex tech stack isn’t a decision teams make lightly.&lt;&#x2F;p&gt;
&lt;p&gt;“There was skepticism,” Artur Jakubiec, their Desktop Tech Lead, admitted. “Not about Rust itself, but about balancing our ecosystem.”&lt;&#x2F;p&gt;
&lt;p&gt;But instead of letting doubt win, Artur took action. He spent weeks building &lt;a href=&quot;&#x2F;blog&#x2F;prototyping&quot;&gt;prototypes&lt;&#x2F;a&gt;, gathering data, and crafting a vision of what could be. It wasn’t just about convincing management – it was about showing his team a glimpse of the future they could build together.&lt;&#x2F;p&gt;
&lt;p&gt;Especially the build system caused some headaches:&lt;&#x2F;p&gt;
&lt;blockquote&gt;
&lt;p&gt;One thing I really wish existed when we started was better C++-Rust integration, not just at the language level but especially in the &lt;strong&gt;build systems&lt;&#x2F;strong&gt;. Oddly enough, integrating Rust into CMake&#x2F;C++ workflows (using tools like &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;corrosion-rs&#x2F;corrosion&quot;&gt;Corrosion&lt;&#x2F;a&gt;) was relatively straightforward, but going the other way — &lt;strong&gt;embedding C++ into Rust—proved much more challenging&lt;&#x2F;strong&gt;. A more seamless and standardized approach for bidirectional integration would have saved us a lot of time and effort.&lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
&lt;p&gt;Artur adds:&lt;&#x2F;p&gt;
&lt;blockquote&gt;
&lt;p&gt;Of course, challenges remain, particularly in ensuring &lt;strong&gt;seamless knowledge transfer and establishing best practices across teams&lt;&#x2F;strong&gt;. But the potential for closer collaboration and a unified stack makes this an exciting step forward.&lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
&lt;h2 id=&quot;was-it-all-worth-it&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#was-it-all-worth-it&quot; aria-label=&quot;Anchor link for: was-it-all-worth-it&quot;&gt;Was It All Worth It?&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;p&gt;For developers coming from interpreted languages like Ruby, two main insights stood out from our conversation:&lt;&#x2F;p&gt;
&lt;blockquote&gt;
&lt;p&gt;Initially, switching to a compiled language felt like a hustle, but the “aha” moments made it worthwhile. The first came when we realized just &lt;strong&gt;how many edge cases the Rust compiler catches for you&lt;&#x2F;strong&gt; — it’s like having an additional safety net during development.
The second came after deploying Rust applications to production. &lt;strong&gt;Seeing how much more resource-efficient the Rust app was compared to its Ruby counterpart was a real eye-opener&lt;&#x2F;strong&gt;. It demonstrated the tangible benefits of Rust’s focus on performance, reinforcing why it was worth tackling the learning curve.&lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
&lt;p&gt;But what about the C++ developers, which worked on the desktop app?
What helped was that the team had prior experience with lower-level concepts from C++.&lt;&#x2F;p&gt;
&lt;blockquote&gt;
&lt;p&gt;I believe the team’s strong C++ background made the transition to Rust almost seamless. Many of Rust’s more challenging low-level concepts have parallels in C++, such as the memory model, RAII, move semantics, pointers, references, and even aspects of ADTs (achievable in C++ with tools like &lt;code&gt;std::optional&lt;&#x2F;code&gt; and &lt;code&gt;std::variant&lt;&#x2F;code&gt;). Similarly, Rust’s ownership system and concepts like lifetimes echo patterns familiar to anyone experienced in managing resources in C++.&lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
&lt;p&gt;Let’s look at the facts:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;Desktop developers now contribute to backend services, breaking down old silos.&lt;&#x2F;li&gt;
&lt;li&gt;Five years without a single memory-related issue in production.&lt;&#x2F;li&gt;
&lt;li&gt;Their C++ developers are on-board with Rust’s safety guarantees as well.&lt;&#x2F;li&gt;
&lt;li&gt;Infrastructure costs stayed flat despite 10x growth.&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;But perhaps the biggest change is &lt;strong&gt;confidence in the codebase&lt;&#x2F;strong&gt;:&lt;&#x2F;p&gt;
&lt;blockquote&gt;
&lt;p&gt;“With C++, there’s a constant sense of paranoia about every line you write,” Artur revealed. “&lt;strong&gt;Rust transformed that fear into confidence&lt;&#x2F;strong&gt;. It changed not just how we code, but how we feel about coding.” […] “it’s like stepping into a world where you can trust your tools”&lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
&lt;p&gt;On top of that, Alex added that using Rust across the stack has also opened up new collaboration opportunities across the teams.&lt;&#x2F;p&gt;
&lt;p&gt;Artur adds that the onboarding experience has also been smoother than expected:&lt;&#x2F;p&gt;
&lt;blockquote&gt;
&lt;p&gt;So far, onboarding hasn’t been an issue at all. Honestly, there’s no secret sauce — it’s all about getting new team members working on the code as soon as possible.&lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
&lt;figure&gt;
  &lt;img src=&quot;team.jpg&quot; alt=&quot;Hubstaff Team&quot;&gt;
  &lt;figcaption&gt;Parts of the Hubstaff Team at their 2022 team offsite in Punta Cana&lt;&#x2F;figcaption&gt;
&lt;&#x2F;figure&gt;
&lt;h2 id=&quot;where-they-are-today&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#where-they-are-today&quot; aria-label=&quot;Anchor link for: where-they-are-today&quot;&gt;Where They Are Today&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;p&gt;Today, Hubstaff’s journey continues.
Their Rust footprint grows steadily: 4,200 lines of mission-critical server code, 2,000 lines in their desktop app, and a team of passionate Rustaceans that’s still growing.&lt;&#x2F;p&gt;
&lt;p&gt;But when I asked Alex and Artur what they’re most proud of, it wasn’t the technical achievements that topped their list. It was how they got there: thoughtfully, methodically, and together as a team.&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;2019&lt;&#x2F;strong&gt;: First steps into Rust - Webhook system prototype. 🌱&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;2020&lt;&#x2F;strong&gt;: Webhook system processes first million events. 🌿&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;2024&lt;&#x2F;strong&gt;: Started desktop app migration to Rust&#x2F;Tauri. 🪴&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;2025&lt;&#x2F;strong&gt;: Expanding Rust across their entire stack. Public release of new Rust-powered desktop app. 🌳&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h2 id=&quot;key-lessons-for-teams-considering-rust&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#key-lessons-for-teams-considering-rust&quot; aria-label=&quot;Anchor link for: key-lessons-for-teams-considering-rust&quot;&gt;Key Lessons for Teams Considering Rust&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;p&gt;What would Alex and Artur recommend to teams standing at their own crossroads?&lt;br &#x2F;&gt;
Here’s what they shared:&lt;&#x2F;p&gt;
&lt;ol&gt;
&lt;li&gt;Start with a clear mission, not just a technical preference&lt;&#x2F;li&gt;
&lt;li&gt;Invest in your team’s journey through learning and support&lt;&#x2F;li&gt;
&lt;li&gt;Make data-driven decisions&lt;&#x2F;li&gt;
&lt;li&gt;Build bridges between the old and the new&lt;&#x2F;li&gt;
&lt;li&gt;Look for opportunities for collaboration and knowledge sharing&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;h2 id=&quot;thanks&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#thanks&quot; aria-label=&quot;Anchor link for: thanks&quot;&gt;Thanks&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;p&gt;Special thanks to &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.linkedin.com&#x2F;in&#x2F;ayarotsky&#x2F;&quot;&gt;Alex Yarotsky&lt;&#x2F;a&gt;, CTO
and &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.linkedin.com&#x2F;in&#x2F;artur-jakubiec&#x2F;&quot;&gt;Artur Jakubiec&lt;&#x2F;a&gt;, Technical Lead at Hubstaff for sharing their journey with Rust.&lt;&#x2F;p&gt;
&lt;p&gt;Want to learn more about Hubstaff? &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;hubstaff.com&#x2F;&quot;&gt;Check out their website&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
</description>
      </item>
      <item>
          <title>Volvo</title>
          <pubDate>Thu, 23 Jan 2025 00:00:00 +0000</pubDate>
          <author>Matthias Endler</author>
          <link>https://corrode.dev/podcast/s03e08-volvo/</link>
          <guid>https://corrode.dev/podcast/s03e08-volvo/</guid>
          <description xml:base="https://corrode.dev/podcast/s03e08-volvo/">&lt;div&gt;&lt;script id=&quot;letscast-player-5d620579&quot; src=&quot;https:&#x2F;&#x2F;letscast.fm&#x2F;podcasts&#x2F;rust-in-production-82281512&#x2F;episodes&#x2F;volvo-with-julius-gustavsson&#x2F;player.js?size=s&quot;&gt;&lt;&#x2F;script&gt;&lt;&#x2F;div&gt;
&lt;p&gt;The car industry is not known for its rapid adoption of new technologies.
Therefore, it’s even more exciting to see a company like Volvo Cars embracing Rust for core components of their software stack.&lt;&#x2F;p&gt;</description>
      </item>
      <item>
          <title>Thinking in Expressions</title>
          <pubDate>Tue, 21 Jan 2025 00:00:00 +0000</pubDate>
          <author>Matthias Endler</author>
          <link>https://corrode.dev/blog/expressions/</link>
          <guid>https://corrode.dev/blog/expressions/</guid>
          <description xml:base="https://corrode.dev/blog/expressions/">&lt;p&gt;Rust’s focus on expressions is an underrated aspect of the language.
Code feels more natural to compose once you embrace expressions as a core mechanic in Rust.
I would go as far as to say that expressions shaped the way I think about control flow in general.&lt;&#x2F;p&gt;
&lt;p&gt;“Everything is an expression” is a bit of an exaggeration, but it’s a useful mental model while you
internalize the concept.&lt;sup class=&quot;footnote-reference&quot; id=&quot;fr-reference-1&quot;&gt;&lt;a href=&quot;#fn-reference&quot;&gt;1&lt;&#x2F;a&gt;&lt;&#x2F;sup&gt;&lt;&#x2F;p&gt;
&lt;p&gt;But what’s so special about them?&lt;&#x2F;p&gt;
&lt;h2 id=&quot;expressions-produce-values-statements-do-not&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#expressions-produce-values-statements-do-not&quot; aria-label=&quot;Anchor link for: expressions-produce-values-statements-do-not&quot;&gt;Expressions produce values, statements do not.&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;p&gt;The difference between expressions and statements can easily be dismissed as a minor detail.
Underneath the surface, though, the fact that expressions return values has a profound impact on the ergonomics of a language.&lt;&#x2F;p&gt;
&lt;p&gt;In Rust, most things produce a value: literals, variables, function calls, blocks, and control flow statements like &lt;code&gt;if&lt;&#x2F;code&gt;, &lt;code&gt;match&lt;&#x2F;code&gt;, and &lt;code&gt;loop&lt;&#x2F;code&gt;.
Even &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;doc.rust-lang.org&#x2F;reference&#x2F;expressions&#x2F;operator-expr.html#borrow-operators&quot;&gt;&lt;code&gt;&amp;amp;&lt;&#x2F;code&gt;&lt;&#x2F;a&gt; and &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;doc.rust-lang.org&#x2F;reference&#x2F;expressions&#x2F;operator-expr.html#the-dereference-operator&quot;&gt;&lt;code&gt;*&lt;&#x2F;code&gt;&lt;&#x2F;a&gt; are expressions in Rust.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;expressions-in-rust-vs-other-languages&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#expressions-in-rust-vs-other-languages&quot; aria-label=&quot;Anchor link for: expressions-in-rust-vs-other-languages&quot;&gt;Expressions In Rust vs other languages&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;p&gt;Rust inherits expressions from its functional roots in the &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;ML_(programming_language)&quot;&gt;ML family of languages&lt;&#x2F;a&gt;; they are not so common in other languages.
Go, C++, Java, and TypeScript have them, but they pale in comparison to Rust.&lt;&#x2F;p&gt;
&lt;p&gt;In Go, for example, an &lt;code&gt;if&lt;&#x2F;code&gt; statement is… well, a &lt;em&gt;statement&lt;&#x2F;em&gt; and not an expression. This has some surprising side-effects. For example, you can’t use &lt;code&gt;if&lt;&#x2F;code&gt; statements in a ternary expression like you would in Rust:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;go&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;&#x2F;&#x2F; This is not valid Go code!&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;var&lt;&#x2F;span&gt;&lt;span&gt; x&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; = if&lt;&#x2F;span&gt;&lt;span&gt; condition {&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt; 1&lt;&#x2F;span&gt;&lt;span&gt; }&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; else&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt; 2&lt;&#x2F;span&gt;&lt;span&gt; };&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Instead, you’d have to write a full-blown &lt;code&gt;if&lt;&#x2F;code&gt; statement
along with a slightly unfortunate upfront variable declaration:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;go&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;var&lt;&#x2F;span&gt;&lt;span&gt; x&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; int&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;if&lt;&#x2F;span&gt;&lt;span&gt; condition {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  x&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt; 1&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; else&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  x&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt; 2&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Since &lt;code&gt;if&lt;&#x2F;code&gt; is an expression in Rust, using it in a ternary expression is perfectly normal.&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;let&lt;&#x2F;span&gt;&lt;span&gt; x&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; = if&lt;&#x2F;span&gt;&lt;span&gt; condition {&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt; 1&lt;&#x2F;span&gt;&lt;span&gt; }&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; else&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt; 2&lt;&#x2F;span&gt;&lt;span&gt; };&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;That explains the absence of the ternary operator  in Rust (i.e. there is no syntax like &lt;code&gt;x = condition ? 1 : 2;&lt;&#x2F;code&gt;).
No special syntax is needed because &lt;code&gt;if&lt;&#x2F;code&gt; is comparably concise.&lt;&#x2F;p&gt;
&lt;p&gt;Also note that in comparison to Go, our variable &lt;code&gt;x&lt;&#x2F;code&gt; does not need to be mutable.
As we will see, Rust’s expressions often lead to less mutable code.&lt;&#x2F;p&gt;
&lt;p&gt;In combination with pattern matching, expressions in Rust become even more powerful:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;let&lt;&#x2F;span&gt;&lt;span&gt; (a, b)&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; = if&lt;&#x2F;span&gt;&lt;span&gt; condition { (&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt;&amp;quot;first&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt; true&lt;&#x2F;span&gt;&lt;span&gt;) }&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; else&lt;&#x2F;span&gt;&lt;span&gt; { (&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt;&amp;quot;second&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt; false&lt;&#x2F;span&gt;&lt;span&gt;) };&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Here, the left side of the assignment (a, b) is a pattern that destructures the tuple returned by the &lt;code&gt;if-else&lt;&#x2F;code&gt; expression.&lt;&#x2F;p&gt;
&lt;p&gt;What if you deal with more complex control flow?
That’s not a problem. &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;doc.rust-lang.org&#x2F;reference&#x2F;expressions&#x2F;match-expr.html&quot;&gt;&lt;code&gt;match&lt;&#x2F;code&gt; is an expression&lt;&#x2F;a&gt;, too.
It is common to assign the result of a &lt;code&gt;match&lt;&#x2F;code&gt; expression to a variable.&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;let&lt;&#x2F;span&gt;&lt;span&gt; color&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; = match&lt;&#x2F;span&gt;&lt;span&gt; duck {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;    Duck&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;Huey&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt; &amp;quot;Red&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;    Duck&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;Dewey&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt; &amp;quot;Blue&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;    Duck&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;Louie&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt; &amp;quot;Green&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;};&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;&lt;h2 id=&quot;combining-match-and-if-expressions&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#combining-match-and-if-expressions&quot; aria-label=&quot;Anchor link for: combining-match-and-if-expressions&quot;&gt;Combining &lt;code&gt;match&lt;&#x2F;code&gt; and &lt;code&gt;if&lt;&#x2F;code&gt; Expressions&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;p&gt;Let’s say you want to return a duck’s color, but you want to return the correct color based on the year.
(In the early Disney comics, the nephews were wearing different colors.)&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;let&lt;&#x2F;span&gt;&lt;span&gt; color&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; = match&lt;&#x2F;span&gt;&lt;span&gt; duck {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;    &#x2F;&#x2F; In early comic books, the&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;    &#x2F;&#x2F; ducks were colored randomly&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    _&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; if&lt;&#x2F;span&gt;&lt;span&gt; year&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; &amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt; 1980&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; random_color&lt;&#x2F;span&gt;&lt;span&gt;(),&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;    &#x2F;&#x2F; In the early 80s, Huey&amp;#39;s cap was pink&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;    Duck&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;Huey&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; if&lt;&#x2F;span&gt;&lt;span&gt; year&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; &amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt; 1982&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt; &amp;quot;Pink&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;    &#x2F;&#x2F; Since 1982, the ducks have dedicated colors&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;    Duck&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;Huey&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt; &amp;quot;Red&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;    Duck&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;Dewey&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt; &amp;quot;Blue&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;    Duck&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;Louie&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt; &amp;quot;Green&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;};&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Neat, right? You can combine &lt;code&gt;match&lt;&#x2F;code&gt; and &lt;code&gt;if&lt;&#x2F;code&gt; expressions to create complex logic in a few lines of code.&lt;&#x2F;p&gt;
&lt;p&gt;Note: those &lt;code&gt;if&lt;&#x2F;code&gt;s are called &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;doc.rust-lang.org&#x2F;reference&#x2F;expressions&#x2F;match-expr.html&quot;&gt;match arm guards&lt;&#x2F;a&gt;, and they really &lt;em&gt;are&lt;&#x2F;em&gt; full-fledged &lt;code&gt;if&lt;&#x2F;code&gt; expressions.
You can put anything in there just like in a regular &lt;code&gt;if&lt;&#x2F;code&gt;.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;lesser-known-facts-about-expressions&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#lesser-known-facts-about-expressions&quot; aria-label=&quot;Anchor link for: lesser-known-facts-about-expressions&quot;&gt;Lesser known facts about expressions&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;h3 id=&quot;break-is-an-expression&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#break-is-an-expression&quot; aria-label=&quot;Anchor link for: break-is-an-expression&quot;&gt;&lt;code&gt;break&lt;&#x2F;code&gt; is an expression&lt;&#x2F;a&gt;&lt;&#x2F;h3&gt;
&lt;p&gt;You can return a value from a loop with &lt;code&gt;break&lt;&#x2F;code&gt;:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;let&lt;&#x2F;span&gt;&lt;span&gt; foo&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; = loop&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; break&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt; 1&lt;&#x2F;span&gt;&lt;span&gt; };&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;&#x2F;&#x2F; foo is 1&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;More commonly, you’d use it like this:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;let&lt;&#x2F;span&gt;&lt;span&gt; result&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; = loop&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    counter&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; +=&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt; 1&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    if&lt;&#x2F;span&gt;&lt;span&gt; counter&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; ==&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt; 10&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;        break&lt;&#x2F;span&gt;&lt;span&gt; counter&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; *&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt; 2&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;};&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;&#x2F;&#x2F; result is 20&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;&lt;h3 id=&quot;dbg-returns-the-value-of-the-inner-expression&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#dbg-returns-the-value-of-the-inner-expression&quot; aria-label=&quot;Anchor link for: dbg-returns-the-value-of-the-inner-expression&quot;&gt;&lt;code&gt;dbg!()&lt;&#x2F;code&gt; returns the value of the inner expression&lt;&#x2F;a&gt;&lt;&#x2F;h3&gt;
&lt;p&gt;You can wrap any expression with &lt;code&gt;dbg!()&lt;&#x2F;code&gt; without changing the behavior of your code (aside from the debug output).&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;let&lt;&#x2F;span&gt;&lt;span&gt; x&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; dbg!&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;compute_complex_value&lt;&#x2F;span&gt;&lt;span&gt;());&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;&lt;h2 id=&quot;real-world-refactoring-with-expressions&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#real-world-refactoring-with-expressions&quot; aria-label=&quot;Anchor link for: real-world-refactoring-with-expressions&quot;&gt;Real-World Refactoring With Expressions&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;p&gt;So far, I showed you some fancy expression tricks, but how do you apply this in practice?&lt;&#x2F;p&gt;
&lt;p&gt;To illustrate this, imagine you have a &lt;code&gt;Config&lt;&#x2F;code&gt; struct that reads a configuration file from a given path:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;&#x2F;&#x2F;&#x2F; Configuration for the application&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;pub struct&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Config&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    config_path&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; PathBuf&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;&#x2F;&#x2F;&#x2F; Creates a new Config with the given path&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;&#x2F;&#x2F;&#x2F;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;&#x2F;&#x2F;&#x2F; The path is resolved against the home directory if relative.&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;&#x2F;&#x2F;&#x2F; Validates that the path exists and has the correct extension.&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;impl&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Config&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    pub fn&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; with_config_path&lt;&#x2F;span&gt;&lt;span&gt;(path&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; PathBuf&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; -&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Result&lt;&#x2F;span&gt;&lt;span&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;font-style: italic;&quot;&gt;Self&lt;&#x2F;span&gt;&lt;span&gt;, std&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span&gt;io&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;Error&lt;&#x2F;span&gt;&lt;span&gt;&amp;gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;        todo!&lt;&#x2F;span&gt;&lt;span&gt;()&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Here’s how you might implement the &lt;code&gt;with_config_path&lt;&#x2F;code&gt; method in an imperative style:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;impl&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Config&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    pub fn&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; with_config_path&lt;&#x2F;span&gt;&lt;span&gt;(path&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; PathBuf&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; -&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Result&lt;&#x2F;span&gt;&lt;span&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;font-style: italic;&quot;&gt;Self&lt;&#x2F;span&gt;&lt;span&gt;, std&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span&gt;io&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;Error&lt;&#x2F;span&gt;&lt;span&gt;&amp;gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;        &#x2F;&#x2F; First determine the base path&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;        let mut&lt;&#x2F;span&gt;&lt;span&gt; config_path;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;        if&lt;&#x2F;span&gt;&lt;span&gt; path&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;is_absolute&lt;&#x2F;span&gt;&lt;span&gt;() {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            config_path&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; path;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        }&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; else&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;            let&lt;&#x2F;span&gt;&lt;span&gt; home&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; get_home_dir&lt;&#x2F;span&gt;&lt;span&gt;();&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;            if&lt;&#x2F;span&gt;&lt;span&gt; home&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;is_none&lt;&#x2F;span&gt;&lt;span&gt;() {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;                return&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Err&lt;&#x2F;span&gt;&lt;span&gt;(io&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;Error&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;new&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                    io&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span&gt;ErrorKind&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;NotFound&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt;                    &amp;quot;Home directory not found&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                ));&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            config_path&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; home&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;unwrap&lt;&#x2F;span&gt;&lt;span&gt;()&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;join&lt;&#x2F;span&gt;&lt;span&gt;(path);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;        &#x2F;&#x2F; Do validation&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;        if !&lt;&#x2F;span&gt;&lt;span&gt;config_path&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;exists&lt;&#x2F;span&gt;&lt;span&gt;() {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;            return&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Err&lt;&#x2F;span&gt;&lt;span&gt;(io&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;Error&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;new&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                io&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span&gt;ErrorKind&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;NotFound&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt;                &amp;quot;Config path does not exist&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            ));&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;        if&lt;&#x2F;span&gt;&lt;span&gt; config_path&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;is_file&lt;&#x2F;span&gt;&lt;span&gt;() {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;            let&lt;&#x2F;span&gt;&lt;span&gt; ext&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; config_path&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;extension&lt;&#x2F;span&gt;&lt;span&gt;();&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;            if&lt;&#x2F;span&gt;&lt;span&gt; ext&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;is_none&lt;&#x2F;span&gt;&lt;span&gt;() {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;                return&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Err&lt;&#x2F;span&gt;&lt;span&gt;(io&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;Error&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;new&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                    io&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span&gt;ErrorKind&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;InvalidInput&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt;                    &amp;quot;Config file must have .conf extension&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                ));&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;            if&lt;&#x2F;span&gt;&lt;span&gt; ext&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;unwrap&lt;&#x2F;span&gt;&lt;span&gt;()&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;to_str&lt;&#x2F;span&gt;&lt;span&gt;()&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; !=&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Some&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt;&amp;quot;conf&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;) {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;                return&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Err&lt;&#x2F;span&gt;&lt;span&gt;(io&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;Error&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;new&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                    io&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span&gt;ErrorKind&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;InvalidInput&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt;                    &amp;quot;Config file must have .conf extension&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                ));&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;        return&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Ok&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;font-style: italic;&quot;&gt;Self&lt;&#x2F;span&gt;&lt;span&gt; { config_path });&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;There are a few things we can improve here:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;The code is quite imperative&lt;&#x2F;li&gt;
&lt;li&gt;Lots of temporary variables&lt;&#x2F;li&gt;
&lt;li&gt;Explicit mutation with &lt;code&gt;mut&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;Nested if statements&lt;&#x2F;li&gt;
&lt;li&gt;Manual unwrapping with &lt;code&gt;is_none()&lt;&#x2F;code&gt;&#x2F;&lt;code&gt;unwrap()&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h2 id=&quot;tip-1-remove-the-unwraps&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#tip-1-remove-the-unwraps&quot; aria-label=&quot;Anchor link for: tip-1-remove-the-unwraps&quot;&gt;Tip 1: Remove the unwraps&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;p&gt;It’s always a good idea to examine &lt;code&gt;unwrap()&lt;&#x2F;code&gt; calls and find safer alternatives.
While we “only” have two &lt;code&gt;unwrap()&lt;&#x2F;code&gt; calls here, both point at flaws in our design.
Here’s the first one:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;let mut&lt;&#x2F;span&gt;&lt;span&gt; config_path;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;if&lt;&#x2F;span&gt;&lt;span&gt; path&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;is_absolute&lt;&#x2F;span&gt;&lt;span&gt;() {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    config_path&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; path;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; else&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    let&lt;&#x2F;span&gt;&lt;span&gt; home&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; get_home_dir&lt;&#x2F;span&gt;&lt;span&gt;();&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    if&lt;&#x2F;span&gt;&lt;span&gt; home&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;is_none&lt;&#x2F;span&gt;&lt;span&gt;() {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;        return&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Err&lt;&#x2F;span&gt;&lt;span&gt;(io&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;Error&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;new&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            io&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span&gt;ErrorKind&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;NotFound&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt;            &amp;quot;Home directory not found&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        ));&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    config_path&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; home&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;unwrap&lt;&#x2F;span&gt;&lt;span&gt;()&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;join&lt;&#x2F;span&gt;&lt;span&gt;(path);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;We know that &lt;code&gt;home&lt;&#x2F;code&gt; is not &lt;code&gt;None&lt;&#x2F;code&gt; when we &lt;code&gt;unwrap&lt;&#x2F;code&gt; it, because we checked it right above.
But what if we refactor the code? We might forget the check and introduce a bug.&lt;&#x2F;p&gt;
&lt;p&gt;This can be rewritten as:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;let&lt;&#x2F;span&gt;&lt;span&gt; config_path&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; = if&lt;&#x2F;span&gt;&lt;span&gt; path&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;is_absolute&lt;&#x2F;span&gt;&lt;span&gt;() {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    path&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; else&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    let&lt;&#x2F;span&gt;&lt;span&gt; home&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; get_home_dir&lt;&#x2F;span&gt;&lt;span&gt;()&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;ok_or_else&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;||&lt;&#x2F;span&gt;&lt;span&gt; io&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span&gt;Error&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;new&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        io&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span&gt;ErrorKind&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;NotFound&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt;        &amp;quot;Home directory not found&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    ))&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;?&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    home&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;join&lt;&#x2F;span&gt;&lt;span&gt;(path)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;};&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Or, if we introduce a custom error type:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;let&lt;&#x2F;span&gt;&lt;span&gt; config_path&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; = if&lt;&#x2F;span&gt;&lt;span&gt; path&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;is_absolute&lt;&#x2F;span&gt;&lt;span&gt;() {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    path&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; else&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    let&lt;&#x2F;span&gt;&lt;span&gt; home&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; get_home_dir&lt;&#x2F;span&gt;&lt;span&gt;()&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;ok_or_else&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;||&lt;&#x2F;span&gt;&lt;span&gt; ConfigError&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;HomeDirNotFound&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;?&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    home&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;join&lt;&#x2F;span&gt;&lt;span&gt;(path)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;};&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;The other &lt;code&gt;unwrap&lt;&#x2F;code&gt; is also unnecessary and makes the happy path harder to read.
Here is the original code:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;if&lt;&#x2F;span&gt;&lt;span&gt; config_path&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;is_file&lt;&#x2F;span&gt;&lt;span&gt;() {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    let&lt;&#x2F;span&gt;&lt;span&gt; ext&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; config_path&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;extension&lt;&#x2F;span&gt;&lt;span&gt;();&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    if&lt;&#x2F;span&gt;&lt;span&gt; ext&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;is_none&lt;&#x2F;span&gt;&lt;span&gt;() {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;        return&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Err&lt;&#x2F;span&gt;&lt;span&gt;(io&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;Error&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;new&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            io&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span&gt;ErrorKind&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;InvalidInput&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt;            &amp;quot;Config file must have .conf extension&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        ));&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    if&lt;&#x2F;span&gt;&lt;span&gt; ext&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;unwrap&lt;&#x2F;span&gt;&lt;span&gt;()&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;to_str&lt;&#x2F;span&gt;&lt;span&gt;()&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; !=&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Some&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt;&amp;quot;conf&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;) {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;        return&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Err&lt;&#x2F;span&gt;&lt;span&gt;(io&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;Error&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;new&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            io&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span&gt;ErrorKind&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;InvalidInput&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt;            &amp;quot;Config file must have .conf extension&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        ));&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;We can rewrite this as:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;if&lt;&#x2F;span&gt;&lt;span&gt; config_path&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;is_file&lt;&#x2F;span&gt;&lt;span&gt;() {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    let&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Some&lt;&#x2F;span&gt;&lt;span&gt;(ext)&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; config_path&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;extension&lt;&#x2F;span&gt;&lt;span&gt;()&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; else&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;        return&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Err&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;...&lt;&#x2F;span&gt;&lt;span&gt;);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    if&lt;&#x2F;span&gt;&lt;span&gt; ext&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; !=&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt; &amp;quot;conf&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;        return&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Err&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;...&lt;&#x2F;span&gt;&lt;span&gt;);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Or we return early to avoid the nested &lt;code&gt;if&lt;&#x2F;code&gt;:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;if !&lt;&#x2F;span&gt;&lt;span&gt;config_path&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;is_file&lt;&#x2F;span&gt;&lt;span&gt;() {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    return&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Err&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;...&lt;&#x2F;span&gt;&lt;span&gt;);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;let&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Some&lt;&#x2F;span&gt;&lt;span&gt;(ext)&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; config_path&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;extension&lt;&#x2F;span&gt;&lt;span&gt;()&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; else&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    return&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Err&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;...&lt;&#x2F;span&gt;&lt;span&gt;);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;if&lt;&#x2F;span&gt;&lt;span&gt; ext&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; !=&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt; &amp;quot;conf&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    return&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Err&lt;&#x2F;span&gt;&lt;span&gt;(io&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;Error&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;new&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;...&lt;&#x2F;span&gt;&lt;span&gt;));&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;(&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;play.rust-lang.org&#x2F;?version=stable&amp;amp;mode=debug&amp;amp;edition=2021&amp;amp;gist=f852d031661536d4cac9f8ac3c9d7317&quot;&gt;Playground&lt;&#x2F;a&gt;)&lt;&#x2F;p&gt;
&lt;h2 id=&quot;tip-2-remove-the-muts&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#tip-2-remove-the-muts&quot; aria-label=&quot;Anchor link for: tip-2-remove-the-muts&quot;&gt;Tip 2: Remove the &lt;code&gt;mut&lt;&#x2F;code&gt;s&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;p&gt;Usually, my next step is to get rid of as many &lt;code&gt;mut&lt;&#x2F;code&gt; variables as possible.&lt;&#x2F;p&gt;
&lt;p&gt;Note how there are no more &lt;code&gt;mut&lt;&#x2F;code&gt; keywords after our first refactoring.
This is a typical pattern in Rust: often when we get rid of an &lt;code&gt;unwrap()&lt;&#x2F;code&gt;, we can remove a &lt;code&gt;mut&lt;&#x2F;code&gt; as well.&lt;&#x2F;p&gt;
&lt;p&gt;Nevertheless, it is always a good idea to look for all &lt;code&gt;mut&lt;&#x2F;code&gt; variables and see if they are really necessary.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;tip-3-remove-the-explicit-return-statements&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#tip-3-remove-the-explicit-return-statements&quot; aria-label=&quot;Anchor link for: tip-3-remove-the-explicit-return-statements&quot;&gt;Tip 3: Remove the explicit return statements&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;p&gt;The last expression in a block is implicitly returned
and that &lt;code&gt;return&lt;&#x2F;code&gt; is an expression itself, so you can often get rid of explicit &lt;code&gt;return&lt;&#x2F;code&gt; statements.
In our case that means:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;return&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Ok&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;font-style: italic;&quot;&gt;Self&lt;&#x2F;span&gt;&lt;span&gt; { config_path });&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;becomes&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;Ok&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;font-style: italic;&quot;&gt;Self&lt;&#x2F;span&gt;&lt;span&gt; { config_path })&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Another simple heuristic is to hunt for &lt;code&gt;returns&lt;&#x2F;code&gt; and semicolons in the middle of your code.
These are like “seams” in our program; stop signs, which break the natural data flow.
Almost effortlessly, removing these blockers often improves the flow; it’s like magic.&lt;&#x2F;p&gt;
&lt;p&gt;For example, the above validation code can also be written without returns:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;match&lt;&#x2F;span&gt;&lt;span&gt; config_path {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    path&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; if !&lt;&#x2F;span&gt;&lt;span&gt;path&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;is_file&lt;&#x2F;span&gt;&lt;span&gt;()&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Err&lt;&#x2F;span&gt;&lt;span&gt;(io&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;Error&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;new&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        io&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span&gt;ErrorKind&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;InvalidInput&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt;        &amp;quot;Config path is not a file&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    )),&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    path&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; if&lt;&#x2F;span&gt;&lt;span&gt; path&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;extension&lt;&#x2F;span&gt;&lt;span&gt;()&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; !=&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Some&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;OsStr&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;new&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt;&amp;quot;conf&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;))&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Err&lt;&#x2F;span&gt;&lt;span&gt;(io&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;Error&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;new&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        io&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span&gt;ErrorKind&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;InvalidInput&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt;        &amp;quot;Config file must have .conf extension&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    )),&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    _&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Ok&lt;&#x2F;span&gt;&lt;span&gt;(())&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;I like that, because we avoid one error message duplication and all conditions start on the left.
Whether you prefer that over &lt;code&gt;let-else&lt;&#x2F;code&gt; is a matter of taste. &lt;sup class=&quot;footnote-reference&quot; id=&quot;fr-let-else-statement-1&quot;&gt;&lt;a href=&quot;#fn-let-else-statement&quot;&gt;2&lt;&#x2F;a&gt;&lt;&#x2F;sup&gt;&lt;&#x2F;p&gt;
&lt;h2 id=&quot;don-t-take-it-too-far&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#don-t-take-it-too-far&quot; aria-label=&quot;Anchor link for: don-t-take-it-too-far&quot;&gt;Don’t take it too far&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;p&gt;Remember when I said “everything is an expression”?
Don’t take this too far or people will stop inviting you to dinner parties.&lt;&#x2F;p&gt;
&lt;p&gt;It’s fun to know that you could use &lt;code&gt;then_some&lt;&#x2F;code&gt;, &lt;code&gt;unwrap_or_else&lt;&#x2F;code&gt;, and &lt;code&gt;map_or&lt;&#x2F;code&gt; to chain expressions together, but don’t use them just to show off.&lt;&#x2F;p&gt;
&lt;div class=&quot;info&quot;&gt;
  
  &lt;div class=&quot;info-header&quot;&gt;
    
      &lt;span class=&quot;icon icon-warning&quot;&gt;&lt;&#x2F;span&gt;
    
    &lt;h4&gt;&lt;p&gt;Warning&lt;&#x2F;p&gt;
&lt;&#x2F;h4&gt;
  &lt;&#x2F;div&gt;
  
  &lt;p&gt;The below code is correct, but the combinators get in the way of readability.
It feels more like a Lisp program than Rust code.&lt;&#x2F;p&gt;

&lt;&#x2F;div&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;impl&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Config&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    pub fn&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; with_config_path&lt;&#x2F;span&gt;&lt;span&gt;(path&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; PathBuf&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; -&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Result&lt;&#x2F;span&gt;&lt;span&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;font-style: italic;&quot;&gt;Self&lt;&#x2F;span&gt;&lt;span&gt;, io&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;Error&lt;&#x2F;span&gt;&lt;span&gt;&amp;gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        (&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;if&lt;&#x2F;span&gt;&lt;span&gt; path&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;is_absolute&lt;&#x2F;span&gt;&lt;span&gt;() {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;            Ok&lt;&#x2F;span&gt;&lt;span&gt;(path)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        }&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; else&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;            get_home_dir&lt;&#x2F;span&gt;&lt;span&gt;()&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;                .&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;ok_or_else&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;&#x2F;* error *&#x2F;&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;                .&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;map&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;|&lt;&#x2F;span&gt;&lt;span&gt;home&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;|&lt;&#x2F;span&gt;&lt;span&gt; home&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;join&lt;&#x2F;span&gt;&lt;span&gt;(path))&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        })&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;        .&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;and_then&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;|&lt;&#x2F;span&gt;&lt;span&gt;config_path&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;|&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            (&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;!&lt;&#x2F;span&gt;&lt;span&gt;config_path&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;exists&lt;&#x2F;span&gt;&lt;span&gt;())&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;                .&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;then_some&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;Err&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;&#x2F;* error *&#x2F;&lt;&#x2F;span&gt;&lt;span&gt;))&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;                .&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;unwrap_or_else&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;||&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                    config_path&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;                        .&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;is_file&lt;&#x2F;span&gt;&lt;span&gt;()&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;                        .&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;then&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;||&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                            (&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;!&lt;&#x2F;span&gt;&lt;span&gt;config_path&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;                                .&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;extension&lt;&#x2F;span&gt;&lt;span&gt;()&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;                                .&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;map_or&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt;false&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; |&lt;&#x2F;span&gt;&lt;span&gt;ext&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;|&lt;&#x2F;span&gt;&lt;span&gt; ext&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; ==&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt; &amp;quot;conf&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;))&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;                                .&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;then_some&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;Err&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;&#x2F;* error *&#x2F;&lt;&#x2F;span&gt;&lt;span&gt;))&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;                                .&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;unwrap_or&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;Ok&lt;&#x2F;span&gt;&lt;span&gt;(()))&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                        })&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;                        .&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;unwrap_or&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;Ok&lt;&#x2F;span&gt;&lt;span&gt;(()))&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;                        .&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;map&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;|&lt;&#x2F;span&gt;&lt;span&gt;_&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;|&lt;&#x2F;span&gt;&lt;span&gt; config_path)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                })&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        })&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;        .&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;map&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;|&lt;&#x2F;span&gt;&lt;span&gt;config_path&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;|&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;font-style: italic;&quot;&gt; Self&lt;&#x2F;span&gt;&lt;span&gt; { config_path })&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Keep your friends and colleagues in mind when writing code.
Find a balance between expressiveness and readability.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;conclusion&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#conclusion&quot; aria-label=&quot;Anchor link for: conclusion&quot;&gt;Conclusion&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;p&gt;If you find that your code doesn’t feel idiomatic, see if expressions can help.
They tend to guide you towards more ergonomic Rust code.&lt;&#x2F;p&gt;
&lt;p&gt;Once you find the right balance, expressions are a joy to use – especially in smaller context where data flow is key.
The “trifecta” of iterators, expressions, and pattern matching is the foundation of data transformations in Rust.
I wrote a complementary article about iterators &lt;a href=&quot;&#x2F;blog&#x2F;iterators&#x2F;&quot;&gt;here&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;Of course, it’s not forbidden to mix expressions and statements!
For example, I personally like to use &lt;code&gt;let-else&lt;&#x2F;code&gt; statements when it makes my code easier to understand.
If you’re unsure about whether using an expression is worth it, seek feedback from someone less familiar with Rust.
If they look confused, you probably tried to be too clever.&lt;&#x2F;p&gt;
&lt;p&gt;Now, try to refactor some code to train that muscle.&lt;&#x2F;p&gt;
&lt;section class=&quot;footnotes&quot;&gt;
&lt;ol class=&quot;footnotes-list&quot;&gt;
&lt;li id=&quot;fn-reference&quot;&gt;
&lt;p&gt;The &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;doc.rust-lang.org&#x2F;reference&#x2F;statements-and-expressions.html&quot;&gt;Rust Reference&lt;&#x2F;a&gt; puts it like this:
“Rust is primarily an expression language. This means that most forms of value-producing or effect-causing evaluation are directed by the uniform syntax category of expressions. Each kind of expression can typically nest within each other kind of expression, and rules for evaluation of expressions involve specifying both the value produced by the expression and the order in which its sub-expressions are themselves evaluated.” &lt;a href=&quot;#fr-reference-1&quot;&gt;↩&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;&#x2F;li&gt;
&lt;li id=&quot;fn-let-else-statement&quot;&gt;
&lt;p&gt;By the way, &lt;code&gt;let-else&lt;&#x2F;code&gt; is not an expression, but a statement. That’s because the &lt;code&gt;else&lt;&#x2F;code&gt; branch doesn’t produce a value. Instead, it moves the “failure” case into the body block, while allowing the “success” case to continue in the surrounding context without additional nesting.  I recommend reading the &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;rust-lang.github.io&#x2F;rfcs&#x2F;3137-let-else.html&quot;&gt;RFC&lt;&#x2F;a&gt; for more details. &lt;a href=&quot;#fr-let-else-statement-1&quot;&gt;↩&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;&#x2F;section&gt;
</description>
      </item>
      <item>
          <title>Prototyping in Rust</title>
          <pubDate>Wed, 15 Jan 2025 00:00:00 +0000</pubDate>
          <author>Matthias Endler</author>
          <link>https://corrode.dev/blog/prototyping/</link>
          <guid>https://corrode.dev/blog/prototyping/</guid>
          <description xml:base="https://corrode.dev/blog/prototyping/">&lt;p&gt;Programming is an iterative process.
As much as we would like to come up with the perfect solution from the start, it rarely works that way.&lt;&#x2F;p&gt;
&lt;p&gt;Good programs often begin as quick prototypes.
While many experiments remain prototypes, the best programs can evolve into production code.&lt;&#x2F;p&gt;
&lt;p&gt;Whether you’re writing games, CLI tools, or designing library APIs, prototyping helps tremendously in finding the best approach before committing to a design.
It often helps reveal the patterns behind more idiomatic code.&lt;&#x2F;p&gt;
&lt;p&gt;For all its explicitness, Rust is surprisingly ergonomic when iterating on ideas. Contrary to popular belief, it is a joy for building prototypes.&lt;&#x2F;p&gt;
&lt;p&gt;You don’t need to be a Rust expert to be productive - in fact, many of the techniques we’ll discuss specifically help you &lt;em&gt;sidestep&lt;&#x2F;em&gt; Rust’s more advanced features.
If you focus on simple patterns and make use of Rust’s excellent tooling, even less experienced Rust developers can quickly bring their ideas to life.&lt;&#x2F;p&gt;
&lt;div class=&quot;info&quot;&gt;
  
  &lt;div class=&quot;info-header&quot;&gt;
    
      &lt;span class=&quot;icon icon-radio&quot;&gt;&lt;&#x2F;span&gt;
    
    &lt;h4&gt;&lt;p&gt;Feel like listening instead?&lt;&#x2F;p&gt;
&lt;&#x2F;h4&gt;
  &lt;&#x2F;div&gt;
  
  &lt;p&gt;I talked about prototyping in Rust on SE Radio.
The article was the basis for the episode, so you can listen to it while reading along.&lt;&#x2F;p&gt;
&lt;iframe src=&quot;https:&#x2F;&#x2F;play.libsyn.com&#x2F;embed&#x2F;episode&#x2F;id&#x2F;36781410&#x2F;height&#x2F;128&#x2F;theme&#x2F;modern&#x2F;size&#x2F;standard&#x2F;thumbnail&#x2F;yes&#x2F;custom-color&#x2F;ffffff&#x2F;time-start&#x2F;00:00:00&#x2F;playlist-height&#x2F;200&#x2F;direction&#x2F;backward&#x2F;download&#x2F;yes&#x2F;hide-subscribe&#x2F;no&#x2F;hide-share&#x2F;no&quot; width=&quot;100%&quot; height=&quot;128&quot; scrolling=&quot;yes&quot; class=&quot;iframe-class&quot; frameborder=&quot;0&quot;&gt;&lt;&#x2F;iframe&gt;
&lt;&#x2F;div&gt;
&lt;h2 id=&quot;why-people-think-rust-is-not-good-for-prototyping&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#why-people-think-rust-is-not-good-for-prototyping&quot; aria-label=&quot;Anchor link for: why-people-think-rust-is-not-good-for-prototyping&quot;&gt;Why People Think Rust Is Not Good For Prototyping&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;p&gt;The common narrative goes like this:&lt;&#x2F;p&gt;
&lt;blockquote&gt;
&lt;p&gt;When you start writing a program, you don’t know what you want and you change your mind pretty often.
Rust pushes back when you change your mind because the type system is very strict.
On top of that, getting your idea to compile takes longer than in other languages, so the feedback loop is slower.&lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
&lt;p&gt;I’ve found that developers not yet too familiar with Rust often share this preconception.
These developers stumble over the strict type system and the borrow checker while trying to sketch out a solution.
They believe that with Rust you’re either at 0% or 100% done (everything works and has no undefined behavior) and there’s nothing in between.&lt;&#x2F;p&gt;
&lt;p&gt;Here are some typical misbeliefs:&lt;&#x2F;p&gt;
&lt;ol&gt;
&lt;li&gt;“Memory safety and prototyping just don’t go together.”&lt;&#x2F;li&gt;
&lt;li&gt;“Ownership and borrowing take the fun out of prototyping.”&lt;&#x2F;li&gt;
&lt;li&gt;“You have to get all the details right from the beginning.”&lt;&#x2F;li&gt;
&lt;li&gt;“Rust always requires you to handle errors.”&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;p&gt;These are all &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;medium.com&#x2F;@victor.ronin&#x2F;love-hate-relationship-with-rust-language-part-2-c36f57d5485d&quot;&gt;common misconceptions&lt;&#x2F;a&gt; and they are not true.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;strong&gt;It turns out you can avoid all of these pitfalls and still get a lot of value from prototyping in Rust.&lt;&#x2F;strong&gt;&lt;&#x2F;p&gt;
&lt;h2 id=&quot;problems-with-prototyping-in-other-languages&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#problems-with-prototyping-in-other-languages&quot; aria-label=&quot;Anchor link for: problems-with-prototyping-in-other-languages&quot;&gt;Problems with Prototyping in Other Languages&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;p&gt;If you’re happy with a scripting language like Python, why bother with Rust?&lt;&#x2F;p&gt;
&lt;p&gt;That’s a fair question!
After all, Python is known for its quick feedback loop and dynamic type system, and you can always rewrite the code in Rust later.&lt;&#x2F;p&gt;
&lt;p&gt;Yes, Python is a great choice for prototyping.
But I’ve been a Python developer for long enough to know that I’ll very quickly grow out of the “prototype” phase
-– which is when the language falls apart for me.&lt;&#x2F;p&gt;
&lt;p&gt;One thing I found particularly challenging in Python was hardening my prototype into a robust, production-ready codebase.
I’ve found that the really hard bugs in Python are often type-related: deep down in your call chain, the program crashes because you just passed the wrong type to a function.
Because of that, I find myself wanting to switch to something more robust as soon as my prototype starts to take shape.&lt;&#x2F;p&gt;
&lt;p&gt;The problem is that switching languages is a &lt;em&gt;huge&lt;&#x2F;em&gt; undertaking – especially mid-project.
Maybe you’ll have to maintain two codebases simultaneously for a while.
On top of that, Rust follows different idioms than Python, so you might have to rethink the software architecture.
And to add insult to injury, you have to change build systems, testing frameworks, and deployment pipelines as well.&lt;&#x2F;p&gt;
&lt;p&gt;Wouldn’t it be nice if you could use a single language for prototyping and production?&lt;&#x2F;p&gt;
&lt;h2 id=&quot;what-makes-rust-great-for-prototyping&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#what-makes-rust-great-for-prototyping&quot; aria-label=&quot;Anchor link for: what-makes-rust-great-for-prototyping&quot;&gt;What Makes Rust Great for Prototyping?&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;p&gt;Using a single language across your entire project lifecycle is great for productivity.
Rust scales from proof-of-concept to production deployment and that eliminates costly context switches and rewrites.
Rust’s strong type system catches design flaws early, but we will see how it also provides pragmatic escape hatches if needed.
This means prototypes can naturally evolve into production code;
even the first version is often production-ready.&lt;&#x2F;p&gt;
&lt;p&gt;But don’t take my word for it. Here’s what Discord had to say about migrating from Go to Rust:&lt;&#x2F;p&gt;
&lt;blockquote&gt;
&lt;p&gt;Remarkably, we had only put very basic thought into optimization as the Rust version was written. Even with just basic optimization, Rust was able to outperform the hyper hand-tuned Go version. This is a huge testament to how easy it is to write efficient programs with Rust compared to the deep dive we had to do with Go.
– From &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;discord.com&#x2F;blog&#x2F;why-discord-is-switching-from-go-to-rust&quot;&gt;Why Discord is switching from Go to Rust&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
&lt;h2 id=&quot;what-a-solid-rust-prototyping-workflow-looks-like&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#what-a-solid-rust-prototyping-workflow-looks-like&quot; aria-label=&quot;Anchor link for: what-a-solid-rust-prototyping-workflow-looks-like&quot;&gt;What A Solid Rust Prototyping Workflow Looks Like&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;p&gt;If you start with Rust, you get a lot of benefits out of the box:
a robust codebase, a strong type system, and built-in &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;doc.rust-lang.org&#x2F;clippy&#x2F;&quot;&gt;linting&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;All without having to change languages mid-project!
It saves you the context switch between languages once you’re done with the prototype.&lt;&#x2F;p&gt;
&lt;img src=&quot;flow.svg&quot; alt=&quot;flow&quot; class=&quot;natural&quot;&gt;
&lt;p&gt;Python has a few good traits that we can learn from:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;fast feedback loop&lt;&#x2F;li&gt;
&lt;li&gt;changing your mind is easy&lt;&#x2F;li&gt;
&lt;li&gt;it’s simple to use (if you ignore the edge cases)&lt;&#x2F;li&gt;
&lt;li&gt;very little boilerplate&lt;&#x2F;li&gt;
&lt;li&gt;it’s easy to experiment and refactor&lt;&#x2F;li&gt;
&lt;li&gt;you can do something useful in just a few lines&lt;&#x2F;li&gt;
&lt;li&gt;no compilation step&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;The goal is to get as close to that experience in Rust as possible while staying true to Rust’s core principles.
Let’s make changes quick and painless and rapidly iterate on our design without painting ourselves into a corner.
(And yes, there will still be a compilation step, but hopefully, a quick one.)&lt;&#x2F;p&gt;
&lt;h2 id=&quot;tips-and-tricks-for-prototyping-in-rust&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#tips-and-tricks-for-prototyping-in-rust&quot; aria-label=&quot;Anchor link for: tips-and-tricks-for-prototyping-in-rust&quot;&gt;Tips And Tricks For Prototyping In Rust&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;h3 id=&quot;use-simple-types&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#use-simple-types&quot; aria-label=&quot;Anchor link for: use-simple-types&quot;&gt;Use simple types&lt;&#x2F;a&gt;&lt;&#x2F;h3&gt;
&lt;p&gt;Even while prototyping, the type system is not going away.
There are ways to make this a blessing rather than a curse.&lt;&#x2F;p&gt;
&lt;p&gt;Use simple types like &lt;code&gt;i32&lt;&#x2F;code&gt;, &lt;code&gt;String&lt;&#x2F;code&gt;, &lt;code&gt;Vec&lt;&#x2F;code&gt; in the beginning.
We can always make things more complex later if we have to – the reverse is much harder.&lt;&#x2F;p&gt;
&lt;p&gt;Here’s a quick reference for common prototype-to-production type transitions:&lt;&#x2F;p&gt;
&lt;table&gt;&lt;thead&gt;&lt;tr&gt;&lt;th&gt;Prototype&lt;&#x2F;th&gt;&lt;th&gt;Production&lt;&#x2F;th&gt;&lt;th&gt;When to switch&lt;&#x2F;th&gt;&lt;&#x2F;tr&gt;&lt;&#x2F;thead&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;String&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;&lt;td&gt;&lt;code&gt;&amp;amp;str&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;&lt;td&gt;When you need to avoid allocations or store string data with a clear lifetime&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;Vec&amp;lt;T&amp;gt;&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;&lt;td&gt;&lt;code&gt;&amp;amp;[T]&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;&lt;td&gt;When the owned vector becomes too expensive to clone or you can’t afford the heap&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;Box&amp;lt;T&amp;gt;&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;&lt;td&gt;&lt;code&gt;&amp;amp;T&lt;&#x2F;code&gt; or &lt;code&gt;&amp;amp;mut T&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;&lt;td&gt;When &lt;code&gt;Box&lt;&#x2F;code&gt; becomes a bottleneck or you don’t want to deal with heap allocations&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;Rc&amp;lt;T&amp;gt;&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;&lt;td&gt;&lt;code&gt;&amp;amp;T&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;&lt;td&gt;When the reference counting overhead becomes too expensive or you need mutability&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;Arc&amp;lt;Mutex&amp;lt;T&amp;gt;&amp;gt;&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;&lt;td&gt;&lt;code&gt;&amp;amp;mut T&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;&lt;td&gt;When you can guarantee exclusive access and don’t need thread safety&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;&#x2F;tbody&gt;&lt;&#x2F;table&gt;
&lt;p&gt;These owned types sidestep most ownership and lifetime issues, but they do it by allocating memory on the heap - just like Python or JavaScript would.&lt;&#x2F;p&gt;
&lt;p&gt;You can always refactor when you actually need the performance or tighter resource usage, but chances are you won’t.&lt;sup class=&quot;footnote-reference&quot; id=&quot;fr-1-1&quot;&gt;&lt;a href=&quot;#fn-1&quot;&gt;1&lt;&#x2F;a&gt;&lt;&#x2F;sup&gt;&lt;&#x2F;p&gt;
&lt;h3 id=&quot;make-use-of-type-inference&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#make-use-of-type-inference&quot; aria-label=&quot;Anchor link for: make-use-of-type-inference&quot;&gt;Make use of type inference&lt;&#x2F;a&gt;&lt;&#x2F;h3&gt;
&lt;p&gt;Rust is a statically, strongly typed language.
It would be a deal-breaker to write out all the types all the time if it weren’t for Rust’s type inference.&lt;&#x2F;p&gt;
&lt;p&gt;You can often omit (“elide”) the types and let the compiler figure it out from the context.&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;let&lt;&#x2F;span&gt;&lt;span&gt; x&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt; 42&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;let&lt;&#x2F;span&gt;&lt;span&gt; y&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt; &amp;quot;hello&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;let&lt;&#x2F;span&gt;&lt;span&gt; z&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; vec!&lt;&#x2F;span&gt;&lt;span&gt;[&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt;1&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt; 2&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt; 3&lt;&#x2F;span&gt;&lt;span&gt;];&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;This is a great way to get started quickly and defer the decision about types to later.
The system scales well with more complex types, so you can use this technique even in larger projects.&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;let&lt;&#x2F;span&gt;&lt;span&gt; x&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Vec&lt;&#x2F;span&gt;&lt;span&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;i32&lt;&#x2F;span&gt;&lt;span&gt;&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; vec!&lt;&#x2F;span&gt;&lt;span&gt;[&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt;1&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt; 2&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt; 3&lt;&#x2F;span&gt;&lt;span&gt;];&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;let&lt;&#x2F;span&gt;&lt;span&gt; y&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Vec&lt;&#x2F;span&gt;&lt;span&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;i32&lt;&#x2F;span&gt;&lt;span&gt;&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; vec!&lt;&#x2F;span&gt;&lt;span&gt;[&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt;4&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt; 5&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt; 6&lt;&#x2F;span&gt;&lt;span&gt;];&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;&#x2F;&#x2F; From the context, Rust knows that `z` needs to be a `Vec&amp;lt;i32&amp;gt;`&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;&#x2F;&#x2F; The `_` is a placeholder for the type that Rust will infer&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;let&lt;&#x2F;span&gt;&lt;span&gt; z&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; x&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;into_iter&lt;&#x2F;span&gt;&lt;span&gt;()&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;chain&lt;&#x2F;span&gt;&lt;span&gt;(y&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;into_iter&lt;&#x2F;span&gt;&lt;span&gt;())&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;collect&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;Vec&lt;&#x2F;span&gt;&lt;span&gt;&amp;lt;_&amp;gt;&amp;gt;();&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Here’s a more complex example which shows just how powerful Rust’s type inference can be:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;use&lt;&#x2F;span&gt;&lt;span&gt; std&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span&gt;collections&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;HashMap&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;&#x2F;&#x2F; Start with some nested data&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;let&lt;&#x2F;span&gt;&lt;span&gt; data&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; vec!&lt;&#x2F;span&gt;&lt;span&gt;[&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    (&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt;&amp;quot;fruits&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; vec!&lt;&#x2F;span&gt;&lt;span&gt;[&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt;&amp;quot;apple&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt; &amp;quot;banana&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;]),&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    (&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt;&amp;quot;vegetables&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; vec!&lt;&#x2F;span&gt;&lt;span&gt;[&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt;&amp;quot;carrot&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt; &amp;quot;potato&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;]),&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;];&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;&#x2F;&#x2F; Let Rust figure out this complex transformation&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;&#x2F;&#x2F; Can you tell what the type of `categorized` is?&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;let&lt;&#x2F;span&gt;&lt;span&gt; categorized&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; data&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    .&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;into_iter&lt;&#x2F;span&gt;&lt;span&gt;()&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    .&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;flat_map&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;|&lt;&#x2F;span&gt;&lt;span&gt;(category, items)&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;|&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        items&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;into_iter&lt;&#x2F;span&gt;&lt;span&gt;()&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;map&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;move |&lt;&#x2F;span&gt;&lt;span&gt;item&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;|&lt;&#x2F;span&gt;&lt;span&gt; (item, category))&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    })&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    .&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;collect&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;HashMap&lt;&#x2F;span&gt;&lt;span&gt;&amp;lt;_, _&amp;gt;&amp;gt;();&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;&#x2F;&#x2F; categorized is now a HashMap&amp;lt;&amp;amp;str, &amp;amp;str&amp;gt; mapping items to their categories&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;println!&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt;&amp;quot;What type is banana? {}&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;, categorized&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;get&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt;&amp;quot;banana&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;unwrap&lt;&#x2F;span&gt;&lt;span&gt;());&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;(&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;play.rust-lang.org&#x2F;?version=stable&amp;amp;mode=debug&amp;amp;edition=2021&amp;amp;gist=fac339eecef40b69b919a1670a0a53df&quot;&gt;Playground&lt;&#x2F;a&gt;)&lt;&#x2F;p&gt;
&lt;p&gt;It’s not easy to visualize the structure of &lt;code&gt;categorized&lt;&#x2F;code&gt; in your head, but Rust can figure it out.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;use-the-rust-playground&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#use-the-rust-playground&quot; aria-label=&quot;Anchor link for: use-the-rust-playground&quot;&gt;Use the Rust playground&lt;&#x2F;a&gt;&lt;&#x2F;h3&gt;
&lt;p&gt;You probably already know about the &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;play.rust-lang.org&quot;&gt;Rust Playground&lt;&#x2F;a&gt;.
The playground doesn’t support auto-complete, but it’s still great when you’re on the go or you’d like to share your code with others.&lt;&#x2F;p&gt;
&lt;p&gt;I find it quite useful for quickly jotting down a bunch of functions or types to test out a design idea.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;use-unwrap-liberally&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#use-unwrap-liberally&quot; aria-label=&quot;Anchor link for: use-unwrap-liberally&quot;&gt;Use &lt;code&gt;unwrap&lt;&#x2F;code&gt; Liberally&lt;&#x2F;a&gt;&lt;&#x2F;h3&gt;
&lt;p&gt;It’s okay to use &lt;code&gt;unwrap&lt;&#x2F;code&gt; in the early stages of your project.
An explicit &lt;code&gt;unwrap&lt;&#x2F;code&gt; is like a stop sign that tells you “here’s something you need to fix later.”
You can easily grep for &lt;code&gt;unwrap&lt;&#x2F;code&gt; and replace it with proper error handling later when you polish your code.
This way, you get the best of both worlds: quick iteration cycles and a clear path to robust error handling.
There’s also a &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;rust-lang.github.io&#x2F;rust-clippy&#x2F;master&#x2F;index.html#unwrap_used&quot;&gt;clippy lint&lt;&#x2F;a&gt; that points out all the &lt;code&gt;unwrap&lt;&#x2F;code&gt;s in your code.&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;use&lt;&#x2F;span&gt;&lt;span&gt; std&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span&gt;fs;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;use&lt;&#x2F;span&gt;&lt;span&gt; std&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span&gt;path&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;PathBuf&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;fn&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; main&lt;&#x2F;span&gt;&lt;span&gt;() {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;    &#x2F;&#x2F; Quick and dirty path handling during prototyping&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    let&lt;&#x2F;span&gt;&lt;span&gt; home&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; std&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span&gt;env&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;var&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt;&amp;quot;HOME&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;unwrap&lt;&#x2F;span&gt;&lt;span&gt;();&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    let&lt;&#x2F;span&gt;&lt;span&gt; config_path&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; PathBuf&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;from&lt;&#x2F;span&gt;&lt;span&gt;(home)&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;join&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt;&amp;quot;.config&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;join&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt;&amp;quot;myapp&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;    &#x2F;&#x2F; Create config directory if it doesn&amp;#39;t exist&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    fs&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;create_dir_all&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;&amp;amp;&lt;&#x2F;span&gt;&lt;span&gt;config_path)&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;unwrap&lt;&#x2F;span&gt;&lt;span&gt;();&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;    &#x2F;&#x2F; Read the config file, defaulting to empty string if it doesn&amp;#39;t exist&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    let&lt;&#x2F;span&gt;&lt;span&gt; config_file&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; config_path&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;join&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt;&amp;quot;config.json&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    let&lt;&#x2F;span&gt;&lt;span&gt; config_content&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; fs&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;read_to_string&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;&amp;amp;&lt;&#x2F;span&gt;&lt;span&gt;config_file)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;        .&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;unwrap_or_default&lt;&#x2F;span&gt;&lt;span&gt;();&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;    &#x2F;&#x2F; Parse the JSON config&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    let&lt;&#x2F;span&gt;&lt;span&gt; config&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span&gt; serde_json&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;Value&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; = if !&lt;&#x2F;span&gt;&lt;span&gt;config_content&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;is_empty&lt;&#x2F;span&gt;&lt;span&gt;() {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        serde_json&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;from_str&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;&amp;amp;&lt;&#x2F;span&gt;&lt;span&gt;config_content)&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;unwrap&lt;&#x2F;span&gt;&lt;span&gt;()&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    }&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; else&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        serde_json&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;json!&lt;&#x2F;span&gt;&lt;span&gt;({})&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    };&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;    println!&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt;&amp;quot;Loaded config: {:?}&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;, config);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;See all those unwraps?
To more experienced Rustaceans, they stand out like a sore thumb – and that’s a good thing!&lt;&#x2F;p&gt;
&lt;p&gt;Compare that to languages like JavaScript which can throw exceptions your way at any time.
It’s much harder to ensure that you handle all the edge-cases correctly.
At the very least, it costs time. Time you could spend on more important things.&lt;&#x2F;p&gt;
&lt;p&gt;While prototyping with Rust, you can safely ignore error handling and focus on
the happy path without losing track of improvement areas.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;add-anyhow-to-your-prototypes&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#add-anyhow-to-your-prototypes&quot; aria-label=&quot;Anchor link for: add-anyhow-to-your-prototypes&quot;&gt;Add &lt;code&gt;anyhow&lt;&#x2F;code&gt; to your prototypes&lt;&#x2F;a&gt;&lt;&#x2F;h3&gt;
&lt;p&gt;I like to add &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;dtolnay&#x2F;anyhow&quot;&gt;&lt;code&gt;anyhow&lt;&#x2F;code&gt;&lt;&#x2F;a&gt; pretty early during the prototyping phase,
to get more fine-grained control over my error handling.
This way, I can use &lt;code&gt;bail!&lt;&#x2F;code&gt; and &lt;code&gt;with_context&lt;&#x2F;code&gt; to quickly add more context to my errors without losing momentum.
Later on, I can revisit each error case and see if I can handle it more gracefully.&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;use&lt;&#x2F;span&gt;&lt;span&gt; anyhow&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span&gt;{bail,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Context&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Result&lt;&#x2F;span&gt;&lt;span&gt;};&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;&#x2F;&#x2F; Here&amp;#39;s how to use `with_context` to add more context to an error&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;let&lt;&#x2F;span&gt;&lt;span&gt; home&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; std&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span&gt;env&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;var&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt;&amp;quot;HOME&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    .&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;with_context&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;||&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt; &amp;quot;Could not read HOME environment variable&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;?&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;&#x2F;&#x2F; ...alternatively, use `bail` to return an error immediately &lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;let&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Ok&lt;&#x2F;span&gt;&lt;span&gt;(home)&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; std&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span&gt;env&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;var&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt;&amp;quot;HOME&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; else&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;    bail!&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt;&amp;quot;Could not read HOME environment variable&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;};&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;The great thing about &lt;code&gt;anyhow&lt;&#x2F;code&gt; is that it’s a solid choice for error handling in production code as well,
so you don’t have to rewrite your error handling logic later on.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;use-a-good-ide&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#use-a-good-ide&quot; aria-label=&quot;Anchor link for: use-a-good-ide&quot;&gt;Use a good IDE&lt;&#x2F;a&gt;&lt;&#x2F;h3&gt;
&lt;p&gt;There is great IDE support for Rust.&lt;&#x2F;p&gt;
&lt;p&gt;IDEs can help you with code completion and refactoring, which keep you in the flow and help you write code faster.
Autocompletion is so much better with Rust than with dynamic languages because the type system gives the IDE a lot more information to work with.&lt;&#x2F;p&gt;
&lt;p&gt;As a corollary to the previous section, be sure to use enable inlay hints (or inline type hints) in your editor.
This way, you can quickly see the inferred types right inside your IDE and make sure the types match your expectations.
There’s support for this in most Rust IDEs, including &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.jetbrains.com&#x2F;help&#x2F;rust&#x2F;viewing-reference-information.html#inlay-hints&quot;&gt;RustRover&lt;&#x2F;a&gt; and &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;code.visualstudio.com&#x2F;docs&#x2F;typescript&#x2F;typescript-editing#_inlay-hints&quot;&gt;Visual Studio Code&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;img src=&quot;https:&#x2F;&#x2F;corrode.dev&#x2F;blog&#x2F;prototyping&#x2F;inlay-hints.png&quot; alt=&quot;Inlay hints in Rust Rover&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;h3 id=&quot;use-bacon-for-quick-feedback-cycles&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#use-bacon-for-quick-feedback-cycles&quot; aria-label=&quot;Anchor link for: use-bacon-for-quick-feedback-cycles&quot;&gt;Use &lt;code&gt;bacon&lt;&#x2F;code&gt; for quick feedback cycles&lt;&#x2F;a&gt;&lt;&#x2F;h3&gt;
&lt;p&gt;Rust is not a scripting language; there is a compile step!&lt;&#x2F;p&gt;
&lt;p&gt;However, for small projects, the compile times are negligible.
Unfortunately, you have to manually run &lt;code&gt;cargo check&lt;&#x2F;code&gt; every time you make a change
or use &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;rust-analyzer.github.io&#x2F;&quot;&gt;rust-analyzer&lt;&#x2F;a&gt; in your editor to get instant feedback.&lt;&#x2F;p&gt;
&lt;p&gt;To fill the gap, you can use external tools like &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;Canop&#x2F;bacon&quot;&gt;&lt;code&gt;bacon&lt;&#x2F;code&gt;&lt;&#x2F;a&gt; which automatically recompiles and runs your code whenever you make a change.
This way, you can get &lt;em&gt;almost&lt;&#x2F;em&gt; the same experience as with a REPL in, say, Python or Ruby.&lt;&#x2F;p&gt;
&lt;p&gt;The setup is simple:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;shellscript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;# Install bacon&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;cargo&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt; install&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt; --locked&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt; bacon&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;# Run bacon in your project directory&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;bacon&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;And just like that, you can get some pretty compilation output alongside your code editor.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;img src=&quot;https:&#x2F;&#x2F;corrode.dev&#x2F;blog&#x2F;prototyping&#x2F;bacon.png&quot; alt=&quot;bacon&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;p&gt;Oh, and in case you were wondering, &lt;code&gt;cargo-watch&lt;&#x2F;code&gt; was another popular tool for
this purpose, but it’s since been &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;watchexec&#x2F;cargo-watch#maintenance&quot;&gt;deprecated&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;cargo-script-is-awesome&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#cargo-script-is-awesome&quot; aria-label=&quot;Anchor link for: cargo-script-is-awesome&quot;&gt;&lt;code&gt;cargo-script&lt;&#x2F;code&gt; is awesome&lt;&#x2F;a&gt;&lt;&#x2F;h3&gt;
&lt;p&gt;Did you know that cargo can also run scripts?&lt;&#x2F;p&gt;
&lt;p&gt;For example, put this into a file called &lt;code&gt;script.rs&lt;&#x2F;code&gt;:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;#&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;!&#x2F;&lt;&#x2F;span&gt;&lt;span&gt;usr&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;&#x2F;&lt;&#x2F;span&gt;&lt;span&gt;bin&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;&#x2F;&lt;&#x2F;span&gt;&lt;span&gt;env cargo&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; +&lt;&#x2F;span&gt;&lt;span&gt;nightly&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; -&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;Zscript&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;fn&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; main&lt;&#x2F;span&gt;&lt;span&gt;() {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;    println!&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt;&amp;quot;Hello prototyping world&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Now you can make the file executable with &lt;code&gt;chmod +x script.rs&lt;&#x2F;code&gt; and run it with &lt;code&gt;.&#x2F;script.rs&lt;&#x2F;code&gt; which it will compile and execute your code!
This allows you to quickly test out ideas without having to create a new project.
There is support for dependencies as well.&lt;&#x2F;p&gt;
&lt;p&gt;At the moment, &lt;code&gt;cargo-script&lt;&#x2F;code&gt; is a nightly feature, but it will be released soon on stable Rust.
You can read more about it in the &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;rust-lang.github.io&#x2F;rfcs&#x2F;3424-cargo-script.html&quot;&gt;RFC&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;don-t-worry-about-performance&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#don-t-worry-about-performance&quot; aria-label=&quot;Anchor link for: don-t-worry-about-performance&quot;&gt;Don’t worry about performance&lt;&#x2F;a&gt;&lt;&#x2F;h3&gt;
&lt;p&gt;You have to try really really hard to write slow code in Rust.
Use that to your advantage: during the prototype phase, try to keep the code as simple as possible.&lt;&#x2F;p&gt;
&lt;p&gt;I gave a talk titled &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;corrode&#x2F;four-horsemen-talk&quot;&gt;“The Four Horsemen of Bad Rust Code”&lt;&#x2F;a&gt; where I
argue that premature optimization is one of the biggest sins in Rust.&lt;&#x2F;p&gt;
&lt;p&gt;Especially experienced developers coming from C or C++ are tempted to optimize too early.&lt;&#x2F;p&gt;
&lt;p&gt;Rust makes code perform well by default - you get memory safety at virtually zero runtime cost. When developers try to optimize too early, they often run up against the borrow checker by using complex lifetime annotations and intricate reference patterns in pursuit of better performance.
This leads to harder-to-maintain code that may not actually run faster.&lt;&#x2F;p&gt;
&lt;p&gt;Resist the urge to optimize too early!
You will thank yourself later. &lt;sup class=&quot;footnote-reference&quot; id=&quot;fr-2-1&quot;&gt;&lt;a href=&quot;#fn-2&quot;&gt;2&lt;&#x2F;a&gt;&lt;&#x2F;sup&gt;&lt;&#x2F;p&gt;
&lt;h3 id=&quot;use-println-and-dbg-for-debugging&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#use-println-and-dbg-for-debugging&quot; aria-label=&quot;Anchor link for: use-println-and-dbg-for-debugging&quot;&gt;Use &lt;code&gt;println!&lt;&#x2F;code&gt; and &lt;code&gt;dbg!&lt;&#x2F;code&gt; for debugging&lt;&#x2F;a&gt;&lt;&#x2F;h3&gt;
&lt;p&gt;I find that printing values is pretty handy while prototyping.
It’s one less context switch to make compared to starting a debugger.&lt;&#x2F;p&gt;
&lt;p&gt;Most people use &lt;code&gt;println!&lt;&#x2F;code&gt; for that, but &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;doc.rust-lang.org&#x2F;std&#x2F;macro.dbg.html&quot;&gt;&lt;code&gt;dbg!&lt;&#x2F;code&gt;&lt;&#x2F;a&gt; has a few advantages:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;It prints the file name and line number where the macro is called. This helps you quickly find the source of the output.&lt;&#x2F;li&gt;
&lt;li&gt;It outputs the expression as well as its value.&lt;&#x2F;li&gt;
&lt;li&gt;It’s less syntax-heavy than &lt;code&gt;println!&lt;&#x2F;code&gt;; e.g. &lt;code&gt;dbg!(x)&lt;&#x2F;code&gt; vs. &lt;code&gt;println!(&quot;{x:?}&quot;)&lt;&#x2F;code&gt;.&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;Where &lt;code&gt;dbg!&lt;&#x2F;code&gt; really shines is in recursive functions or when you want to see the intermediate values during an iteration:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;fn&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; factorial&lt;&#x2F;span&gt;&lt;span&gt;(n&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; u32&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; -&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; u32&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;    &#x2F;&#x2F; `dbg!` returns the argument, &lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;    &#x2F;&#x2F; so you can use it in the middle of an expression&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    if&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; dbg!&lt;&#x2F;span&gt;&lt;span&gt;(n&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; &amp;lt;=&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt; 1&lt;&#x2F;span&gt;&lt;span&gt;) {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;        dbg!&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt;1&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    }&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; else&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;        dbg!&lt;&#x2F;span&gt;&lt;span&gt;(n&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; *&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; factorial&lt;&#x2F;span&gt;&lt;span&gt;(n&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; -&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt; 1&lt;&#x2F;span&gt;&lt;span&gt;))&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;dbg!&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;factorial&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt;4&lt;&#x2F;span&gt;&lt;span&gt;));&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;The output is nice and tidy:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;[src&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;&#x2F;&lt;&#x2F;span&gt;&lt;span&gt;main&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span&gt;rs&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt;2&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt;8&lt;&#x2F;span&gt;&lt;span&gt;] n&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; &amp;lt;=&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt; 1&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt; false&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;[src&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;&#x2F;&lt;&#x2F;span&gt;&lt;span&gt;main&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span&gt;rs&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt;2&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt;8&lt;&#x2F;span&gt;&lt;span&gt;] n&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; &amp;lt;=&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt; 1&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt; false&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;[src&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;&#x2F;&lt;&#x2F;span&gt;&lt;span&gt;main&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span&gt;rs&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt;2&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt;8&lt;&#x2F;span&gt;&lt;span&gt;] n&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; &amp;lt;=&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt; 1&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt; false&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;[src&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;&#x2F;&lt;&#x2F;span&gt;&lt;span&gt;main&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span&gt;rs&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt;2&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt;8&lt;&#x2F;span&gt;&lt;span&gt;] n&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; &amp;lt;=&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt; 1&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt; true&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;[src&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;&#x2F;&lt;&#x2F;span&gt;&lt;span&gt;main&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span&gt;rs&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt;3&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt;9&lt;&#x2F;span&gt;&lt;span&gt;]&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt; 1&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt; 1&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;[src&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;&#x2F;&lt;&#x2F;span&gt;&lt;span&gt;main&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span&gt;rs&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt;7&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt;9&lt;&#x2F;span&gt;&lt;span&gt;] n&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; *&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; factorial&lt;&#x2F;span&gt;&lt;span&gt;(n&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; -&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt; 1&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt; 2&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;[src&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;&#x2F;&lt;&#x2F;span&gt;&lt;span&gt;main&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span&gt;rs&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt;7&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt;9&lt;&#x2F;span&gt;&lt;span&gt;] n&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; *&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; factorial&lt;&#x2F;span&gt;&lt;span&gt;(n&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; -&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt; 1&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt; 6&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;[src&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;&#x2F;&lt;&#x2F;span&gt;&lt;span&gt;main&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span&gt;rs&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt;7&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt;9&lt;&#x2F;span&gt;&lt;span&gt;] n&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; *&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; factorial&lt;&#x2F;span&gt;&lt;span&gt;(n&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; -&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt; 1&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt; 24&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;[src&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;&#x2F;&lt;&#x2F;span&gt;&lt;span&gt;main&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span&gt;rs&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt;9&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt;1&lt;&#x2F;span&gt;&lt;span&gt;]&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; factorial&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt;4&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt; 24&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Note that you should not keep the &lt;code&gt;dbg!&lt;&#x2F;code&gt; calls in your final code as they will also be executed in release mode.
If you’re interested, &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;edgarluque.com&#x2F;blog&#x2F;rust-dbg-macro&#x2F;&quot;&gt;here are more details on how to use the &lt;code&gt;dbg!&lt;&#x2F;code&gt; macro&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;design-through-types&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#design-through-types&quot; aria-label=&quot;Anchor link for: design-through-types&quot;&gt;Design through types&lt;&#x2F;a&gt;&lt;&#x2F;h3&gt;
&lt;p&gt;Quite frankly, the type system is one of the main reasons I love Rust.
It feels great to express my ideas in types and see them come to life.
I would encourage you to heavily lean into the type system during the prototyping phase.&lt;&#x2F;p&gt;
&lt;p&gt;In the beginning, you won’t have a good idea of the types in your system.
That’s fine!
Start with &lt;em&gt;something&lt;&#x2F;em&gt; and quickly sketch out solutions and gradually add constraints to model the business requirements.
Don’t stop until you find a version that feels just right.
You know you’ve found a good abstraction when your types “click” with the rest of the code. &lt;sup class=&quot;footnote-reference&quot; id=&quot;fr-3-1&quot;&gt;&lt;a href=&quot;#fn-3&quot;&gt;3&lt;&#x2F;a&gt;&lt;&#x2F;sup&gt;
Try to build up a vocabulary of concepts and own types which describe your system.&lt;&#x2F;p&gt;
&lt;p&gt;Wrestling with Rust’s type system might feel slower at first compared to more dynamic languages, but it often leads to fewer iterations overall.
Think of it this way: in a language like Python, each iteration might be quicker since you can skip type definitions, but you’ll likely need more iterations as you discover edge cases and invariants that weren’t immediately obvious.
In Rust, the type system forces you to think through these relationships up front. Although each iteration takes longer, you typically need fewer of them to arrive at a robust solution.&lt;&#x2F;p&gt;
&lt;p&gt;This is exactly what we’ll see in the following example.&lt;&#x2F;p&gt;
&lt;p&gt;Say you’re modeling course enrollments in a student system. You might start with something simple:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;struct&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Enrollment&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    student&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; StudentId&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    course&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; CourseId&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    is_enrolled&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; bool&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;But then requirements come in: some courses are very popular.
More students want to enroll than there are spots available,
so the school decides to add a waitlist.&lt;&#x2F;p&gt;
&lt;p&gt;Easy, let’s just add another boolean flag!&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;struct&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Enrollment&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    student&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; StudentId&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    course&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; CourseId&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    is_enrolled&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; bool&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    is_waitlisted&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; bool&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt; &#x2F;&#x2F; 🚩 uh oh&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;The problem is that both boolean flags could be set to &lt;code&gt;true&lt;&#x2F;code&gt;!
This design allows invalid states where a student could be both enrolled and waitlisted.&lt;&#x2F;p&gt;
&lt;p&gt;Think for a second how we could leverage Rust’s type system to make this impossible…&lt;&#x2F;p&gt;
&lt;p&gt;Here’s one attempt:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;enum&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; EnrollmentStatus&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;    Active&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        date&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; DateTime&lt;&#x2F;span&gt;&lt;span&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;Utc&lt;&#x2F;span&gt;&lt;span&gt;&amp;gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    },&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;    Waitlisted&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        position&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; u32&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    },&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;struct&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Enrollment&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    student&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; StudentId&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    course&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; CourseId&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    status&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; EnrollmentStatus&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Now we have a clear distinction between an active enrollment and a waitlisted enrollment.
What’s better is that we encapsulate the details of each state in the enum variants.
We can never have someone on the waitlist without a position in said list.&lt;&#x2F;p&gt;
&lt;p&gt;Just think about how much more complicated this would be in a dynamic language
or a language that doesn’t support tagged unions like Rust does.&lt;&#x2F;p&gt;
&lt;p&gt;In summary, iterating on your data model is the crucial part of any prototyping phase.
The result of this phase is not the code, but a &lt;em&gt;deeper understanding of the problem domain itself&lt;&#x2F;em&gt;.
You can harvest this knowledge to build a more robust and maintainable solution.&lt;&#x2F;p&gt;
&lt;p&gt;It turns out you can model a surprisingly large system in just a few lines of code.&lt;&#x2F;p&gt;
&lt;p&gt;So, never be afraid to play around with types and refactor your code as you go.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;the-todo-macro&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#the-todo-macro&quot; aria-label=&quot;Anchor link for: the-todo-macro&quot;&gt;The &lt;code&gt;todo!&lt;&#x2F;code&gt; Macro&lt;&#x2F;a&gt;&lt;&#x2F;h3&gt;
&lt;p&gt;One of the cornerstones of prototyping is that you don’t have to have all the answers right away.
In Rust, I find myself reaching for the &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;doc.rust-lang.org&#x2F;std&#x2F;macro.todo.html&quot;&gt;&lt;code&gt;todo!&lt;&#x2F;code&gt;&lt;&#x2F;a&gt; macro to
express that idea.&lt;&#x2F;p&gt;
&lt;p&gt;I routinely just scaffold out the functions or a module and then fill in the blanks later.&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;&#x2F;&#x2F; We don&amp;#39;t know yet how to process the data&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;&#x2F;&#x2F; but we&amp;#39;re pretty certain that we need a function&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;&#x2F;&#x2F; that takes a Vec&amp;lt;i32&amp;gt; and returns an i32&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;fn&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; process_data&lt;&#x2F;span&gt;&lt;span&gt;(data&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Vec&lt;&#x2F;span&gt;&lt;span&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;i32&lt;&#x2F;span&gt;&lt;span&gt;&amp;gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; -&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; i32&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;    todo!&lt;&#x2F;span&gt;&lt;span&gt;()&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;&#x2F;&#x2F; There exists a function that loads the data and returns a Vec&amp;lt;i32&amp;gt;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;&#x2F;&#x2F; How exactly it does that is not important right now&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;fn&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; load_data&lt;&#x2F;span&gt;&lt;span&gt;()&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; -&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Vec&lt;&#x2F;span&gt;&lt;span&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;i32&lt;&#x2F;span&gt;&lt;span&gt;&amp;gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;    todo!&lt;&#x2F;span&gt;&lt;span&gt;()&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;fn&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; main&lt;&#x2F;span&gt;&lt;span&gt;() {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;    &#x2F;&#x2F; Given that we have a function to load the data&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    let&lt;&#x2F;span&gt;&lt;span&gt; data&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; load_data&lt;&#x2F;span&gt;&lt;span&gt;();&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;    &#x2F;&#x2F; ... and a function to process it&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    let&lt;&#x2F;span&gt;&lt;span&gt; result&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; process_data&lt;&#x2F;span&gt;&lt;span&gt;(data);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;    &#x2F;&#x2F; ... we can print the result&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;    println!&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt;&amp;quot;Result: {}&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;, result);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;We did not do much here, but we have a clear idea of what the program should do.
Now we can go and iterate on the design.
For example, should &lt;code&gt;process_data&lt;&#x2F;code&gt; take a reference to the data?
Should we create a struct to hold the data and the processing logic?
How about using an iterator instead of a vector?
Should we introduce a trait to support algorithms for processing the data?&lt;&#x2F;p&gt;
&lt;p&gt;These are all helpful questions that we can answer without having to worry about the details of the implementation.
And yet our code is typesafe and compiles, and it is ready for refactoring.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;unreachable-for-unreachable-branches&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#unreachable-for-unreachable-branches&quot; aria-label=&quot;Anchor link for: unreachable-for-unreachable-branches&quot;&gt;&lt;code&gt;unreachable!&lt;&#x2F;code&gt; for unreachable branches&lt;&#x2F;a&gt;&lt;&#x2F;h3&gt;
&lt;p&gt;On a related note, you can use the &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;doc.rust-lang.org&#x2F;std&#x2F;macro.unreachable.html&quot;&gt;&lt;code&gt;unreachable!&lt;&#x2F;code&gt;&lt;&#x2F;a&gt; macro to mark branches of your code that should never be reached.&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;fn&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; main&lt;&#x2F;span&gt;&lt;span&gt;() {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    let&lt;&#x2F;span&gt;&lt;span&gt; age&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; u8&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt; 170&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    match&lt;&#x2F;span&gt;&lt;span&gt; age {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt;        0&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;..&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt;150&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; println!&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt;&amp;quot;Normal human age&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;),&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt;        150&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.. =&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; unreachable!&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt;&amp;quot;Witchcraft!&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;),&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;     }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;This is a great way to document your assumptions about the code.
The result is the same as if you had used &lt;code&gt;todo!&lt;&#x2F;code&gt;, but it’s more explicit about the fact that this branch should never be reached:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;thread&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt; &amp;#39;main&amp;#39;&lt;&#x2F;span&gt;&lt;span&gt; panicked at src&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;&#x2F;&lt;&#x2F;span&gt;&lt;span&gt;main&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span&gt;rs&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt;6&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt;18&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;internal error&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span&gt; entered unreachable code&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Witchcraft!&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Note that we added a message to the &lt;code&gt;unreachable!&lt;&#x2F;code&gt; macro to make it clear what the assumption is.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;use-assert-for-invariants&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#use-assert-for-invariants&quot; aria-label=&quot;Anchor link for: use-assert-for-invariants&quot;&gt;Use &lt;code&gt;assert!&lt;&#x2F;code&gt; for invariants&lt;&#x2F;a&gt;&lt;&#x2F;h3&gt;
&lt;p&gt;Another way to document your assumptions is to use the &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;doc.rust-lang.org&#x2F;std&#x2F;macro.assert.html&quot;&gt;&lt;code&gt;assert!&lt;&#x2F;code&gt;&lt;&#x2F;a&gt; macro.
This is especially useful for invariants that should hold true at runtime.&lt;&#x2F;p&gt;
&lt;p&gt;For example, the above code could be rewritten like this:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;fn&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; main&lt;&#x2F;span&gt;&lt;span&gt;() {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    let&lt;&#x2F;span&gt;&lt;span&gt; age&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; u8&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt; 170&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;    assert!&lt;&#x2F;span&gt;&lt;span&gt;(age&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; &amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt; 150&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt; &amp;quot;This is very unlikely to be a human age&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;    println!&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt;&amp;quot;Normal human age&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;During prototyping, this can be helpful to catch logic bugs early on without having to write a lot of tests
and you can safely carry them over to your production code.&lt;&#x2F;p&gt;
&lt;p&gt;Consider using
&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;doc.rust-lang.org&#x2F;std&#x2F;macro.debug_assert.html&quot;&gt;&lt;code&gt;debug_assert!&lt;&#x2F;code&gt;&lt;&#x2F;a&gt; for
expensive invariant checks that should only run in test&#x2F;debug builds.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;avoid-generics&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#avoid-generics&quot; aria-label=&quot;Anchor link for: avoid-generics&quot;&gt;Avoid generics&lt;&#x2F;a&gt;&lt;&#x2F;h3&gt;
&lt;p&gt;Chances are, you won’t know which parts of your application should be generic in the beginning.
Therefore it’s better to be conservative and use concrete types instead of generics until necessary.&lt;&#x2F;p&gt;
&lt;p&gt;So instead of writing this:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;fn&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; foo&lt;&#x2F;span&gt;&lt;span&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;T&lt;&#x2F;span&gt;&lt;span&gt;&amp;gt;(x&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; T&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; -&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; T&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;    &#x2F;&#x2F; ...&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Write this:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;fn&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; foo&lt;&#x2F;span&gt;&lt;span&gt;(x&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; i32&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; -&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; i32&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;    &#x2F;&#x2F; ...&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;If you need the same function for a different type, feel free to just copy and paste the function and change the type.
This way, you avoid the trap of settling on the wrong kind of abstraction too early.
Maybe the two functions only differ by type signature for now, but they might serve a completely different purpose.
If the function is not generic from the start, it’s easier to remove the duplication later.&lt;&#x2F;p&gt;
&lt;p&gt;Only introduce generics when you see a clear pattern emerge in multiple places.
I personally avoid generics up until the very last moment. I want to feel the “pain” of duplication logic before I abstract it away.
In 50% of the cases, I find that the problem is not missing generics, but that there’s a better algorithm or data structure that solves the problem more elegantly.&lt;&#x2F;p&gt;
&lt;p&gt;Also avoid “fancy” generic type signatures:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;fn&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; foo&lt;&#x2F;span&gt;&lt;span&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;T&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; AsRef&lt;&#x2F;span&gt;&lt;span&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;str&lt;&#x2F;span&gt;&lt;span&gt;&amp;gt;&amp;gt;(x&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; T&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; -&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; String&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;    &#x2F;&#x2F; ...&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Yes, this allows you to pass in a &lt;code&gt;&amp;amp;str&lt;&#x2F;code&gt; or a &lt;code&gt;String&lt;&#x2F;code&gt;, but at the cost of readability.&lt;&#x2F;p&gt;
&lt;p&gt;Just use an owned type for your first implementation:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;fn&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; foo&lt;&#x2F;span&gt;&lt;span&gt;(x&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; String&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; -&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; String&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;    &#x2F;&#x2F; ...&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Chances are, you won’t need the flexibility after all.&lt;&#x2F;p&gt;
&lt;p&gt;In summary, generics are powerful, but they can make the code harder to read and write.
Avoid them until you have a clear idea of what you’re doing.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;avoid-lifetimes&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#avoid-lifetimes&quot; aria-label=&quot;Anchor link for: avoid-lifetimes&quot;&gt;Avoid Lifetimes&lt;&#x2F;a&gt;&lt;&#x2F;h3&gt;
&lt;p&gt;One major blocker for rapid prototyping is Rust’s ownership system.
If the compiler constantly reminds you of borrows and lifetimes it can ruin your flow.
For example, it’s cumbersome to deal with references when you’re just trying to get something to work.&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;&#x2F;&#x2F; First attempt with references - compiler error!&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;struct&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Note&lt;&#x2F;span&gt;&lt;span&gt;&amp;lt;&amp;#39;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;a&lt;&#x2F;span&gt;&lt;span&gt;&amp;gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    title&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;: &amp;amp;&lt;&#x2F;span&gt;&lt;span&gt;&amp;#39;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;a str&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    content&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;: &amp;amp;&lt;&#x2F;span&gt;&lt;span&gt;&amp;#39;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;a str&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;fn&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; create_note&lt;&#x2F;span&gt;&lt;span&gt;()&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; -&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Note&lt;&#x2F;span&gt;&lt;span&gt;&amp;lt;&amp;#39;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;_&lt;&#x2F;span&gt;&lt;span&gt;&amp;gt; {&lt;&#x2F;span&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;  &#x2F;&#x2F; ❌ lifetime error&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    let&lt;&#x2F;span&gt;&lt;span&gt; title&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; String&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;from&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt;&amp;quot;Draft&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    let&lt;&#x2F;span&gt;&lt;span&gt; content&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; String&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;from&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt;&amp;quot;My first note&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;    Note&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        title&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;: &amp;amp;&lt;&#x2F;span&gt;&lt;span&gt;title,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        content&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;: &amp;amp;&lt;&#x2F;span&gt;&lt;span&gt;content&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;This code doesn’t compile because the references are not valid outside of the function.&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;   Compiling&lt;&#x2F;span&gt;&lt;span&gt; playground v0&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt;0.1&lt;&#x2F;span&gt;&lt;span&gt; (&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;&#x2F;&lt;&#x2F;span&gt;&lt;span&gt;playground)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;error[&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;E0106&lt;&#x2F;span&gt;&lt;span&gt;]&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span&gt; missing lifetime specifier&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; --&amp;gt;&lt;&#x2F;span&gt;&lt;span&gt; src&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;&#x2F;&lt;&#x2F;span&gt;&lt;span&gt;lib&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span&gt;rs&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt;7&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt;26&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;  |&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt;7&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; | fn&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; create_note&lt;&#x2F;span&gt;&lt;span&gt;()&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; -&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Note&lt;&#x2F;span&gt;&lt;span&gt;&amp;lt;&amp;#39;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;_&lt;&#x2F;span&gt;&lt;span&gt;&amp;gt; {&lt;&#x2F;span&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;  &#x2F;&#x2F; ❌ lifetime error&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;  |                          ^^&lt;&#x2F;span&gt;&lt;span&gt; expected named lifetime parameter&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;  |&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;  =&lt;&#x2F;span&gt;&lt;span&gt; help&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span&gt; this function&amp;#39;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;s&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; return type&lt;&#x2F;span&gt;&lt;span&gt; contains a borrowed value, but there is no value&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; for&lt;&#x2F;span&gt;&lt;span&gt; it to be borrowed from&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;help&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span&gt; consider using the `&amp;#39;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;static&lt;&#x2F;span&gt;&lt;span&gt;` lifetime, but this is uncommon unless you&amp;#39;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;re&lt;&#x2F;span&gt;&lt;span&gt; returning a borrowed value from a `&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;const&lt;&#x2F;span&gt;&lt;span&gt;` or a `&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;static&lt;&#x2F;span&gt;&lt;span&gt;`, or&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; if&lt;&#x2F;span&gt;&lt;span&gt; you will only have owned values&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;  |&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;(&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;play.rust-lang.org&#x2F;?version=stable&amp;amp;mode=debug&amp;amp;edition=2021&amp;amp;gist=7274f20a06226316c93d9984f1d66b5f&quot;&gt;Playground&lt;&#x2F;a&gt;)&lt;&#x2F;p&gt;
&lt;p&gt;A simple way around that is to use owned types like &lt;code&gt;String&lt;&#x2F;code&gt; and &lt;code&gt;Vec&lt;&#x2F;code&gt; and avoid lifetime annotations altogether. &lt;a href=&quot;&#x2F;blog&#x2F;lifetimes&#x2F;&quot;&gt;They’re needed less often than you’d think&lt;&#x2F;a&gt;.
Just &lt;code&gt;.clone()&lt;&#x2F;code&gt; wherever you need to pass data around.&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;&#x2F;&#x2F; Much simpler with owned types&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;struct&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Note&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    title&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; String&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    content&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; String&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;fn&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; create_note&lt;&#x2F;span&gt;&lt;span&gt;()&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; -&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Note&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;  &#x2F;&#x2F; ✓ just works&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;    Note&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        title&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; String&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;from&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt;&amp;quot;Draft&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;),&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        content&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; String&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;from&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt;&amp;quot;My first note&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;If you have a type that you need to move between threads (i.e. it needs to be &lt;code&gt;Send&lt;&#x2F;code&gt;), you can use an &lt;code&gt;Arc&amp;lt;Mutex&amp;lt;T&amp;gt;&amp;gt;&lt;&#x2F;code&gt; to get around the borrow checker.
If you’re worried about performance, remember that other languages like Python or Java do this implicitly behind your back.&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;use&lt;&#x2F;span&gt;&lt;span&gt; std&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span&gt;sync&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span&gt;{&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;Arc&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Mutex&lt;&#x2F;span&gt;&lt;span&gt;};&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;use&lt;&#x2F;span&gt;&lt;span&gt; std&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span&gt;thread;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;let&lt;&#x2F;span&gt;&lt;span&gt; note&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Arc&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;new&lt;&#x2F;span&gt;&lt;span&gt;(Mutex&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;new&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;Note&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    title&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span&gt; String&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;from&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt;&amp;quot;Draft&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;),&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    content&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span&gt; String&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;from&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt;&amp;quot;My first note&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}));&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;let&lt;&#x2F;span&gt;&lt;span&gt; note_clone&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Arc&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;clone&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;&amp;amp;&lt;&#x2F;span&gt;&lt;span&gt;note);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;thread&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;spawn&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;move ||&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    let mut&lt;&#x2F;span&gt;&lt;span&gt; note&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; note_clone&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;lock&lt;&#x2F;span&gt;&lt;span&gt;()&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;unwrap&lt;&#x2F;span&gt;&lt;span&gt;();&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    note&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span&gt;content&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;push_str&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt;&amp;quot; with additions&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;});&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;(&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;play.rust-lang.org&#x2F;?version=stable&amp;amp;mode=debug&amp;amp;edition=2021&amp;amp;gist=4b93a53ebc1d7ee6bc2b39c91543fba7&quot;&gt;Playground&lt;&#x2F;a&gt;)&lt;&#x2F;p&gt;
&lt;p&gt;If you feel like you have to use &lt;code&gt;Arc&amp;lt;Mutex&amp;lt;T&amp;gt;&amp;gt;&lt;&#x2F;code&gt; too often, there might be a design issue.
For example, you might be able to avoid sharing state between threads.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;keep-a-flat-hierarchy&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#keep-a-flat-hierarchy&quot; aria-label=&quot;Anchor link for: keep-a-flat-hierarchy&quot;&gt;Keep a flat hierarchy&lt;&#x2F;a&gt;&lt;&#x2F;h3&gt;
&lt;p&gt;&lt;code&gt;main.rs&lt;&#x2F;code&gt; is your best friend while prototyping.&lt;&#x2F;p&gt;
&lt;p&gt;Stuff your code in there – no need for modules or complex organization yet. This makes it easy to experiment and move things around.&lt;&#x2F;p&gt;
&lt;h4 id=&quot;first-draft-everything-in-main-rs&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#first-draft-everything-in-main-rs&quot; aria-label=&quot;Anchor link for: first-draft-everything-in-main-rs&quot;&gt;First draft: everything in main.rs&lt;&#x2F;a&gt;&lt;&#x2F;h4&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;struct&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Config&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    port&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; u16&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;fn&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; load_config&lt;&#x2F;span&gt;&lt;span&gt;()&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; -&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Config&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;    Config&lt;&#x2F;span&gt;&lt;span&gt; { port&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt; 8080&lt;&#x2F;span&gt;&lt;span&gt; }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;struct&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Server&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    config&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Config&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;impl&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Server&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    fn&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; new&lt;&#x2F;span&gt;&lt;span&gt;(config&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Config&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; -&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;font-style: italic;&quot;&gt; Self&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;        Server&lt;&#x2F;span&gt;&lt;span&gt; { config }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    fn&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; start&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;&amp;amp;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;font-style: italic;&quot;&gt;self&lt;&#x2F;span&gt;&lt;span&gt;) {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;        println!&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt;&amp;quot;Starting server on port {}&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;font-style: italic;&quot;&gt; self&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span&gt;config&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span&gt;port);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;fn&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; main&lt;&#x2F;span&gt;&lt;span&gt;() {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    let&lt;&#x2F;span&gt;&lt;span&gt; config&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; load_config&lt;&#x2F;span&gt;&lt;span&gt;();&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    let&lt;&#x2F;span&gt;&lt;span&gt; server&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Server&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;new&lt;&#x2F;span&gt;&lt;span&gt;(config);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    server&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;start&lt;&#x2F;span&gt;&lt;span&gt;();&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Once you have a better feel for your code’s structure, Rust’s &lt;code&gt;mod&lt;&#x2F;code&gt; keyword becomes a handy tool for sketching out potential organization. You can nest modules right in your main file.&lt;&#x2F;p&gt;
&lt;h4 id=&quot;later-experiment-with-module-structure-in-the-same-file&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#later-experiment-with-module-structure-in-the-same-file&quot; aria-label=&quot;Anchor link for: later-experiment-with-module-structure-in-the-same-file&quot;&gt;Later: experiment with module structure in the same file&lt;&#x2F;a&gt;&lt;&#x2F;h4&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;mod&lt;&#x2F;span&gt;&lt;span&gt; config {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    pub struct&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Config&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;        pub&lt;&#x2F;span&gt;&lt;span&gt; port&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; u16&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    pub fn&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; load&lt;&#x2F;span&gt;&lt;span&gt;()&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; -&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Config&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;        Config&lt;&#x2F;span&gt;&lt;span&gt; { port&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt; 8080&lt;&#x2F;span&gt;&lt;span&gt; }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;mod&lt;&#x2F;span&gt;&lt;span&gt; server {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    use crate::&lt;&#x2F;span&gt;&lt;span&gt;config;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    pub struct&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Server&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        config&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span&gt; config&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;Config&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    impl&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Server&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;        pub fn&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; new&lt;&#x2F;span&gt;&lt;span&gt;(config&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span&gt; config&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;Config&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; -&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;font-style: italic;&quot;&gt; Self&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;            Server&lt;&#x2F;span&gt;&lt;span&gt; { config }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;        pub fn&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; start&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;&amp;amp;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;font-style: italic;&quot;&gt;self&lt;&#x2F;span&gt;&lt;span&gt;) {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;            println!&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt;&amp;quot;Starting server on port {}&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;font-style: italic;&quot;&gt; self&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span&gt;config&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span&gt;port);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;This inline module structure lets you quickly test different organizational patterns.
You can easily move code between scopes with cut and paste, and experiment with different APIs and naming conventions.
Once a particular structure feels right, you can move modules into their own files.&lt;&#x2F;p&gt;
&lt;p&gt;The key is to keep things simple until it calls for more complexity.
Start flat, then add structure incrementally as your understanding of the problem grows.&lt;&#x2F;p&gt;
&lt;p&gt;See also &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;matklad.github.io&#x2F;2021&#x2F;08&#x2F;22&#x2F;large-rust-workspaces.html&quot;&gt;Matklad’s article on large Rust workspaces&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;start-small&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#start-small&quot; aria-label=&quot;Anchor link for: start-small&quot;&gt;Start small&lt;&#x2F;a&gt;&lt;&#x2F;h3&gt;
&lt;p&gt;Allow yourself to ignore some of the best practices for production code for a while.&lt;&#x2F;p&gt;
&lt;p&gt;It’s possible, but you need to switch off your inner critic who always wants to write perfect code from the beginning.
Rust enables you to comfortably defer perfection.
You can make the rough edges obvious so that you can sort them out later.
Don’t let perfect be the enemy of good.&lt;&#x2F;p&gt;
&lt;p&gt;One of the biggest mistakes I observe is an engineer’s perfectionist instinct to jump on minor details which don’t have a broad enough impact to warrant the effort.
It’s better to have a working prototype with a few rough edges than a perfect implementation of a small part of the system.&lt;&#x2F;p&gt;
&lt;p&gt;Remember: you are exploring!
Use a coarse brush to paint the landscape first.
Try to get into a flow state where you can quickly iterate.
Don’t get distracted by the details too early.
During this phase, it’s also fine to throw away a lot failed attempts.&lt;&#x2F;p&gt;
&lt;p&gt;There’s some overlap between prototyping and “&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.youtube.com&#x2F;watch?v=33FG6O3qejM&quot;&gt;easy Rust&lt;&#x2F;a&gt;.”&lt;&#x2F;p&gt;
&lt;h2 id=&quot;summary&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#summary&quot; aria-label=&quot;Anchor link for: summary&quot;&gt;Summary&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;p&gt;The beauty of prototyping in Rust is that your “rough drafts” have the same memory safety and performance as polished code.
Even when I liberally use &lt;code&gt;unwrap()&lt;&#x2F;code&gt;, stick everything in &lt;code&gt;main.rs&lt;&#x2F;code&gt;, and reach for owned types everywhere, the resulting code
is on-par with a Python prototype in reliability, but outperforms it easily.
This makes it perfect for experimenting with real-world workloads, even before investing time in proper error handling.&lt;&#x2F;p&gt;
&lt;p&gt;Let’s see how Rust stacks up against Python for prototyping:&lt;&#x2F;p&gt;
&lt;table&gt;&lt;thead&gt;&lt;tr&gt;&lt;th&gt;Aspect&lt;&#x2F;th&gt;&lt;th&gt;Python&lt;&#x2F;th&gt;&lt;th&gt;Rust&lt;&#x2F;th&gt;&lt;&#x2F;tr&gt;&lt;&#x2F;thead&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;Initial Development Speed&lt;&#x2F;td&gt;&lt;td&gt;✓ Very quick to write initial code&lt;br&gt;✓ No compilation step&lt;br&gt;✓ Dynamic typing speeds up prototyping&lt;br&gt;✓ File watchers available&lt;&#x2F;td&gt;&lt;td&gt;⚠️ Slightly slower initial development&lt;br&gt;✓ Type inference helps&lt;br&gt;✓ Tools like &lt;code&gt;bacon&lt;&#x2F;code&gt; provide quick feedback&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;Standard Library&lt;&#x2F;td&gt;&lt;td&gt;✓ Batteries included&lt;br&gt;✓ Rich ecosystem&lt;&#x2F;td&gt;&lt;td&gt;❌ Smaller standard library&lt;br&gt;✓ Growing ecosystem of high-quality crates&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;Transition to Production&lt;&#x2F;td&gt;&lt;td&gt;❌ Need extensive testing to catch type errors&lt;br&gt;❌ Bad performance might require extra work or rewrite in another language&lt;&#x2F;td&gt;&lt;td&gt;✓ Minimal changes needed beyond error handling&lt;br&gt;✓ Already has good performance&lt;br&gt;✓ Memory safety guaranteed&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;Maintenance&lt;&#x2F;td&gt;&lt;td&gt;❌ Type errors surface during runtime&lt;br&gt;❌ Refactoring is risky&lt;&#x2F;td&gt;&lt;td&gt;✓ Compiler catches most issues&lt;br&gt;✓ Safe refactoring with type system&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;Code Evolution&lt;&#x2F;td&gt;&lt;td&gt;❌ Hard to maintain large codebases&lt;br&gt;❌ Type issues compound&lt;&#x2F;td&gt;&lt;td&gt;✓ Compiler guides improvements&lt;br&gt;✓ Types help manage complexity&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;&#x2F;tbody&gt;&lt;&#x2F;table&gt;
&lt;p&gt;Quite frankly, Rust makes for an excellent prototyping language if you embrace its strengths.
Yes, the type system will make you think harder about your design up front - but that’s actually a good thing!
Each iteration might take a bit longer than in Python or JavaScript, but you’ll typically need fewer iterations from prototype to production.&lt;&#x2F;p&gt;
&lt;p&gt;I’ve found that my prototypes in other languages often hit a wall where I need to switch to something more robust.
With Rust, I can start simple and gradually turn that proof-of-concept into production code, all while staying in the same language and ecosystem.&lt;&#x2F;p&gt;
&lt;p&gt;If you have any more tips or tricks for prototyping in Rust, &lt;a href=&quot;&#x2F;services&quot;&gt;get in touch&lt;&#x2F;a&gt; and I’ll add them to the list!&lt;&#x2F;p&gt;
&lt;section class=&quot;footnotes&quot;&gt;
&lt;ol class=&quot;footnotes-list&quot;&gt;
&lt;li id=&quot;fn-1&quot;&gt;
&lt;p&gt;More experienced Rust developers might find themselves reaching for an &lt;code&gt;impl IntoIterator&amp;lt;Item=T&amp;gt;&lt;&#x2F;code&gt; where &lt;code&gt;&amp;amp;[T]&lt;&#x2F;code&gt;&#x2F;&lt;code&gt;Vec&amp;lt;T&amp;gt;&lt;&#x2F;code&gt; would do. Keep it simple! &lt;a href=&quot;#fr-1-1&quot;&gt;↩&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;&#x2F;li&gt;
&lt;li id=&quot;fn-2&quot;&gt;
&lt;p&gt;In the talk, I show an example where early over-optimization led to the wrong abstraction and made the code slower. The actual bottleneck was elsewhere and hard to uncover without profiling. &lt;a href=&quot;#fr-2-1&quot;&gt;↩&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;&#x2F;li&gt;
&lt;li id=&quot;fn-3&quot;&gt;
&lt;p&gt;I usually know when I found a good abstraction once I can use all of Rust’s features like expression-oriented programming and pattern matching together with my own types. &lt;a href=&quot;#fr-3-1&quot;&gt;↩&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;&#x2F;section&gt;
</description>
      </item>
      <item>
          <title>Brave</title>
          <pubDate>Thu, 09 Jan 2025 00:00:00 +0000</pubDate>
          <author>Matthias Endler</author>
          <link>https://corrode.dev/podcast/s03e07-brave/</link>
          <guid>https://corrode.dev/podcast/s03e07-brave/</guid>
          <description xml:base="https://corrode.dev/podcast/s03e07-brave/">&lt;div&gt;&lt;script id=&quot;letscast-player-9d22a062&quot; src=&quot;https:&#x2F;&#x2F;letscast.fm&#x2F;podcasts&#x2F;rust-in-production-82281512&#x2F;episodes&#x2F;brave-with-anton-lazarev&#x2F;player.js?size=s&quot;&gt;&lt;&#x2F;script&gt;&lt;&#x2F;div&gt;
&lt;p&gt;Web browsers today face increasing demands for both performance and privacy. At Brave, they’re tackling both challenges head-on with their Rust-based ad-blocking engine. This isn’t just about blocking ads – it’s about doing so with minimal performance impact while maintaining compatibility with existing filter lists and adapting to evolving web technologies.&lt;&#x2F;p&gt;</description>
      </item>
      <item>
          <title>2024 Holiday Special</title>
          <pubDate>Thu, 26 Dec 2024 00:00:00 +0000</pubDate>
          <author>Matthias Endler</author>
          <link>https://corrode.dev/podcast/s03e06-holiday/</link>
          <guid>https://corrode.dev/podcast/s03e06-holiday/</guid>
          <description xml:base="https://corrode.dev/podcast/s03e06-holiday/">&lt;div&gt;&lt;script id=&quot;letscast-player-ec214dbb&quot; src=&quot;https:&#x2F;&#x2F;letscast.fm&#x2F;podcasts&#x2F;rust-in-production-82281512&#x2F;episodes&#x2F;holiday-special&#x2F;player.js?size=s&quot;&gt;&lt;&#x2F;script&gt;&lt;&#x2F;div&gt;
&lt;p&gt;While we try not to get too sentimental, celebrating one year of ‘Rust in Production’ alongside the holiday season feels like a perfect occasion to reflect. For this special episode of the podcast, we’ve gathered heartfelt messages from our guests to the Rust community.&lt;&#x2F;p&gt;
&lt;p&gt;There are two common themes that run through these messages:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;The importance of writing simple, approachable Rust code to help flatten the learning curve for newcomers&lt;&#x2F;li&gt;
&lt;li&gt;Their gratitude for the vibrant ecosystem and the wealth of available crates&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;As we look ahead to the Rust 2024 edition, we’re excited about what’s to come. Thank you for being part of this journey with us, and here’s to a great start to 2025! May the new year bring us all faster compile times, gentler learning curves, and, if we get lucky, let-chains on stable Rust.&lt;&#x2F;p&gt;
</description>
      </item>
      <item>
          <title>Migrating from Python to Rust</title>
          <pubDate>Fri, 13 Dec 2024 00:00:00 +0000</pubDate>
          <author>Matthias Endler</author>
          <link>https://corrode.dev/learn/migration-guides/python-to-rust/</link>
          <guid>https://corrode.dev/learn/migration-guides/python-to-rust/</guid>
          <description xml:base="https://corrode.dev/learn/migration-guides/python-to-rust/">&lt;div class=&quot;info&quot;&gt;
  
  &lt;div class=&quot;info-header&quot;&gt;
    
      &lt;span class=&quot;icon icon-info&quot;&gt;&lt;&#x2F;span&gt;
    
    &lt;h4&gt;&lt;p&gt;A Practical Guide for Decision Makers&lt;&#x2F;p&gt;
&lt;&#x2F;h4&gt;
  &lt;&#x2F;div&gt;
  
  &lt;p&gt;This guide is written for technical leaders and developers considering moving their teams from Python to Rust.
I used to be a Python developer myself, and I know how daunting it can be to switch to a new language.
Base on years of experience helping teams make this transition, I’ll share practical insights on what works, what doesn’t, and how to ensure a successful migration.&lt;&#x2F;p&gt;

&lt;&#x2F;div&gt;
&lt;p&gt;Python is an incredibly versatile language that powers everything from web applications to data science pipelines. However, as organizations scale, they often encounter limitations around performance, type safety, and robustness. While Rust isn’t a direct replacement for Python, it has some answers to these challenges.&lt;&#x2F;p&gt;
&lt;p&gt;But is Rust the right choice for your team?&lt;&#x2F;p&gt;
&lt;p&gt;In this article, you’ll learn:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;How to evaluate whether Rust is the right choice for your Python codebase&lt;&#x2F;li&gt;
&lt;li&gt;Practical strategies for Python-to-Rust migration&lt;&#x2F;li&gt;
&lt;li&gt;Common pitfalls and how to avoid them&lt;&#x2F;li&gt;
&lt;li&gt;Ways to maintain productivity during the transition&lt;&#x2F;li&gt;
&lt;li&gt;How to leverage Python’s strengths alongside Rust&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h2 id=&quot;get-your-customized-migration-plan&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#get-your-customized-migration-plan&quot; aria-label=&quot;Anchor link for: get-your-customized-migration-plan&quot;&gt;Get Your Customized Migration Plan&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;p&gt;I help teams migrate from Python to Rust, providing tailored guidance and training.
If you’re considering a migration, answer a few questions about your project, and I’ll reach out with a customized plan.&lt;&#x2F;p&gt;
&lt;div class=&quot;quiz-container&quot;&gt;
  &lt;div class=&quot;quiz-progress-container&quot;&gt;
    &lt;div class=&quot;progress-bar&quot; id=&quot;progress-bar&quot; style=&quot;width: 0%&quot;&gt;&lt;&#x2F;div&gt;
  &lt;&#x2F;div&gt;
  &lt;div id=&quot;quiz-question-container&quot;&gt;&lt;&#x2F;div&gt;

  &lt;div id=&quot;quiz-navigation-container&quot;&gt;
    &lt;button
      class=&quot;quiz-navbutton&quot;
      id=&quot;quiz-prev-question&quot;
      style=&quot;display: none&quot;
    &gt;
      ← Previous
    &lt;&#x2F;button&gt;
    &lt;button class=&quot;quiz-navbutton&quot; id=&quot;quiz-next-question&quot;&gt;Next →&lt;&#x2F;button&gt;
  &lt;&#x2F;div&gt;

  &lt;div id=&quot;quiz-results&quot; style=&quot;display: none&quot;&gt;
    &lt;h2&gt;Thank you for your interest!&lt;&#x2F;h2&gt;
    &lt;p&gt;
      I&#x27;ll send you a customized migration strategy based on your responses.
    &lt;&#x2F;p&gt;
    &lt;p&gt;
      In the meantime, feel free to check out my
      &lt;a href=&quot;&#x2F;blog&quot;&gt;other articles about Rust&lt;&#x2F;a&gt;.
    &lt;&#x2F;p&gt;
  &lt;&#x2F;div&gt;
&lt;&#x2F;div&gt;

&lt;script&gt;
  const languageOptions = [
    &quot;Python&quot;,
    &quot;Java&quot;,
    &quot;C++&quot;,
    &quot;Go&quot;,
    &quot;TypeScript&quot;,
    &quot;JavaScript&quot;,
    &quot;C#&quot;,
    &quot;Ruby&quot;,
    &quot;PHP&quot;,
    &quot;Swift&quot;,
    &quot;Kotlin&quot;,
    &quot;Other&quot;,
  ];

  const questions = [
  {
    type: &quot;multipleChoice&quot;,
    question: &quot;Which languages are currently used in your codebase?&quot;,
    id: &quot;currentLanguages&quot;,
    options: languageOptions,
  },
  {
    type: &quot;multipleChoice&quot;,
    question: &quot;Which types of applications are you looking to migrate?&quot;,
    id: &quot;applicationType&quot;,
    direction: &quot;column&quot;,
    options: [
      &quot;Web services &#x2F; APIs&quot;,
      &quot;CLI tools&quot;,
      &quot;Embedded systems&quot;,
      &quot;Desktop applications&quot;,
      &quot;WebAssembly modules&quot;,
      &quot;Data processing pipelines&quot;,
      &quot;Machine learning systems&quot;,
      &quot;Other&quot;,
    ],
  },
  {
    type: &quot;radio&quot;,
    question: &quot;What&#x27;s the size of your codebase?&quot;,
    id: &quot;codebaseSize&quot;,
    options: [&quot;&lt; 10k lines&quot;, &quot;&lt; 100k lines&quot;, &quot;&gt; 100k lines&quot;],
  },
  {
    type: &quot;radio&quot;,
    question: &quot;What&#x27;s your team&#x27;s experience with Rust?&quot;,
    id: &quot;rustExperience&quot;,
    direction: &quot;column&quot;,
    options: [
      &quot;No experience yet&quot;,
      &quot;Some team members have experimented with it&quot;,
      &quot;We have one or more small projects in production&quot;,
      &quot;We have significant production experience&quot;,
    ],
  },
  {
    type: &quot;multipleChoice&quot;,
    question: &quot;What are your main motivations for migrating to Rust?&quot;,
    direction: &quot;column&quot;,
    id: &quot;motivations&quot;,
    options: [
      &quot;Performance improvements&quot;,
      &quot;Better type safety&quot;,
      &quot;Memory efficiency&quot;,
      &quot;Production reliability&quot;,
      &quot;Cross-platform deployment&quot;,
      &quot;WebAssembly support&quot;,
      &quot;Embedded systems development&quot;,
      &quot;Microservices migration&quot;,
      &quot;Other&quot;,
    ],
  },
  {
    type: &quot;multipleChoice&quot;,
    question: &quot;What are your main concerns about migrating to Rust?&quot;,
    id: &quot;concerns&quot;,
    direction: &quot;column&quot;,
    options: [
      &quot;Learning curve for the team&quot;,
      &quot;Migration complexity&quot;,
      &quot;Maintaining productivity during transition&quot;,
      &quot;Finding Rust developers&quot;,
      &quot;Integration with existing Python code&quot;,
      &quot;Third-party library availability&quot;,
      &quot;Build times&quot;,
      &quot;Testing and deployment changes&quot;,
      &quot;None&#x2F;Other&quot;,
    ],
  },
  {
    type: &quot;radio&quot;,
    question: &quot;What&#x27;s your timeline for the migration?&quot;,
    id: &quot;timeline&quot;,
    options: [
      &quot;Immediate (next 3 months)&quot;,
      &quot;Medium-term (3-12 months)&quot;,
      &quot;Long-term (12+ months)&quot;,
    ],
  },
  {
    type: &quot;multipleChoice&quot;,
    question: &quot;What kind of support is most important for your team?&quot;,
    id: &quot;supportNeeded&quot;,
    direction: &quot;column&quot;,
    options: [
      &quot;Planning and strategy&quot;,
      &quot;Project audit&quot;,
      &quot;Training and workshops&quot;,
      &quot;Code reviews and mentoring&quot;,
      &quot;PyO3 integration support&quot;,
      &quot;Performance optimization&quot;,
      &quot;Architecture design&quot;,
      &quot;Best practices guidance&quot;,
      &quot;Team hiring support&quot;,
    ],
  },
  {
    type: &quot;radio&quot;,
    question: &quot;How many developers would be involved in the migration?&quot;,
    options: [&quot;1&quot;, &quot;2-3&quot;, &quot;4-9&quot;, &quot;10+&quot;],
    id: &quot;teamSize&quot;,
  },
  {
    type: &quot;input&quot;,
    question: &quot;Anything else you&#x27;d like to share about your migration plans?&quot;,
    id: &quot;additionalComments&quot;,
    placeholder: &quot;Share your thoughts...&quot;,
    optional: true,
  },
  {
    type: &quot;email&quot;,
    question:
      &quot;What&#x27;s your email? I&#x27;ll send you a customized migration strategy based on your responses.&quot;,
    id: &quot;email&quot;,
    placeholder: &quot;Your email address&quot;,
  },
];

const formURL = &quot;https:&#x2F;&#x2F;submit-form.com&#x2F;YkAFE1mIq&quot;;

  &#x2F;&#x2F; Quiz state
  let answers = {};
  let currentQuestionIndex = 0;
  let totalQuestions;

  &#x2F;&#x2F; DOM elements
  const progressBar = document.getElementById(&quot;progress-bar&quot;);
  const questionContainer = document.getElementById(&quot;quiz-question-container&quot;);
  const prevButton = document.getElementById(&quot;quiz-prev-question&quot;);
  const nextButton = document.getElementById(&quot;quiz-next-question&quot;);

  function initQuiz() {
    totalQuestions = questions.length;
    nextButton.addEventListener(&quot;click&quot;, nextQuestion);
    prevButton.addEventListener(&quot;click&quot;, previousQuestion);

    &#x2F;&#x2F; Handle browser back&#x2F;forward buttons
    window.addEventListener(&quot;popstate&quot;, (event) =&gt; {
      if (event.state) {
        currentQuestionIndex = event.state.index;
        answers = event.state.answers || {};
        displayQuestion(currentQuestionIndex);
      } else {
        resetQuiz();
      }
    });

    displayQuestion(0);
  }

  function resetQuiz() {
    answers = {};
    currentQuestionIndex = 0;
    displayQuestion(0);
  }

  function updateProgressBar() {
    const progressPercentage =
      ((currentQuestionIndex + 1) &#x2F; totalQuestions) * 100;
    progressBar.style.width = `${progressPercentage}%`;
  }

  function createQuestionElement(question) {
    const element = document.createElement(&quot;div&quot;);
    element.className = &quot;question&quot;;
    element.innerHTML = `&lt;h3&gt;${question.question}${
      question.optional ? &quot; (Optional)&quot; : &quot;&quot;
    }&lt;&#x2F;h3&gt;`;

    let inputContainer;

    switch (question.type) {
      case &quot;multipleChoice&quot;:
        inputContainer = document.createElement(&quot;div&quot;);
        if (question.direction) {
          inputContainer.style.display = &quot;flex&quot;;
          inputContainer.style.flexDirection = question.direction;
        } else {
          inputContainer.className = &quot;checkbox-grid&quot;;
        }

        question.options.forEach((option) =&gt; {
          const label = document.createElement(&quot;label&quot;);
          label.className = &quot;checkbox-label&quot;;

          const input = document.createElement(&quot;input&quot;);
          input.type = &quot;checkbox&quot;;
          input.name = question.id;
          input.value = option;

          label.appendChild(input);
          label.append(` ${option}`);
          inputContainer.appendChild(label);
        });
        break;

      case &quot;radio&quot;:
        inputContainer = document.createElement(&quot;div&quot;);
        inputContainer.className = &quot;quiz-flex-container&quot;;
        if (question.direction) {
          inputContainer.style.flexDirection = question.direction;
        }

        question.options.forEach((option) =&gt; {
          const label = document.createElement(&quot;label&quot;);
          label.className = &quot;quiz-button&quot;;
          label.textContent = option;

          const input = document.createElement(&quot;input&quot;);
          input.type = &quot;radio&quot;;
          input.name = question.id;
          input.value = option;

          input.addEventListener(&quot;change&quot;, () =&gt; {
            saveCurrentAnswers();
            nextButton.disabled = false;
            &#x2F;&#x2F; Auto-advance
            if (currentQuestionIndex &lt; totalQuestions - 1) {
              nextQuestion();
            }
          });

          label.appendChild(input);
          inputContainer.appendChild(label);
        });
        break;

      case &quot;input&quot;:
      case &quot;email&quot;:
        inputContainer = document.createElement(&quot;input&quot;);
        inputContainer.type = question.type;
        inputContainer.id = question.id;
        inputContainer.name = question.id;
        inputContainer.placeholder = question.placeholder || &quot;&quot;;
        if (question.type === &quot;email&quot;) {
          inputContainer.required = true;
        }
        if (!question.optional) {
          inputContainer.required = true;
        }
        break;
    }

    element.appendChild(inputContainer);
    return { element, inputContainer };
  }

  function saveCurrentAnswers() {
    const inputs = questionContainer.querySelectorAll(&quot;input&quot;);
    const questionId = questions[currentQuestionIndex].id;

    delete answers[questionId];

    inputs.forEach((input) =&gt; {
      if (input.type === &quot;checkbox&quot;) {
        if (input.checked) {
          answers[questionId] = answers[questionId] || [];
          answers[questionId].push(input.value);
        }
      } else if (
        (input.type === &quot;radio&quot; &amp;&amp; input.checked) ||
        input.type === &quot;text&quot; ||
        input.type === &quot;email&quot;
      ) {
        if (input.value.trim()) {
          answers[questionId] = input.value;
        }
      }
    });
  }

  function restorePreviousAnswers(question, container) {
    const previousAnswer = answers[question.id];
    if (!previousAnswer) return;

    const inputs = container.querySelectorAll(&quot;input&quot;);
    inputs.forEach((input) =&gt; {
      if (input.type === &quot;checkbox&quot;) {
        input.checked = previousAnswer.includes(input.value);
      } else if (input.type === &quot;radio&quot;) {
        input.checked = input.value === previousAnswer;
      } else {
        input.value = previousAnswer;
      }
    });
  }

  function updateNavigationState() {
    prevButton.style.display = currentQuestionIndex &gt; 0 ? &quot;&quot; : &quot;none&quot;;
    const question = questions[currentQuestionIndex];
    nextButton.disabled = !isQuestionAnswered(question);
  }

  function isQuestionAnswered(question) {
    if (question.optional) return true;
    const answer = answers[question.id];
    if (!answer) return false;
    if (Array.isArray(answer)) return answer.length &gt; 0;
    
    if (question.type === &quot;email&quot;) {
      const input = document.getElementById(question.id);
      return input &amp;&amp; input.checkValidity() &amp;&amp; answer.trim().length &gt; 0;
    }
    
    return answer.trim().length &gt; 0;
  }

  function nextQuestion() {
    if (currentQuestionIndex &lt; totalQuestions - 1) {
      saveCurrentAnswers();
      currentQuestionIndex++;
      displayQuestion(currentQuestionIndex);
    } else {
      submitQuiz();
    }
  }

  function previousQuestion() {
    if (currentQuestionIndex &gt; 0) {
      saveCurrentAnswers();
      currentQuestionIndex--;
      displayQuestion(currentQuestionIndex);
    }
  }

  function displayQuestion(index) {
    const question = questions[index];
    if (!question) return;

    history.pushState(
      { index, answers: { ...answers } },
      `Question ${index + 1}`,
      `?question=${index + 1}`
    );

    questionContainer.innerHTML = &quot;&quot;;
    const { element, inputContainer } = createQuestionElement(question);
    questionContainer.appendChild(element);

    restorePreviousAnswers(question, inputContainer);
    updateProgressBar();
    updateNavigationState();

    if (question.type === &quot;input&quot; || question.type === &quot;email&quot;) {
      const input = inputContainer;
      input.addEventListener(&quot;input&quot;, () =&gt; {
        if (question.type === &quot;email&quot;) {
          nextButton.disabled = !input.checkValidity() &amp;&amp; !question.optional;
        } else {
          nextButton.disabled = !input.value.trim() &amp;&amp; !question.optional;
        }
      });
    } else if (question.type === &quot;multipleChoice&quot;) {
      const inputs = inputContainer.querySelectorAll(&quot;input&quot;);
      inputs.forEach((input) =&gt; {
        input.addEventListener(&quot;change&quot;, () =&gt; {
          const anyChecked = Array.from(inputs).some((i) =&gt; i.checked);
          nextButton.disabled = !anyChecked &amp;&amp; !question.optional;
        });
      });
    }

    if (question.type === &quot;radio&quot;) {
      nextButton.disabled = !answers[question.id] &amp;&amp; !question.optional;
    }
  }

  async function submitQuiz() {
    saveCurrentAnswers();

    &#x2F;&#x2F; Hide the quiz
    questionContainer.innerHTML = &quot;&quot;;
    document.getElementById(&quot;quiz-navigation-container&quot;).style.display = &quot;none&quot;;

    &#x2F;&#x2F; Show the thank you message
    const resultsContainer = document.getElementById(&quot;quiz-results&quot;);
    resultsContainer.style.display = &quot;block&quot;;

    try {
      &#x2F;&#x2F; Using Formspark as an example
      const response = await fetch(formUrl, {
        method: &quot;POST&quot;,
        headers: {
          &quot;Content-Type&quot;: &quot;application&#x2F;json&quot;,
          Accept: &quot;application&#x2F;json&quot;,
        },
        body: JSON.stringify(answers),
      });

      if (!response.ok) {
        throw new Error(&quot;Failed to submit&quot;);
      }
    } catch (error) {
      console.error(&quot;Failed to submit form:&quot;, error);
      &#x2F;&#x2F; Optionally show an error message to the user
    }
  }

  document.addEventListener(&quot;DOMContentLoaded&quot;, initQuiz);
&lt;&#x2F;script&gt;

&lt;style&gt;
  .quiz-container {
    margin: 0 auto;
    overflow: hidden;
  }

  .quiz-progress-container {
    width: 100%;
    background-color: #ddd;
    height: 5px;
    margin-bottom: 20px;
  }

  .progress-bar {
    height: 100%;
    background-color: #ee3856;
    transition: width 0.5s ease-in-out;
  }

  #quiz-navigation-container {
    width: 100%;
    margin-top: 10px;
    display: flex;
    justify-content: flex-end;
    gap: 10px;
  }

  .quiz-navbutton {
    padding: 10px 20px;
    background-color: #111;
    color: white;
    cursor: pointer;
    border: none;
  }

  .quiz-flex-container {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
  }

  .quiz-button {
    padding: 14px;
    border-radius: 4px;
    background-color: #111;
    color: white;
    white-space: nowrap;
    cursor: pointer;
    flex: 1;
    text-align: center;
    font-size: large;
  }

  .quiz-button:hover {
    background-color: #ee3856;
  }

  input,
  .checkbox-label,
  .quiz-button:hover {
    cursor: pointer;
  }

  #quiz-next-question:disabled {
    cursor: not-allowed;
    opacity: 0.5;
  }

  .quiz-button input[type=&quot;radio&quot;] {
    display: none;
  }

  .quiz-container input[type=&quot;input&quot;],
  .quiz-container input[type=&quot;text&quot;],
  .quiz-container input[type=&quot;email&quot;] {
    font-size: larger;
    width: 100%;
    padding: 15px;
    border: 1px solid #000;
    box-sizing: border-box;
    margin-bottom: 20px;
  }

  .quiz-container input::placeholder {
    color: #ccc;
  }

  .question h2 {
    margin: 0;
  }

  .question .checkbox-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
    gap: 10px;
  }

  .checkbox-label {
    display: flex;
    align-items: center;
    gap: 8px;
  }

  .question input[type=&quot;checkbox&quot;] {
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
    flex-shrink: 0; &#x2F;* Prevent checkbox from shrinking *&#x2F;
    width: 20px;
    height: 20px;
    border: 2px solid #111;
    border-radius: 4px;
    margin: 0; &#x2F;* Remove margin, we&#x27;re using gap instead *&#x2F;
  }

  .question input[type=&quot;checkbox&quot;]:checked {
    border: 2px solid #111;
    background-color: #ee3856;
  }

  @media (max-width: 600px) {
    .quiz-container input[type=&quot;text&quot;],
    .quiz-container input[type=&quot;email&quot;] {
      width: calc(100% - 30px);
    }
  }

  @media (prefers-color-scheme: dark) {
    .quiz-button {
      background-color: #fab71c;
      color: #111;
    }

    .question input[type=&quot;checkbox&quot;] {
      border-color: #fff;
    }

    .question input[type=&quot;checkbox&quot;]:checked {
      border: 2px solid #fff;
      background-color: #ee3856;
    }
  }
&lt;&#x2F;style&gt;
&lt;h2 id=&quot;key-differences-between-python-and-rust&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#key-differences-between-python-and-rust&quot; aria-label=&quot;Anchor link for: key-differences-between-python-and-rust&quot;&gt;Key Differences Between Python and Rust&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;table&gt;&lt;thead&gt;&lt;tr&gt;&lt;th&gt;Aspect&lt;&#x2F;th&gt;&lt;th&gt;Python 🐍&lt;&#x2F;th&gt;&lt;th&gt;Rust 🦀&lt;&#x2F;th&gt;&lt;&#x2F;tr&gt;&lt;&#x2F;thead&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;Type System&lt;&#x2F;td&gt;&lt;td&gt;Dynamic, optional type hints&lt;&#x2F;td&gt;&lt;td&gt;Static, strong type system&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;Memory Management&lt;&#x2F;td&gt;&lt;td&gt;Garbage collected&lt;&#x2F;td&gt;&lt;td&gt;No GC, ownership and borrowing&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;Performance&lt;&#x2F;td&gt;&lt;td&gt;Moderate&lt;&#x2F;td&gt;&lt;td&gt;High performance, low-level control&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;Deployment&lt;&#x2F;td&gt;&lt;td&gt;Runtime required&lt;&#x2F;td&gt;&lt;td&gt;Single binary, minimal runtime&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;Package Manager&lt;&#x2F;td&gt;&lt;td&gt;Multiple (pip, conda, uv)&lt;&#x2F;td&gt;&lt;td&gt;cargo (built-in, consistent)&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;Error Handling&lt;&#x2F;td&gt;&lt;td&gt;Exceptions&lt;&#x2F;td&gt;&lt;td&gt;Result type&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;Concurrency&lt;&#x2F;td&gt;&lt;td&gt;Limited by GIL&lt;&#x2F;td&gt;&lt;td&gt;zero-cost abstractions, no GIL&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;Learning Curve&lt;&#x2F;td&gt;&lt;td&gt;Gentle&lt;&#x2F;td&gt;&lt;td&gt;Steep&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;Ecosystem Size&lt;&#x2F;td&gt;&lt;td&gt;Large (500,000+ packages)&lt;&#x2F;td&gt;&lt;td&gt;Medium (160,000+ crates)&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;&#x2F;tbody&gt;&lt;&#x2F;table&gt;
&lt;h2 id=&quot;why-python-teams-consider-rust&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#why-python-teams-consider-rust&quot; aria-label=&quot;Anchor link for: why-python-teams-consider-rust&quot;&gt;Why Python Teams Consider Rust&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;p&gt;Python developers often want to transition to Rust for several reasons:&lt;&#x2F;p&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;Developers interested in Rust are likely willing to understand systems programming concepts.
They grew out of Python’s limitations and are looking for more control over performance and memory management.&lt;&#x2F;p&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;
&lt;p&gt;Python developers often long for stronger type guarantees.
They appreciate Rust’s static type system and the safety it provides.&lt;&#x2F;p&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;
&lt;p&gt;Developers with a Python background often work on data processing or web applications.
These are areas where Rust’s performance benefits are most pronounced.&lt;&#x2F;p&gt;
&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;p&gt;While Python excels at readability and rapid development, teams often hit scaling challenges as their applications grow. Below, I’ve listed a few common pain points that get mentioned in consultations with teams considering a migration.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;performance-bottlenecks&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#performance-bottlenecks&quot; aria-label=&quot;Anchor link for: performance-bottlenecks&quot;&gt;Performance Bottlenecks&lt;&#x2F;a&gt;&lt;&#x2F;h3&gt;
&lt;p&gt;Python’s Global Interpreter Lock (GIL) limits true parallelism, making it challenging to fully utilize modern multi-core processors.
There is a version of Python without the GIL, but it &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=41677131&quot;&gt;doesn’t solve the performance issues&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;While tools like asyncio help with I&#x2F;O-bound tasks, CPU-intensive operations remain constrained. Teams often resort to complex workarounds involving multiple processes or C extensions.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;type-safety-concerns&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#type-safety-concerns&quot; aria-label=&quot;Anchor link for: type-safety-concerns&quot;&gt;Type Safety Concerns&lt;&#x2F;a&gt;&lt;&#x2F;h3&gt;
&lt;p&gt;Despite Python’s type hints, runtime type errors still occur.
Types are optional in Python.
Developers need the discipline to add and maintain type hints consistently, which can be challenging in large codebases.
Furthermore, adoption is inconsistent across the Python ecosyste (e.g., third-party libraries).
Large Python applications can become difficult to maintain and refactor confidently.&lt;&#x2F;p&gt;
&lt;p&gt;From experience, there is a breaking point around the 10-100k lines of code mark where the lack of type safety becomes a significant liability.&lt;sup class=&quot;footnote-reference&quot; id=&quot;fr-1-1&quot;&gt;&lt;a href=&quot;#fn-1&quot;&gt;1&lt;&#x2F;a&gt;&lt;&#x2F;sup&gt;&lt;&#x2F;p&gt;
&lt;h3 id=&quot;deployment-complexity&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#deployment-complexity&quot; aria-label=&quot;Anchor link for: deployment-complexity&quot;&gt;Deployment Complexity&lt;&#x2F;a&gt;&lt;&#x2F;h3&gt;
&lt;p&gt;Python applications require managing runtime environments, dependencies, and potential version conflicts.
A lot of the issues can be mitigated with containerization.
However, bundling Python applications for deployment is not an easy task, especially when targeting platforms with different architectures.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;resource-usage&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#resource-usage&quot; aria-label=&quot;Anchor link for: resource-usage&quot;&gt;Resource Usage&lt;&#x2F;a&gt;&lt;&#x2F;h3&gt;
&lt;p&gt;Python has a relatively manageable memory profile, but it can be inefficient for certain workloads.
For example, Python’s memory overhead can be significant for large-scale data processing or long-running services.
CPU-bound tasks often get offloaded to C extensions or to worker processes, adding complexity and overhead.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;key-challenges-in-transitioning-to-rust&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#key-challenges-in-transitioning-to-rust&quot; aria-label=&quot;Anchor link for: key-challenges-in-transitioning-to-rust&quot;&gt;Key Challenges in Transitioning to Rust&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;p&gt;The transition from Python to Rust presents unique challenges:&lt;&#x2F;p&gt;
&lt;h3 id=&quot;syntax&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#syntax&quot; aria-label=&quot;Anchor link for: syntax&quot;&gt;Syntax&lt;&#x2F;a&gt;&lt;&#x2F;h3&gt;
&lt;p&gt;Python is very syntax-light, which makes it easy to read and write.
By comparison, Rust is full of “symbols” and keywords that can be intimidating at first.&lt;&#x2F;p&gt;
&lt;p&gt;Developers need to see through the syntax and understand the underlying semantics to become productive.
This is a critical step in the transition process.&lt;&#x2F;p&gt;
&lt;p&gt;Here is an example of a simple list comprehension in Python:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;python&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;# A list of bands&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;bands&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; [&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #E9F284;&quot;&gt;    &amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt;Metallica&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E9F284;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #E9F284;&quot;&gt;    &amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt;Iron Maiden&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E9F284;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #E9F284;&quot;&gt;    &amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt;AC&#x2F;DC&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E9F284;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #E9F284;&quot;&gt;    &amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt;Judas Priest&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E9F284;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #E9F284;&quot;&gt;    &amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt;Megadeth&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E9F284;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;# A list comprehension to filter for bands that start with &amp;quot;M&amp;quot;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;m_bands&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; [band&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; for&lt;&#x2F;span&gt;&lt;span&gt; band&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; in&lt;&#x2F;span&gt;&lt;span&gt; bands&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; if&lt;&#x2F;span&gt;&lt;span&gt; band.startswith(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E9F284;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt;M&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E9F284;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;)]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;# A list comprehension to uppercase the bands&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;uppercased&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; [band.upper()&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; for&lt;&#x2F;span&gt;&lt;span&gt; band&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; in&lt;&#x2F;span&gt;&lt;span&gt; m_bands]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;# We get [&amp;quot;METALLICA&amp;quot;, &amp;quot;MEGADETH&amp;quot;] &lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Rust does not have a direct equivalent to list comprehensions.
Instead, &lt;a href=&quot;&#x2F;blog&#x2F;iterators&quot;&gt;iterator patterns&lt;&#x2F;a&gt; are used to achieve the same result:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;let&lt;&#x2F;span&gt;&lt;span&gt; bands&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; vec!&lt;&#x2F;span&gt;&lt;span&gt;[&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt;    &amp;quot;Metallica&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt;    &amp;quot;Iron Maiden&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt;    &amp;quot;AC&#x2F;DC&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt;    &amp;quot;Judas Priest&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt;    &amp;quot;Megadeth&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;];&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;let&lt;&#x2F;span&gt;&lt;span&gt; uppercased&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Vec&lt;&#x2F;span&gt;&lt;span&gt;&amp;lt;_&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; bands&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;iter&lt;&#x2F;span&gt;&lt;span&gt;()&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;                    .&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;filter&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;|&lt;&#x2F;span&gt;&lt;span&gt;band&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;|&lt;&#x2F;span&gt;&lt;span&gt; band&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;starts_with&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt;&amp;quot;M&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;))&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;                    .&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;map&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;|&lt;&#x2F;span&gt;&lt;span&gt;band&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;|&lt;&#x2F;span&gt;&lt;span&gt; band&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;to_uppercase&lt;&#x2F;span&gt;&lt;span&gt;())&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;                    .&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;collect&lt;&#x2F;span&gt;&lt;span&gt;();&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;&#x2F;&#x2F; uppercased = vec![&amp;quot;METALLICA&amp;quot;, &amp;quot;MEGADETH&amp;quot;]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;&lt;h3 id=&quot;ownership-and-borrowing&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#ownership-and-borrowing&quot; aria-label=&quot;Anchor link for: ownership-and-borrowing&quot;&gt;Ownership and Borrowing&lt;&#x2F;a&gt;&lt;&#x2F;h3&gt;
&lt;p&gt;Python developers need to adjust to start “thinking in Rust” to avoid common pitfalls.
Plan for a 3-4 month learning period where developers will need to understand concepts like:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;Stack vs heap&lt;&#x2F;li&gt;
&lt;li&gt;Borrowing and move semantics&lt;&#x2F;li&gt;
&lt;li&gt;Trait-based composition (instead of Python’s OOP model)&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;These are fundamental concepts in Rust that Python developers are not used to, and it’s important to get them right to become really effective.&lt;&#x2F;p&gt;
&lt;p&gt;Lifetimes are another concept that can be challenging to grasp initially, but you can get a long way without fully understanding them. &lt;a href=&quot;&#x2F;blog&#x2F;lifetimes&quot;&gt;Don’t worry about lifetimes&lt;&#x2F;a&gt; when you’re just starting out. &lt;a href=&quot;&#x2F;blog&#x2F;simple&quot;&gt;Keep it simple&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;Pointer handling and boxing is another area where Python developers need to adjust. However, beginners can often get by without understanding this in detail.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;type-system-adaptation&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#type-system-adaptation&quot; aria-label=&quot;Anchor link for: type-system-adaptation&quot;&gt;Type System Adaptation&lt;&#x2F;a&gt;&lt;&#x2F;h3&gt;
&lt;p&gt;Moving from Python’s dynamic typing to Rust’s static typing requires another mindset shift.
Developers suddenly need to:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;Think about types upfront&lt;&#x2F;li&gt;
&lt;li&gt;Understand generics and traits&lt;&#x2F;li&gt;
&lt;li&gt;Lean into &lt;code&gt;Option&amp;lt;T&amp;gt;&lt;&#x2F;code&gt; and &lt;code&gt;Result&amp;lt;T, E&amp;gt;&lt;&#x2F;code&gt; for error handling&lt;&#x2F;li&gt;
&lt;li&gt;Use enums for modeling complex states&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;This can feel intimidating at first, but it’s actually a lot of fun once you get the hang of it.
The compiler is helpfully guiding you along the way, and you can start without a deep understanding of all the concepts.&lt;&#x2F;p&gt;
&lt;p&gt;The pattern matching syntax in Rust can be a game-changer for developers coming from Python
and is often cited as one of the most enjoyable features of Rust.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;integration-strategies&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#integration-strategies&quot; aria-label=&quot;Anchor link for: integration-strategies&quot;&gt;Integration Strategies&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;p&gt;There are several ways to integrate Rust into your Python codebase:&lt;&#x2F;p&gt;
&lt;h3 id=&quot;1-pyo3-python-rust-bindings&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#1-pyo3-python-rust-bindings&quot; aria-label=&quot;Anchor link for: 1-pyo3-python-rust-bindings&quot;&gt;1. PyO3 (Python-Rust Bindings)&lt;&#x2F;a&gt;&lt;&#x2F;h3&gt;
&lt;p&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;pyo3.rs&#x2F;&quot;&gt;PyO3&lt;&#x2F;a&gt; lets you write Python extensions in Rust or call Rust functions from Python.&lt;&#x2F;p&gt;
&lt;p&gt;This is ideal for:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;Optimizing performance-critical components&lt;&#x2F;li&gt;
&lt;li&gt;Gradually introducing Rust while maintaining Python interfaces&lt;&#x2F;li&gt;
&lt;li&gt;Creating Python packages with Rust internals&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h3 id=&quot;2-microservices&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#2-microservices&quot; aria-label=&quot;Anchor link for: 2-microservices&quot;&gt;2. Microservices&lt;&#x2F;a&gt;&lt;&#x2F;h3&gt;
&lt;p&gt;For distributed systems, you can:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;Build new services in Rust&lt;&#x2F;li&gt;
&lt;li&gt;Migrate existing services one at a time&lt;&#x2F;li&gt;
&lt;li&gt;Use REST or gRPC for inter-service communication&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;If you already have a microservices architecture, this can be a great way to start.
You can build new services in Rust and gradually replace old Python services as needed.
The new services can be deployed alongside the old ones, and you can ensure that the APIs are compatible.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;3-cli-tools-and-utilities&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#3-cli-tools-and-utilities&quot; aria-label=&quot;Anchor link for: 3-cli-tools-and-utilities&quot;&gt;3. CLI Tools and Utilities&lt;&#x2F;a&gt;&lt;&#x2F;h3&gt;
&lt;p&gt;If you’re just starting out, I recommend to write a command-line tool, which is an excellent candidate for
getting your feet wet.&lt;&#x2F;p&gt;
&lt;p&gt;CLI tools have all the positive indicators for a successful first project:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;They are self-contained, so you don’t have to worry about integrating with the rest of the codebase&lt;&#x2F;li&gt;
&lt;li&gt;The deployment is simple, as you can just ship a single binary&lt;&#x2F;li&gt;
&lt;li&gt;Rust shines in this area, as it’s very convenient to write command-line tools in Rust&lt;&#x2F;li&gt;
&lt;li&gt;There is no “startup cost” when a CLI tool runs with Rust (as opposed to Python where the interpreter needs to start up)&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h3 id=&quot;4-worker-processes&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#4-worker-processes&quot; aria-label=&quot;Anchor link for: 4-worker-processes&quot;&gt;4. Worker Processes&lt;&#x2F;a&gt;&lt;&#x2F;h3&gt;
&lt;p&gt;Let’s say you have a web application that needs to do some heavy lifting.
One common way is to offload the work to a worker queue.
That’s a great place to test out Rust, as you can directly compare the performance and developer experience with Python.&lt;&#x2F;p&gt;
&lt;p&gt;You can use a message queue like RabbitMQ or Kafka to communicate between the Python web application and the Rust worker.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;data-processing-pipelines&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#data-processing-pipelines&quot; aria-label=&quot;Anchor link for: data-processing-pipelines&quot;&gt;Data Processing Pipelines&lt;&#x2F;a&gt;&lt;&#x2F;h3&gt;
&lt;p&gt;Are you using Python for data science or ETL tasks?
For example, you might be using Pandas or Dask for data processing.&lt;&#x2F;p&gt;
&lt;p&gt;Rust has some excellent libraries for data processing, like &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;pola.rs&#x2F;&quot;&gt;Polars&lt;&#x2F;a&gt; and &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;arrow.apache.org&#x2F;&quot;&gt;Apache Arrow&lt;&#x2F;a&gt;.
A lot of teams start by moving the data preprocessing and ETL tasks to Rust, and they like it so much that they move more and more of the business logic over.&lt;&#x2F;p&gt;
&lt;p&gt;That worked extremely well for a few clients I worked with, as they could leverage Rust’s performance and reliability for the most critical parts of their data processing pipeline.
After a short learning period, the team was as productive in Rust as they were in Python.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;planning-your-migration&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#planning-your-migration&quot; aria-label=&quot;Anchor link for: planning-your-migration&quot;&gt;Planning Your Migration&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;p&gt;A successful migration requires careful planning:&lt;&#x2F;p&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Start Small&lt;&#x2F;strong&gt;&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;Choose non-critical components first&lt;&#x2F;li&gt;
&lt;li&gt;Focus on areas where Rust’s benefits are most valuable&lt;&#x2F;li&gt;
&lt;li&gt;Build team confidence through early wins&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Invest in Training&lt;&#x2F;strong&gt;&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;Allocate time for learning Rust fundamentals&lt;&#x2F;li&gt;
&lt;li&gt;Consider bringing in &lt;a href=&quot;&#x2F;services&quot;&gt;external expertise&lt;&#x2F;a&gt; for guidance&lt;&#x2F;li&gt;
&lt;li&gt;Set realistic expectations for the learning curve&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Measure Success&lt;&#x2F;strong&gt;&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;Define clear metrics (performance, resource usage, development velocity)&lt;&#x2F;li&gt;
&lt;li&gt;Document improvements and challenges&lt;&#x2F;li&gt;
&lt;li&gt;Adjust strategy based on results&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;h2 id=&quot;practical-migration-tips&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#practical-migration-tips&quot; aria-label=&quot;Anchor link for: practical-migration-tips&quot;&gt;Practical Migration Tips&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;p&gt;Based on real-world experience from helping teams migrate from
Python to Rust, here are some tips for a successful transition:&lt;&#x2F;p&gt;
&lt;h3 id=&quot;identify-bounded-contexts&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#identify-bounded-contexts&quot; aria-label=&quot;Anchor link for: identify-bounded-contexts&quot;&gt;Identify Bounded Contexts&lt;&#x2F;a&gt;&lt;&#x2F;h3&gt;
&lt;p&gt;Focus on modules with clear interfaces to the rest of your system. No tangled spaghetti code!
(That also means that you should refactor your Python codebase in case it’s a mess.)&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;Look for self-contained parts of your codebase that share common functionality&lt;&#x2F;li&gt;
&lt;li&gt;Document the data flow and dependencies between these contexts. This will help you understand the impact of migration
and can serve as a blueprint for the migration process and a reference for future developers.&lt;&#x2F;li&gt;
&lt;li&gt;Map out how these components communicate with each other: which functions are called, which data is passed around, and which interfaces are used.&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h3 id=&quot;prioritize-cpu-bound-tasks-first&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#prioritize-cpu-bound-tasks-first&quot; aria-label=&quot;Anchor link for: prioritize-cpu-bound-tasks-first&quot;&gt;Prioritize CPU-Bound Tasks First&lt;&#x2F;a&gt;&lt;&#x2F;h3&gt;
&lt;p&gt;Start with computationally intensive operations that don’t require heavy I&#x2F;O.
That’s where Rust shines the most, as it can provide significant performance improvements over Python.&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;Look for tasks that are currently bottlenecked by Python’s performance (measure first!).&lt;&#x2F;li&gt;
&lt;li&gt;Avoid beginning with components that make heavy use of async&#x2F;IO operations.
Async Python is quite efficient and Rust might not provide a significant improvement.
Be cautious with async operations between languages, as they can introduce significant overhead.&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h3 id=&quot;minimize-calls-between-language-boundaries&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#minimize-calls-between-language-boundaries&quot; aria-label=&quot;Anchor link for: minimize-calls-between-language-boundaries&quot;&gt;Minimize Calls Between Language Boundaries&lt;&#x2F;a&gt;&lt;&#x2F;h3&gt;
&lt;p&gt;Evaluate how frequently your Rust code needs to call back into Python
and try to minimize the number of cross-language calls.&lt;&#x2F;p&gt;
&lt;p&gt;If you have a large number of small calls, the overhead of crossing the language boundary can add up.
Instead, consider batching operations to reduce the number of transitions&lt;&#x2F;p&gt;
&lt;h3 id=&quot;baby-steps&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#baby-steps&quot; aria-label=&quot;Anchor link for: baby-steps&quot;&gt;Baby Steps&lt;&#x2F;a&gt;&lt;&#x2F;h3&gt;
&lt;p&gt;Break down the migration into small, measurable pieces. You want quick wins to keep the team motivated.&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;Start with a single component and validate its performance.&lt;&#x2F;li&gt;
&lt;li&gt;Add functionality piece by piece rather than attempting a complete rewrite.&lt;&#x2F;li&gt;
&lt;li&gt;Maintain comprehensive tests throughout the migration process.&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h3 id=&quot;continuously-monitor-performance&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#continuously-monitor-performance&quot; aria-label=&quot;Anchor link for: continuously-monitor-performance&quot;&gt;Continuously Monitor Performance&lt;&#x2F;a&gt;&lt;&#x2F;h3&gt;
&lt;p&gt;Do you have a performance baseline for your Python code?
If not, set one up before you start the migration.
It’s very easy to get lost in the weeds and lose track of the performance improvements.
If that happens, you have no clear way to measure the success of the migration.&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;Set up benchmarks before starting the migration.&lt;&#x2F;li&gt;
&lt;li&gt;Track performance metrics for each migrated component.&lt;&#x2F;li&gt;
&lt;li&gt;Use tools like &lt;code&gt;cspeed&lt;&#x2F;code&gt; to monitor improvements.&lt;&#x2F;li&gt;
&lt;li&gt;Document performance gains and any unexpected bottlenecks.&lt;&#x2F;li&gt;
&lt;li&gt;Make performance monitoring part of your PR review process.&lt;&#x2F;li&gt;
&lt;li&gt;Choose components where you can easily compare performance.&lt;&#x2F;li&gt;
&lt;li&gt;Look for opportunities to run old and new implementations in parallel.&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h2 id=&quot;common-pitfalls-to-avoid&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#common-pitfalls-to-avoid&quot; aria-label=&quot;Anchor link for: common-pitfalls-to-avoid&quot;&gt;Common Pitfalls to Avoid&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;p&gt;Rust’s ecosystem is smaller than Python’s.&lt;&#x2F;p&gt;
&lt;p&gt;On top of that, Rust has a much smaller standard library compared to Python.
This means you’ll commonly rely on third-party crates for functionality that’s built into Python.&lt;&#x2F;p&gt;
&lt;p&gt;Depending on your use case, here are some comparisons between Python packages and their Rust equivalents:&lt;&#x2F;p&gt;
&lt;h3 id=&quot;data-science&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#data-science&quot; aria-label=&quot;Anchor link for: data-science&quot;&gt;Data Science&lt;&#x2F;a&gt;&lt;&#x2F;h3&gt;
&lt;p&gt;Python dominates data science with libraries like &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;numpy.org&#x2F;&quot;&gt;NumPy&lt;&#x2F;a&gt; and &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;pandas.pydata.org&#x2F;&quot;&gt;Pandas&lt;&#x2F;a&gt;.
However, Rust is making inroads with libraries like &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;pola.rs&#x2F;&quot;&gt;Polars&lt;&#x2F;a&gt; and &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;arrow.apache.org&#x2F;&quot;&gt;Apache’s Arrow&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;You don’t have to migrate your entire data science stack to Rust.
Chances are, you have experts on your team who are comfortable with doing data analysis in Python.
You can start by using the Rust libraries for data preprocessing and ETL tasks.
They have Python bindings, so you get a lot of the benefits of Rust without having to do a full migration.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;backend-services&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#backend-services&quot; aria-label=&quot;Anchor link for: backend-services&quot;&gt;Backend Services&lt;&#x2F;a&gt;&lt;&#x2F;h3&gt;
&lt;p&gt;Rust wasn’t initially planned to be a strong contender in the web development space.
This has changed in recent years with the rise of frameworks like &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;axum.rs&#x2F;&quot;&gt;Axum&lt;&#x2F;a&gt; and &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;loco.rs&#x2F;&quot;&gt;Loco&lt;&#x2F;a&gt;.
Now, Rust is a viable option for building high-performance APIs and web applications.
It is one key area the Rust team is investing in, and the ecosystem is maturing rapidly.&lt;&#x2F;p&gt;
&lt;p&gt;In combination with &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;launchbadge&#x2F;sqlx&quot;&gt;sqlx&lt;&#x2F;a&gt; for database access and &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;serde.rs&#x2F;&quot;&gt;serde&lt;&#x2F;a&gt; for serialization, Rust is a very effective choice for web backends.
What surprises many Python developers is how similar it is to working with other web frameworks like Flask or FastAPI.
Another surprise is how robust the final product is, as it catches many bugs at compile time and scales extremely well.
Production Rust web applications are extremely robust.
This lifts a lot of the burden from the operations team.
I expect more backend services to be written in Rust in the future – especially for high-performance applications.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;keeping-python-s-strengths&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#keeping-python-s-strengths&quot; aria-label=&quot;Anchor link for: keeping-python-s-strengths&quot;&gt;Keeping Python’s Strengths&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;p&gt;Not everything needs to be migrated! Python excels at:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;&#x2F;blog&#x2F;prototyping&quot;&gt;I personally prototype in Rust&lt;&#x2F;a&gt;, but Python is still a fine choice for prototyping.&lt;&#x2F;li&gt;
&lt;li&gt;Data analysis and visualization are great in Python (e.g., Pandas, Matplotlib)&lt;&#x2F;li&gt;
&lt;li&gt;Machine learning workflows (e.g., TensorFlow, PyTorch)&lt;&#x2F;li&gt;
&lt;li&gt;Admin interfaces and tools (e.g., Django admin)&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;Consider a hybrid approach where each language handles what it does best.&lt;&#x2F;p&gt;
&lt;p&gt;One winning strategy is to explore a space in Python and moving production-workloads to Rust once the requirements are clear
and the project can benefit from performance and scale.
Speaking of which…&lt;&#x2F;p&gt;
&lt;h2 id=&quot;expected-big-performance-improvements&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#expected-big-performance-improvements&quot; aria-label=&quot;Anchor link for: expected-big-performance-improvements&quot;&gt;Expected Big Performance Improvements&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;p&gt;Actual performance numbers vary significantly based on workload and implementation,
so take these numbers with a grain of salt.&lt;&#x2F;p&gt;
&lt;p&gt;Based on my experience helping teams migrate, here are typical improvements:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;CPU Usage&lt;&#x2F;strong&gt;: 2-10x reduction in CPU utilization&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Memory Usage&lt;&#x2F;strong&gt;: 30-70% reduction in memory footprint&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Latency&lt;&#x2F;strong&gt;: 50-90% improvement in response times&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Throughput&lt;&#x2F;strong&gt;: 2-5x increase in requests&#x2F;second&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;Especially the P90 latency improvements are often surprising to teams.
&lt;strong&gt;There are very few outliers and things tend to run smoothly, no matter the load.&lt;&#x2F;strong&gt;
In Python, this is a common source of frustration, where a single request can take significantly longer than the rest.
Production payloads are extremely boring in Rust. The DevOps team will thank you.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;conclusion&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#conclusion&quot; aria-label=&quot;Anchor link for: conclusion&quot;&gt;Conclusion&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;p&gt;Migrating to a different programming language is a significant undertaking that requires careful planning and execution.
The step from Python to Rust is no exception.&lt;&#x2F;p&gt;
&lt;p&gt;While the learning curve is steep, the benefits in terms of performance, reliability, and maintainability can be substantial.&lt;&#x2F;p&gt;
&lt;p&gt;Success depends on:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;Realistic timeline expectations&lt;&#x2F;li&gt;
&lt;li&gt;Strong team support and training&lt;&#x2F;li&gt;
&lt;li&gt;Clear understanding of migration goals&lt;&#x2F;li&gt;
&lt;li&gt;A pragmatic approach to choosing what to migrate&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;Remember that this isn’t an all-or-nothing decision!
Many organizations successfully use Python and Rust together, leveraging each language’s strengths.
Write down your reasoning for the migration.
Many issues can be solved in Python, and the migration might not be necessary.
However, if you’re hitting the limits of Python, Rust is a strong replacement.&lt;&#x2F;p&gt;
&lt;div class=&quot;info&quot;&gt;
  
  &lt;div class=&quot;info-header&quot;&gt;
    
      &lt;span class=&quot;icon icon-crab&quot;&gt;&lt;&#x2F;span&gt;
    
    &lt;h4&gt;&lt;p&gt;Ready to Make the Move to Rust?&lt;&#x2F;p&gt;
&lt;&#x2F;h4&gt;
  &lt;&#x2F;div&gt;
  
  &lt;p&gt;I help teams make successful transitions from Python to Rust.
My clients moved critical workloads to Rust and saw significant improvements in performance and reliability.
Whether you need training, architecture guidance, or migration planning, &lt;a href=&quot;&#x2F;services&quot;&gt;let’s talk about your needs&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;

&lt;&#x2F;div&gt;
&lt;section class=&quot;footnotes&quot;&gt;
&lt;ol class=&quot;footnotes-list&quot;&gt;
&lt;li id=&quot;fn-1&quot;&gt;
&lt;p&gt;See discussions on large-scale Python applications on &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.reddit.com&#x2F;r&#x2F;Python&#x2F;comments&#x2F;a7zrjn&#x2F;why_do_people_say_that_python_is_not_good_for&#x2F;&quot;&gt;Reddit&lt;&#x2F;a&gt; and &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=25073308&quot;&gt;HN&lt;&#x2F;a&gt;. &lt;a href=&quot;#fr-1-1&quot;&gt;↩&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;&#x2F;section&gt;
</description>
      </item>
      <item>
          <title>Migrating from TypeScript to Rust</title>
          <pubDate>Fri, 13 Dec 2024 00:00:00 +0000</pubDate>
          <author>Matthias Endler</author>
          <link>https://corrode.dev/learn/migration-guides/typescript-to-rust/</link>
          <guid>https://corrode.dev/learn/migration-guides/typescript-to-rust/</guid>
          <description xml:base="https://corrode.dev/learn/migration-guides/typescript-to-rust/">&lt;div class=&quot;info&quot;&gt;
  
  &lt;div class=&quot;info-header&quot;&gt;
    
      &lt;span class=&quot;icon icon-info&quot;&gt;&lt;&#x2F;span&gt;
    
    &lt;h4&gt;&lt;p&gt;A Practical Guide for Decision Makers&lt;&#x2F;p&gt;
&lt;&#x2F;h4&gt;
  &lt;&#x2F;div&gt;
  
  &lt;p&gt;I wrote this guide for technical leaders and developers considering a move from TypeScript to Rust.
After years of helping teams make this transition, I’ll share what works, what doesn’t, and how to make your migration successful.&lt;&#x2F;p&gt;

&lt;&#x2F;div&gt;
&lt;p&gt;TypeScript excels at making JavaScript more maintainable, but teams often hit scaling challenges as their codebases grow.
You might be facing performance bottlenecks, reliability issues, or maintenance overhead.
Rust offers compelling solutions to these problems, but migration needs careful planning and execution.
Let me show you how to evaluate if Rust is right for your team, plan a successful migration, and keep your team productive during the transition.&lt;&#x2F;p&gt;
&lt;p&gt;In this article, you’ll learn:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;How to evaluate if Rust is right for your team&lt;&#x2F;li&gt;
&lt;li&gt;Practical strategies for TypeScript-to-Rust migration&lt;&#x2F;li&gt;
&lt;li&gt;Common pitfalls and how to avoid them&lt;&#x2F;li&gt;
&lt;li&gt;Ways to maintain productivity during transition&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h2 id=&quot;key-differences-between-typescript-and-rust&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#key-differences-between-typescript-and-rust&quot; aria-label=&quot;Anchor link for: key-differences-between-typescript-and-rust&quot;&gt;Key Differences Between TypeScript and Rust&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;table&gt;&lt;thead&gt;&lt;tr&gt;&lt;th&gt;Aspect&lt;&#x2F;th&gt;&lt;th&gt;TypeScript&lt;&#x2F;th&gt;&lt;th&gt;Rust&lt;&#x2F;th&gt;&lt;&#x2F;tr&gt;&lt;&#x2F;thead&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;1.0 Release&lt;&#x2F;td&gt;&lt;td&gt;2014&lt;&#x2F;td&gt;&lt;td&gt;2015&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;Packages&lt;&#x2F;td&gt;&lt;td&gt;3 million+ (npm)&lt;&#x2F;td&gt;&lt;td&gt;160,000+ (crates.io)&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;Type System&lt;&#x2F;td&gt;&lt;td&gt;Optional&lt;&#x2F;td&gt;&lt;td&gt;Mandatory&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;Tooling&lt;&#x2F;td&gt;&lt;td&gt;Rich ecosystem, frequent updates&lt;&#x2F;td&gt;&lt;td&gt;Stable, integrated toolchain&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;Memory Management&lt;&#x2F;td&gt;&lt;td&gt;Garbage collected&lt;&#x2F;td&gt;&lt;td&gt;Ownership system, compile-time checks&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;Speed&lt;&#x2F;td&gt;&lt;td&gt;Moderate&lt;&#x2F;td&gt;&lt;td&gt;Fast&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;Error Handling&lt;&#x2F;td&gt;&lt;td&gt;Exceptions&lt;&#x2F;td&gt;&lt;td&gt;Explicit handling with &lt;code&gt;Result&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;Learning Curve&lt;&#x2F;td&gt;&lt;td&gt;Moderate&lt;&#x2F;td&gt;&lt;td&gt;Steep&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;&#x2F;tbody&gt;&lt;&#x2F;table&gt;
&lt;h2 id=&quot;why-teams-consider-rust&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#why-teams-consider-rust&quot; aria-label=&quot;Anchor link for: why-teams-consider-rust&quot;&gt;Why Teams Consider Rust&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;p&gt;TypeScript is a great language, but many teams hit a wall around the 10k to 100k lines of code mark.
At this scale, the codebase becomes hard to maintain and teams start to feel the pain.
The honeymoon phase with TypeScript codebases is surprisingly short - when working with larger applications, adding functionality or performing large-scale refactoring becomes increasingly challenging.&lt;&#x2F;p&gt;
&lt;p&gt;The problems are clear and specific.
While TypeScript has a type system, it remains a dynamically typed language built on JavaScript.
Types are optional and can be &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;dev.to&#x2F;martinpersson&#x2F;a-guide-to-using-the-option-type-in-typescript-ki2&quot;&gt;bypassed using &lt;code&gt;any&lt;&#x2F;code&gt; or &lt;code&gt;unknown&lt;&#x2F;code&gt;&lt;&#x2F;a&gt; or by freely &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;medium.com&#x2F;livefront&#x2F;to-cast-or-not-to-cast-a-typescript-dilemma-c0c20c53c6d9&quot;&gt;casting&lt;&#x2F;a&gt; between types.
Without enough discipline, this leads to runtime errors and bugs.&lt;&#x2F;p&gt;
&lt;p&gt;Memory leaks and security vulnerabilities become more common, especially in large, long-running backend services.
Some companies I’ve worked with needed regular service restarts to manage memory leaks.&lt;&#x2F;p&gt;
&lt;p&gt;External packages often have security vulnerabilities and need regular updates.
Breaking changes are common, and packages frequently become &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.aquasec.com&#x2F;blog&#x2F;deceptive-deprecation-the-truth-about-npm-deprecated-packages&#x2F;&quot;&gt;unmaintained&lt;&#x2F;a&gt;.
&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.propelauth.com&#x2F;post&#x2F;nextjs-challenges&quot;&gt;Frameworks like Next.js introduce frequent breaking changes&lt;&#x2F;a&gt;, forcing teams to spend time on updates instead of business logic.&lt;&#x2F;p&gt;
&lt;p&gt;Performance isn’t guaranteed.
TypeScript is fast enough for most cases, but performance-critical applications will hit limitations.
&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;dev.to&#x2F;mpiorowski&#x2F;typescript-with-gorust-errors-no-trycatch-heresy-49mf&quot;&gt;Error handling through exceptions and promises can be hard to reason about.&lt;&#x2F;a&gt;
Large TypeScript codebases become difficult to refactor and maintain, even with type safety.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;typescript-as-a-bridge-to-rust&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#typescript-as-a-bridge-to-rust&quot; aria-label=&quot;Anchor link for: typescript-as-a-bridge-to-rust&quot;&gt;TypeScript as a Bridge to Rust&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;p&gt;TypeScript’s type system creates an excellent foundation for Rust adoption.
Your team already understands static typing and values its benefits.
This gives you a head start with Rust, which takes these concepts further and adds more powerful guarantees.&lt;&#x2F;p&gt;
&lt;p&gt;The developer experience differs in two key ways: Rust has stronger type guarantees but slower compile times compared to TypeScript.
Many developers find this tradeoff worthwhile, especially because you can write high-level Rust code without dropping into systems-level programming.
Rust’s powerful abstractions like the trait system and generics allow you to model behavior in just the right way.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;understanding-rust-s-learning-curve&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#understanding-rust-s-learning-curve&quot; aria-label=&quot;Anchor link for: understanding-rust-s-learning-curve&quot;&gt;Understanding Rust’s Learning Curve&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;p&gt;Rust enforces stronger guarantees than TypeScript through its ownership system and borrow checker.
You’ll need to plan for an adjustment period.
Most developers need 2-4 months to become comfortable with Rust’s ownership model.
They’ll go through a phase of &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.youtube.com&#x2F;watch?v=ZNFdkTIzdXM&quot;&gt;“fighting the borrow checker”&lt;&#x2F;a&gt; – this is normal and temporary.
Your job is to keep the team motivated during this learning curve.
I’ve seen time and again that developers who push through this phase become the strongest Rust advocates.
These developers then become valuable mentors for their teammates.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;rust-has-its-roots-in-systems-programming&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#rust-has-its-roots-in-systems-programming&quot; aria-label=&quot;Anchor link for: rust-has-its-roots-in-systems-programming&quot;&gt;Rust Has Its Roots In Systems Programming&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;p&gt;Rust pushes your team to understand systems concepts better than TypeScript ever required.
You need to know the difference between stack and heap allocation.
You’ll work with different string types like &lt;code&gt;String&lt;&#x2F;code&gt; and &lt;code&gt;&amp;amp;str&lt;&#x2F;code&gt;.
And you should be willing to learn what a pointer or a mutex is.&lt;&#x2F;p&gt;
&lt;p&gt;These concepts might seem intimidating at first, but they make Rust fast.
Rust won’t hide these details from you.
The idea is that explicit is better than implicit.&lt;&#x2F;p&gt;
&lt;p&gt;Your team will write more efficient code because Rust makes these low-level details explicit and manageable.&lt;&#x2F;p&gt;
&lt;p&gt;You don’t need to be a systems programmer to use Rust and yet, you will need to learn these concepts
to become proficient in Rust.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;safety-and-reliability&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#safety-and-reliability&quot; aria-label=&quot;Anchor link for: safety-and-reliability&quot;&gt;Safety and Reliability&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;p&gt;The strict Rust compiler is your strongest ally.
You can refactor without fear because the compiler catches mistakes early and consistently.
You won’t deal with &lt;code&gt;null&lt;&#x2F;code&gt; or &lt;code&gt;undefined&lt;&#x2F;code&gt; errors.
Error handling becomes explicit and predictable with &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;doc.rust-lang.org&#x2F;std&#x2F;result&#x2F;&quot;&gt;&lt;code&gt;Result&lt;&#x2F;code&gt;&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;ecosystem-maturity&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#ecosystem-maturity&quot; aria-label=&quot;Anchor link for: ecosystem-maturity&quot;&gt;Ecosystem Maturity&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;p&gt;NPM gives you more packages, but Rust’s ecosystem prioritizes quality.&lt;&#x2F;p&gt;
&lt;blockquote&gt;
&lt;p&gt;In September 2022 over 2.1 million packages were reported being listed in the npm registry, making it the biggest single language code repository on Earth – Source: &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;nodejs.org&#x2F;en&#x2F;learn&#x2F;getting-started&#x2F;an-introduction-to-the-npm-package-manager&quot;&gt;Nodejs.org&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
&lt;p&gt;A small portion of these packages provide type definitions (i.e. TypeScript support).
Many packages are outdated or are actively maintained.
According to &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.scworld.com&#x2F;news&#x2F;npm-registry-users-download-2-1b-deprecated-packages-weekly-researchers-say&quot;&gt;SC Media&lt;&#x2F;a&gt;, “NPM registry users download 2.1B deprecated packages weekly”.&lt;&#x2F;p&gt;
&lt;p&gt;Compare that to Rust’s crate ecosystem.
At the time of writing, it lists &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;crates.io&#x2F;&quot;&gt;170.435 crates&lt;&#x2F;a&gt;.
That is a fraction of NPM’s packages.
Crates also can’t be easily removed from the registry:&lt;&#x2F;p&gt;
&lt;blockquote&gt;
&lt;p&gt;Take care when publishing a crate, because a publish is permanent. The version can never be overwritten, and the code cannot be deleted. There is no limit to the number of versions which can be published, however.&lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
&lt;p&gt;That’s a feature, not a bug.
It means that your build pipelines won’t break due to a missing dependency.
You can &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;doc.rust-lang.org&#x2F;cargo&#x2F;reference&#x2F;publishing.html#cargo-yank&quot;&gt;yank&lt;&#x2F;a&gt; a version to indicate that it’s no longer supported, but the code remains available for those who depend on it.&lt;&#x2F;p&gt;
&lt;p&gt;Libraries maintain strong backward compatibility.
Breaking changes are rare.
Rust itself releases new &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;doc.rust-lang.org&#x2F;edition-guide&#x2F;editions&#x2F;&quot;&gt;editions&lt;&#x2F;a&gt; every three years with opt-in changes.&lt;&#x2F;p&gt;
&lt;p&gt;The quality difference becomes especially noticeable in larger applications.
While the Rust ecosystem may be smaller, the crates are typically more reliable and provide better documentation compared to the TypeScript ecosystem.
When you build a large application, that higher quality standard makes a significant difference.&lt;&#x2F;p&gt;
&lt;p&gt;Many Rust crates stay in 0.x versions longer than you might expect.
Don’t let this worry you – Rust’s type system ensures robust functionality even before reaching 1.0.
The ecosystem grows fast, and the existing libraries work reliably.
For specific use cases, writing your own library is common and well-supported.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;rust-vs-typescript-for-backend-services&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#rust-vs-typescript-for-backend-services&quot; aria-label=&quot;Anchor link for: rust-vs-typescript-for-backend-services&quot;&gt;Rust vs TypeScript For Backend Services&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;p&gt;TypeScript is a great language for backend services.
A lot of companies use it successfully.
There are many frameworks to choose from, like Express, NestJS, or Fastify.
These frameworks are mature and well-documented.&lt;&#x2F;p&gt;
&lt;p&gt;By comparison, Rust’s backend ecosystem is smaller.
You have Axum, Actix, and Rocket, among others.
These frameworks are fast and reliable, but they don’t provide a “batteries-included” experience like Express.&lt;&#x2F;p&gt;
&lt;p&gt;That said, Rust’s ecosystem is growing fast and most companies find the available libraries sufficient.
I personally recommend &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;tokio-rs&#x2F;axum&quot;&gt;axum&lt;&#x2F;a&gt; as it has the largest momentum and is backed by the Tokio team.&lt;&#x2F;p&gt;
&lt;p&gt;Deployment is straightforward.
You can build your Rust service into a single binary and deploy it to a container or a server.
Rust binaries are small and have no runtime dependencies.
This makes deployment easy and reliable.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;rust-is-really-fast&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#rust-is-really-fast&quot; aria-label=&quot;Anchor link for: rust-is-really-fast&quot;&gt;Rust is Really Fast&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;p&gt;Teams are often shocks that Rust is so fast.
They go in expecting Rust to be fast, but the reality still surprises them.
You can expect an order of magnitude better CPU and memory usage if you’re coming from JS&#x2F;TS.
The effects of that are very real: reduced cloud costs, less hardware, and faster response times.&lt;&#x2F;p&gt;
&lt;p&gt;Most importantly, &lt;strong&gt;your runtime behavior becomes predictable&lt;&#x2F;strong&gt;.
Production incidents decrease.
Your operations team will thank you for the reduced overhead.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;planning-your-migration&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#planning-your-migration&quot; aria-label=&quot;Anchor link for: planning-your-migration&quot;&gt;Planning Your Migration&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;p&gt;Write down why you want to migrate before you start:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;What problems do you face today?&lt;&#x2F;li&gt;
&lt;li&gt;Why will Rust solve these problems?&lt;&#x2F;li&gt;
&lt;li&gt;Could you fix them in TypeScript instead?&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;This clarity helps when things get tough.&lt;&#x2F;p&gt;
&lt;p&gt;I know this evaluation isn’t easy.
We often struggle to see our codebase’s problems clearly.
Politics and inertia hold us back.
Sometimes you need an outside perspective.
I can help you evaluate your situation objectively and create a solid migration plan.
This might sound expensive, but think about your team’s salaries and the cost of making the wrong decision.
Good consulting pays for itself quickly. &lt;a href=&quot;&#x2F;services&quot;&gt;Reach out for a free consultation&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;integration-strategies&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#integration-strategies&quot; aria-label=&quot;Anchor link for: integration-strategies&quot;&gt;Integration Strategies&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;p&gt;You have two main ways to integrate Rust with TypeScript.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;webassembly&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#webassembly&quot; aria-label=&quot;Anchor link for: webassembly&quot;&gt;WebAssembly&lt;&#x2F;a&gt;&lt;&#x2F;h3&gt;
&lt;p&gt;You can use WebAssembly (WASM) to compile your Rust code to a library and call it directly from TypeScript.
This works great for speeding up performance-critical components.
Teams often start here and expand their Rust usage as they see the benefits.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;standalone-web-service&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#standalone-web-service&quot; aria-label=&quot;Anchor link for: standalone-web-service&quot;&gt;Standalone Web-Service&lt;&#x2F;a&gt;&lt;&#x2F;h3&gt;
&lt;p&gt;Alternatively, you can deploy Rust as separate services.
This fits well with microservice architectures.
Your TypeScript and Rust components communicate over the network.
This gives you a clean separation and lets you migrate gradually.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;find-a-rust-champion&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#find-a-rust-champion&quot; aria-label=&quot;Anchor link for: find-a-rust-champion&quot;&gt;Find A Rust Champion&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;p&gt;You need a Rust champion in your team.
This person should have some prior Rust experience and be excited about the language.&lt;&#x2F;p&gt;
&lt;p&gt;Outside help can get you started, but keep the knowledge in-house.
You know your codebase and business domain best.
A consultant helps with the tricky Rust parts, team augmentation, and training,
but your team maintains and extends the codebase in the long run.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;strong&gt;They need to believe in the mission.&lt;&#x2F;strong&gt;&lt;&#x2F;p&gt;
&lt;p&gt;In order to succeed, your Rust champion needs to be able to motivate the team, answer questions, and guide the team through the learning curve.
They work hand-in-hand with the consultant to ensure the team’s success.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;starting-your-journey&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#starting-your-journey&quot; aria-label=&quot;Anchor link for: starting-your-journey&quot;&gt;Starting Your Journey&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;p&gt;Don’t rewrite everything at once!
Start small.
Maybe pick a monitoring service or CLI tool – something important but not critical.
Perhaps you’ll give it a shot during a hackathon or a sprint.
Build confidence through early wins.&lt;&#x2F;p&gt;
&lt;div class=&quot;info&quot;&gt;
  
  &lt;div class=&quot;info-header&quot;&gt;
    
      &lt;span class=&quot;icon icon-crab&quot;&gt;&lt;&#x2F;span&gt;
    
    &lt;h4&gt;&lt;p&gt;Ready to make the switch to Rust?&lt;&#x2F;p&gt;
&lt;&#x2F;h4&gt;
  &lt;&#x2F;div&gt;
  
  &lt;p&gt;I help teams make successful transitions from TypeScript to Rust.
Whether you need training, architecture guidance, or migration planning, &lt;a href=&quot;&#x2F;services&quot;&gt;let’s talk about your needs&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;

&lt;&#x2F;div&gt;
</description>
      </item>
      <item>
          <title>Zoo</title>
          <pubDate>Thu, 12 Dec 2024 00:00:00 +0000</pubDate>
          <author>Matthias Endler</author>
          <link>https://corrode.dev/podcast/s03e05-zoo/</link>
          <guid>https://corrode.dev/podcast/s03e05-zoo/</guid>
          <description xml:base="https://corrode.dev/podcast/s03e05-zoo/">&lt;div&gt;&lt;script id=&quot;letscast-player-34099980&quot; src=&quot;https:&#x2F;&#x2F;letscast.fm&#x2F;podcasts&#x2F;rust-in-production-82281512&#x2F;episodes&#x2F;zoo-with-jessie-frazelle&#x2F;player.js?size=s&quot;&gt;&lt;&#x2F;script&gt;&lt;&#x2F;div&gt;
&lt;p&gt;Think about this: software engineers have modern code editors, parallel processing, continuous integration, and countless tools that make their work efficient. But hardware engineers? They’re often working with single-threaded tools, limited automation, and workflows that haven’t fundamentally changed in decades. Zoo is building the infrastructure to change that, creating a modern set of tools and APIs that will allow companies and engineers to build better hardware design tools and accelerate the development of physical products.&lt;&#x2F;p&gt;</description>
      </item>
      <item>
          <title>Migrating from Java to Rust</title>
          <pubDate>Mon, 09 Dec 2024 00:00:00 +0000</pubDate>
          <author>Matthias Endler</author>
          <link>https://corrode.dev/learn/migration-guides/java-to-rust/</link>
          <guid>https://corrode.dev/learn/migration-guides/java-to-rust/</guid>
          <description xml:base="https://corrode.dev/learn/migration-guides/java-to-rust/">&lt;div class=&quot;info&quot;&gt;
  
  &lt;div class=&quot;info-header&quot;&gt;
    
      &lt;span class=&quot;icon icon-info&quot;&gt;&lt;&#x2F;span&gt;
    
    &lt;h4&gt;&lt;p&gt;A Practical Guide for Decision Makers&lt;&#x2F;p&gt;
&lt;&#x2F;h4&gt;
  &lt;&#x2F;div&gt;
  
  &lt;p&gt;This article is aimed at technical product managers and CTOs who are considering migrating a production Java application — or part of it — to Rust.
I will give an &lt;strong&gt;honest overview&lt;&#x2F;strong&gt; of the challenges and benefits of such a migration, as well as practical tips to make it successful
based on years of experience and successful transitions.&lt;&#x2F;p&gt;

&lt;&#x2F;div&gt;
&lt;p&gt;Java is an amazing language.
It’s a true workhorse, powering some of the world’s most critical systems.
Even so, large organizations are increasingly looking to Rust as a way to improve reliability, resource usage, and reduce costs.
Decision makers need to weigh the benefits and risks of migrating to Rust, and it’s not always an easy choice.&lt;&#x2F;p&gt;
&lt;p&gt;In this article, you’ll learn:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;How to plan and execute a successful Java-to-Rust migration&lt;&#x2F;li&gt;
&lt;li&gt;Common pitfalls to avoid during the transition&lt;&#x2F;li&gt;
&lt;li&gt;Practical strategies for managing mixed Java&#x2F;Rust codebases&lt;&#x2F;li&gt;
&lt;li&gt;How to measure success and maintain productivity during migration&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;By the end, you’ll have a clear idea if Rust is the right choice for your organization and if so, how to make the transition as smooth as possible.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;get-your-customized-migration-plan&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#get-your-customized-migration-plan&quot; aria-label=&quot;Anchor link for: get-your-customized-migration-plan&quot;&gt;Get Your Customized Migration Plan&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;p&gt;I help teams migrate from Java to Rust, providing tailored guidance and training.
If you’re considering a migration, answer a few questions about your project, and I’ll reach out with a customized plan.&lt;&#x2F;p&gt;
&lt;div class=&quot;quiz-container&quot;&gt;
  &lt;div class=&quot;quiz-progress-container&quot;&gt;
    &lt;div class=&quot;progress-bar&quot; id=&quot;progress-bar&quot; style=&quot;width: 0%&quot;&gt;&lt;&#x2F;div&gt;
  &lt;&#x2F;div&gt;
  &lt;div id=&quot;quiz-question-container&quot;&gt;&lt;&#x2F;div&gt;

  &lt;div id=&quot;quiz-navigation-container&quot;&gt;
    &lt;button
      class=&quot;quiz-navbutton&quot;
      id=&quot;quiz-prev-question&quot;
      style=&quot;display: none&quot;
    &gt;
      ← Previous
    &lt;&#x2F;button&gt;
    &lt;button class=&quot;quiz-navbutton&quot; id=&quot;quiz-next-question&quot;&gt;Next →&lt;&#x2F;button&gt;
  &lt;&#x2F;div&gt;

  &lt;div id=&quot;quiz-results&quot; style=&quot;display: none&quot;&gt;
    &lt;h2&gt;Thank you for your interest!&lt;&#x2F;h2&gt;
    &lt;p&gt;
      I&#x27;ll send you a customized migration strategy based on your responses.
    &lt;&#x2F;p&gt;
    &lt;p&gt;
      In the meantime, feel free to check out my
      &lt;a href=&quot;&#x2F;blog&quot;&gt;other articles about Rust&lt;&#x2F;a&gt;.
    &lt;&#x2F;p&gt;
  &lt;&#x2F;div&gt;
&lt;&#x2F;div&gt;

&lt;script&gt;
  const languageOptions = [
    &quot;Python&quot;,
    &quot;Java&quot;,
    &quot;C++&quot;,
    &quot;Go&quot;,
    &quot;TypeScript&quot;,
    &quot;JavaScript&quot;,
    &quot;C#&quot;,
    &quot;Ruby&quot;,
    &quot;PHP&quot;,
    &quot;Swift&quot;,
    &quot;Kotlin&quot;,
    &quot;Other&quot;,
  ];

  const questions = [
  {
    type: &quot;multipleChoice&quot;,
    question: &quot;Which languages are currently used in your codebase?&quot;,
    id: &quot;currentLanguages&quot;,
    options: languageOptions,
  },
  {
    type: &quot;multipleChoice&quot;,
    question: &quot;Which types of applications are you looking to migrate?&quot;,
    id: &quot;applicationType&quot;,
    direction: &quot;column&quot;,
    options: [
      &quot;Web services &#x2F; APIs&quot;,
      &quot;Desktop applications&quot;,
      &quot;CLI tools&quot;,
      &quot;Embedded systems&quot;,
      &quot;WebAssembly modules&quot;,
      &quot;Data processing pipelines&quot;,
      &quot;Machine learning systems&quot;,
      &quot;Other&quot;,
    ],
  },
  {
    type: &quot;radio&quot;,
    question: &quot;What&#x27;s the size of your codebase?&quot;,
    id: &quot;codebaseSize&quot;,
    options: [&quot;&lt; 10k lines&quot;, &quot;&lt; 100k lines&quot;, &quot;&gt; 100k lines&quot;],
  },
  {
    type: &quot;radio&quot;,
    question: &quot;What&#x27;s your team&#x27;s experience with Rust?&quot;,
    id: &quot;rustExperience&quot;,
    direction: &quot;column&quot;,
    options: [
      &quot;No experience yet&quot;,
      &quot;Some team members have experimented with it&quot;,
      &quot;We have one or more small projects in production&quot;,
      &quot;We have significant production experience&quot;,
    ],
  },
  {
    type: &quot;multipleChoice&quot;,
    question: &quot;What are your main motivations for migrating to Rust?&quot;,
    direction: &quot;column&quot;,
    id: &quot;motivations&quot;,
    options: [
      &quot;Performance improvements&quot;,
      &quot;Better type safety&quot;,
      &quot;Memory efficiency&quot;,
      &quot;Production reliability&quot;,
      &quot;Cross-platform deployment&quot;,
      &quot;WebAssembly support&quot;,
      &quot;Embedded systems development&quot;,
      &quot;Microservices migration&quot;,
      &quot;Other&quot;,
    ],
  },
  {
    type: &quot;multipleChoice&quot;,
    question: &quot;What are your main concerns about migrating to Rust?&quot;,
    id: &quot;concerns&quot;,
    direction: &quot;column&quot;,
    options: [
      &quot;Learning curve for the team&quot;,
      &quot;Migration complexity&quot;,
      &quot;Maintaining productivity during transition&quot;,
      &quot;Finding Rust developers&quot;,
      &quot;Integration with existing Java code&quot;,
      &quot;Third-party library availability&quot;,
      &quot;Build times&quot;,
      &quot;Testing and deployment changes&quot;,
      &quot;None&#x2F;Other&quot;,
    ],
  },
  {
    type: &quot;radio&quot;,
    question: &quot;What&#x27;s your timeline for the migration?&quot;,
    id: &quot;timeline&quot;,
    options: [
      &quot;Immediate (next 3 months)&quot;,
      &quot;Medium-term (3-12 months)&quot;,
      &quot;Long-term (12+ months)&quot;,
    ],
  },
  {
    type: &quot;multipleChoice&quot;,
    question: &quot;What kind of support is most important for your team?&quot;,
    id: &quot;supportNeeded&quot;,
    direction: &quot;column&quot;,
    options: [
      &quot;Planning and strategy&quot;,
      &quot;Project audit&quot;,
      &quot;Training and workshops&quot;,
      &quot;Code reviews and mentoring&quot;,
      &quot;Java integration support&quot;,
      &quot;Performance optimization&quot;,
      &quot;Architecture design&quot;,
      &quot;Best practices guidance&quot;,
      &quot;Team hiring support&quot;,
    ],
  },
  {
    type: &quot;radio&quot;,
    question: &quot;How many developers would be involved in the migration?&quot;,
    options: [&quot;1&quot;, &quot;2-3&quot;, &quot;4-9&quot;, &quot;10+&quot;],
    id: &quot;teamSize&quot;,
  },
  {
    type: &quot;input&quot;,
    question: &quot;Anything else you&#x27;d like to share about your migration plans?&quot;,
    id: &quot;additionalComments&quot;,
    placeholder: &quot;Share your thoughts...&quot;,
    optional: true,
  },
  {
    type: &quot;email&quot;,
    question:
      &quot;What&#x27;s your email? I&#x27;ll send you a customized migration strategy based on your responses.&quot;,
    id: &quot;email&quot;,
    placeholder: &quot;Your email address&quot;,
  },
];

const formUrl = &quot;https:&#x2F;&#x2F;submit-form.com&#x2F;OH6mf241q&quot;;

  &#x2F;&#x2F; Quiz state
  let answers = {};
  let currentQuestionIndex = 0;
  let totalQuestions;

  &#x2F;&#x2F; DOM elements
  const progressBar = document.getElementById(&quot;progress-bar&quot;);
  const questionContainer = document.getElementById(&quot;quiz-question-container&quot;);
  const prevButton = document.getElementById(&quot;quiz-prev-question&quot;);
  const nextButton = document.getElementById(&quot;quiz-next-question&quot;);

  function initQuiz() {
    totalQuestions = questions.length;
    nextButton.addEventListener(&quot;click&quot;, nextQuestion);
    prevButton.addEventListener(&quot;click&quot;, previousQuestion);

    &#x2F;&#x2F; Handle browser back&#x2F;forward buttons
    window.addEventListener(&quot;popstate&quot;, (event) =&gt; {
      if (event.state) {
        currentQuestionIndex = event.state.index;
        answers = event.state.answers || {};
        displayQuestion(currentQuestionIndex);
      } else {
        resetQuiz();
      }
    });

    displayQuestion(0);
  }

  function resetQuiz() {
    answers = {};
    currentQuestionIndex = 0;
    displayQuestion(0);
  }

  function updateProgressBar() {
    const progressPercentage =
      ((currentQuestionIndex + 1) &#x2F; totalQuestions) * 100;
    progressBar.style.width = `${progressPercentage}%`;
  }

  function createQuestionElement(question) {
    const element = document.createElement(&quot;div&quot;);
    element.className = &quot;question&quot;;
    element.innerHTML = `&lt;h3&gt;${question.question}${
      question.optional ? &quot; (Optional)&quot; : &quot;&quot;
    }&lt;&#x2F;h3&gt;`;

    let inputContainer;

    switch (question.type) {
      case &quot;multipleChoice&quot;:
        inputContainer = document.createElement(&quot;div&quot;);
        if (question.direction) {
          inputContainer.style.display = &quot;flex&quot;;
          inputContainer.style.flexDirection = question.direction;
        } else {
          inputContainer.className = &quot;checkbox-grid&quot;;
        }

        question.options.forEach((option) =&gt; {
          const label = document.createElement(&quot;label&quot;);
          label.className = &quot;checkbox-label&quot;;

          const input = document.createElement(&quot;input&quot;);
          input.type = &quot;checkbox&quot;;
          input.name = question.id;
          input.value = option;

          label.appendChild(input);
          label.append(` ${option}`);
          inputContainer.appendChild(label);
        });
        break;

      case &quot;radio&quot;:
        inputContainer = document.createElement(&quot;div&quot;);
        inputContainer.className = &quot;quiz-flex-container&quot;;
        if (question.direction) {
          inputContainer.style.flexDirection = question.direction;
        }

        question.options.forEach((option) =&gt; {
          const label = document.createElement(&quot;label&quot;);
          label.className = &quot;quiz-button&quot;;
          label.textContent = option;

          const input = document.createElement(&quot;input&quot;);
          input.type = &quot;radio&quot;;
          input.name = question.id;
          input.value = option;

          input.addEventListener(&quot;change&quot;, () =&gt; {
            saveCurrentAnswers();
            nextButton.disabled = false;
            &#x2F;&#x2F; Auto-advance
            if (currentQuestionIndex &lt; totalQuestions - 1) {
              nextQuestion();
            }
          });

          label.appendChild(input);
          inputContainer.appendChild(label);
        });
        break;

      case &quot;input&quot;:
      case &quot;email&quot;:
        inputContainer = document.createElement(&quot;input&quot;);
        inputContainer.type = question.type;
        inputContainer.id = question.id;
        inputContainer.name = question.id;
        inputContainer.placeholder = question.placeholder || &quot;&quot;;
        if (question.type === &quot;email&quot;) {
          inputContainer.required = true;
        }
        if (!question.optional) {
          inputContainer.required = true;
        }
        break;
    }

    element.appendChild(inputContainer);
    return { element, inputContainer };
  }

  function saveCurrentAnswers() {
    const inputs = questionContainer.querySelectorAll(&quot;input&quot;);
    const questionId = questions[currentQuestionIndex].id;

    delete answers[questionId];

    inputs.forEach((input) =&gt; {
      if (input.type === &quot;checkbox&quot;) {
        if (input.checked) {
          answers[questionId] = answers[questionId] || [];
          answers[questionId].push(input.value);
        }
      } else if (
        (input.type === &quot;radio&quot; &amp;&amp; input.checked) ||
        input.type === &quot;text&quot; ||
        input.type === &quot;email&quot;
      ) {
        if (input.value.trim()) {
          answers[questionId] = input.value;
        }
      }
    });
  }

  function restorePreviousAnswers(question, container) {
    const previousAnswer = answers[question.id];
    if (!previousAnswer) return;

    const inputs = container.querySelectorAll(&quot;input&quot;);
    inputs.forEach((input) =&gt; {
      if (input.type === &quot;checkbox&quot;) {
        input.checked = previousAnswer.includes(input.value);
      } else if (input.type === &quot;radio&quot;) {
        input.checked = input.value === previousAnswer;
      } else {
        input.value = previousAnswer;
      }
    });
  }

  function updateNavigationState() {
    prevButton.style.display = currentQuestionIndex &gt; 0 ? &quot;&quot; : &quot;none&quot;;
    const question = questions[currentQuestionIndex];
    nextButton.disabled = !isQuestionAnswered(question);
  }

  function isQuestionAnswered(question) {
    if (question.optional) return true;
    const answer = answers[question.id];
    if (!answer) return false;
    if (Array.isArray(answer)) return answer.length &gt; 0;
    
    if (question.type === &quot;email&quot;) {
      const input = document.getElementById(question.id);
      return input &amp;&amp; input.checkValidity() &amp;&amp; answer.trim().length &gt; 0;
    }
    
    return answer.trim().length &gt; 0;
  }

  function nextQuestion() {
    if (currentQuestionIndex &lt; totalQuestions - 1) {
      saveCurrentAnswers();
      currentQuestionIndex++;
      displayQuestion(currentQuestionIndex);
    } else {
      submitQuiz();
    }
  }

  function previousQuestion() {
    if (currentQuestionIndex &gt; 0) {
      saveCurrentAnswers();
      currentQuestionIndex--;
      displayQuestion(currentQuestionIndex);
    }
  }

  function displayQuestion(index) {
    const question = questions[index];
    if (!question) return;

    history.pushState(
      { index, answers: { ...answers } },
      `Question ${index + 1}`,
      `?question=${index + 1}`
    );

    questionContainer.innerHTML = &quot;&quot;;
    const { element, inputContainer } = createQuestionElement(question);
    questionContainer.appendChild(element);

    restorePreviousAnswers(question, inputContainer);
    updateProgressBar();
    updateNavigationState();

    if (question.type === &quot;input&quot; || question.type === &quot;email&quot;) {
      const input = inputContainer;
      input.addEventListener(&quot;input&quot;, () =&gt; {
        if (question.type === &quot;email&quot;) {
          nextButton.disabled = !input.checkValidity() &amp;&amp; !question.optional;
        } else {
          nextButton.disabled = !input.value.trim() &amp;&amp; !question.optional;
        }
      });
    } else if (question.type === &quot;multipleChoice&quot;) {
      const inputs = inputContainer.querySelectorAll(&quot;input&quot;);
      inputs.forEach((input) =&gt; {
        input.addEventListener(&quot;change&quot;, () =&gt; {
          const anyChecked = Array.from(inputs).some((i) =&gt; i.checked);
          nextButton.disabled = !anyChecked &amp;&amp; !question.optional;
        });
      });
    }

    if (question.type === &quot;radio&quot;) {
      nextButton.disabled = !answers[question.id] &amp;&amp; !question.optional;
    }
  }

  async function submitQuiz() {
    saveCurrentAnswers();

    &#x2F;&#x2F; Hide the quiz
    questionContainer.innerHTML = &quot;&quot;;
    document.getElementById(&quot;quiz-navigation-container&quot;).style.display = &quot;none&quot;;

    &#x2F;&#x2F; Show the thank you message
    const resultsContainer = document.getElementById(&quot;quiz-results&quot;);
    resultsContainer.style.display = &quot;block&quot;;

    try {
      &#x2F;&#x2F; Using Formspark as an example
      const response = await fetch(formUrl, {
        method: &quot;POST&quot;,
        headers: {
          &quot;Content-Type&quot;: &quot;application&#x2F;json&quot;,
          Accept: &quot;application&#x2F;json&quot;,
        },
        body: JSON.stringify(answers),
      });

      if (!response.ok) {
        throw new Error(&quot;Failed to submit&quot;);
      }
    } catch (error) {
      console.error(&quot;Failed to submit form:&quot;, error);
      &#x2F;&#x2F; Optionally show an error message to the user
    }
  }

  document.addEventListener(&quot;DOMContentLoaded&quot;, initQuiz);
&lt;&#x2F;script&gt;

&lt;style&gt;
  .quiz-container {
    margin: 0 auto;
    overflow: hidden;
  }

  .quiz-progress-container {
    width: 100%;
    background-color: #ddd;
    height: 5px;
    margin-bottom: 20px;
  }

  .progress-bar {
    height: 100%;
    background-color: #ee3856;
    transition: width 0.5s ease-in-out;
  }

  #quiz-navigation-container {
    width: 100%;
    margin-top: 10px;
    display: flex;
    justify-content: flex-end;
    gap: 10px;
  }

  .quiz-navbutton {
    padding: 10px 20px;
    background-color: #111;
    color: white;
    cursor: pointer;
    border: none;
  }

  .quiz-flex-container {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
  }

  .quiz-button {
    padding: 14px;
    border-radius: 4px;
    background-color: #111;
    color: white;
    white-space: nowrap;
    cursor: pointer;
    flex: 1;
    text-align: center;
    font-size: large;
  }

  .quiz-button:hover {
    background-color: #ee3856;
  }

  input,
  .checkbox-label,
  .quiz-button:hover {
    cursor: pointer;
  }

  #quiz-next-question:disabled {
    cursor: not-allowed;
    opacity: 0.5;
  }

  .quiz-button input[type=&quot;radio&quot;] {
    display: none;
  }

  .quiz-container input[type=&quot;input&quot;],
  .quiz-container input[type=&quot;text&quot;],
  .quiz-container input[type=&quot;email&quot;] {
    font-size: larger;
    width: 100%;
    padding: 15px;
    border: 1px solid #000;
    box-sizing: border-box;
    margin-bottom: 20px;
  }

  .quiz-container input::placeholder {
    color: #ccc;
  }

  .question h2 {
    margin: 0;
  }

  .question .checkbox-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
    gap: 10px;
  }

  .checkbox-label {
    display: flex;
    align-items: center;
    gap: 8px;
  }

  .question input[type=&quot;checkbox&quot;] {
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
    flex-shrink: 0; &#x2F;* Prevent checkbox from shrinking *&#x2F;
    width: 20px;
    height: 20px;
    border: 2px solid #111;
    border-radius: 4px;
    margin: 0; &#x2F;* Remove margin, we&#x27;re using gap instead *&#x2F;
  }

  .question input[type=&quot;checkbox&quot;]:checked {
    border: 2px solid #111;
    background-color: #ee3856;
  }

  @media (max-width: 600px) {
    .quiz-container input[type=&quot;text&quot;],
    .quiz-container input[type=&quot;email&quot;] {
      width: calc(100% - 30px);
    }
  }

  @media (prefers-color-scheme: dark) {
    .quiz-button {
      background-color: #fab71c;
      color: #111;
    }

    .question input[type=&quot;checkbox&quot;] {
      border-color: #fff;
    }

    .question input[type=&quot;checkbox&quot;]:checked {
      border: 2px solid #fff;
      background-color: #ee3856;
    }
  }
&lt;&#x2F;style&gt;
&lt;h2 id=&quot;differences-between-java-and-rust&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#differences-between-java-and-rust&quot; aria-label=&quot;Anchor link for: differences-between-java-and-rust&quot;&gt;Differences Between Java and Rust&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;p&gt;Before diving into migration tips, let’s look at key differences between Java and Rust:&lt;&#x2F;p&gt;
&lt;table&gt;&lt;thead&gt;&lt;tr&gt;&lt;th&gt;Aspect&lt;&#x2F;th&gt;&lt;th&gt;Java&lt;&#x2F;th&gt;&lt;th&gt;Rust&lt;&#x2F;th&gt;&lt;&#x2F;tr&gt;&lt;&#x2F;thead&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;Memory Management&lt;&#x2F;td&gt;&lt;td&gt;Garbage collector; possible memory leaks and GC pauses&lt;&#x2F;td&gt;&lt;td&gt;Borrow checker at compile time; no GC pauses&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;Performance&lt;&#x2F;td&gt;&lt;td&gt;JVM bytecode, requires runtime&lt;&#x2F;td&gt;&lt;td&gt;Native machine code via LLVM&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;Default Mutability&lt;&#x2F;td&gt;&lt;td&gt;Mutable by default&lt;&#x2F;td&gt;&lt;td&gt;Immutable by default, requires &lt;code&gt;mut&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;Null Safety&lt;&#x2F;td&gt;&lt;td&gt;Allows null pointers&lt;&#x2F;td&gt;&lt;td&gt;No null pointers, uses &lt;code&gt;Option&amp;lt;T&amp;gt;&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;Code Organization&lt;&#x2F;td&gt;&lt;td&gt;Classes with inheritance and interfaces&lt;&#x2F;td&gt;&lt;td&gt;Structs with traits (no inheritance)&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;Package Management&lt;&#x2F;td&gt;&lt;td&gt;Gradle&#x2F;Maven&lt;&#x2F;td&gt;&lt;td&gt;Cargo (integrated build + deps)&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;Concurrency&lt;&#x2F;td&gt;&lt;td&gt;Thread-based with synchronized blocks&lt;&#x2F;td&gt;&lt;td&gt;Built-in safety via ownership system; async&#x2F;await&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;Error Handling&lt;&#x2F;td&gt;&lt;td&gt;Checked exceptions&lt;&#x2F;td&gt;&lt;td&gt;Result and Option types&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;Compilation Speed&lt;&#x2F;td&gt;&lt;td&gt;Fast to medium&lt;&#x2F;td&gt;&lt;td&gt;Slow&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;Learning Curve&lt;&#x2F;td&gt;&lt;td&gt;Moderate&lt;&#x2F;td&gt;&lt;td&gt;Steep&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;Deployment&lt;&#x2F;td&gt;&lt;td&gt;Requires JVM runtime&lt;&#x2F;td&gt;&lt;td&gt;Small, self-contained binaries&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;&#x2F;tbody&gt;&lt;&#x2F;table&gt;
&lt;p&gt;These differences highlight why organizations might consider migrating to Rust, particularly for performance-critical or resource-constrained applications. However, migration isn’t just about technical differences - it requires careful planning and execution. Let’s look at how to make this transition successful.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;mindset-shifts-for-java-developers&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#mindset-shifts-for-java-developers&quot; aria-label=&quot;Anchor link for: mindset-shifts-for-java-developers&quot;&gt;Mindset Shifts for Java Developers&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;p&gt;Moving from Java to Rust requires some fundamental shifts in how you think about programming. Here are the key changes that will help your team succeed.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;from-objects-to-ownership&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#from-objects-to-ownership&quot; aria-label=&quot;Anchor link for: from-objects-to-ownership&quot;&gt;From Objects to Ownership&lt;&#x2F;a&gt;&lt;&#x2F;h3&gt;
&lt;p&gt;Java lets you pass objects freely between methods and classes. Rust doesn’t. Each piece of data has exactly one owner, and the compiler enforces this strictly. While this feels limiting at first, it prevents entire categories of memory issues at compile time rather than runtime. Instead of relying on garbage collection to clean up, you plan your memory usage upfront. Most developers find this leads to more predictable and efficient code once they adapt to the mindset.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;strong&gt;The ownership model also forces better data structure design.&lt;&#x2F;strong&gt; Rust’s has stricter memory rules, which encourage you to think more carefully about how you organize data and pass it between functions. This often leads to more efficient algorithms and cleaner architectures.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;embracing-immutability&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#embracing-immutability&quot; aria-label=&quot;Anchor link for: embracing-immutability&quot;&gt;Embracing Immutability&lt;&#x2F;a&gt;&lt;&#x2F;h3&gt;
&lt;p&gt;Java makes everything mutable by default, which is arguably its single biggest issue. In large codebases, this mutability makes maintenance nearly impossible - you have to trace through deeply nested call trees to ensure variables aren’t modified somewhere unexpected. Code reviews become nightmarish exercises in hunting down potential side effects.&lt;&#x2F;p&gt;
&lt;p&gt;Rust does the opposite - everything stays immutable unless marked with &lt;code&gt;mut&lt;&#x2F;code&gt;. This simple change has profound effects on code quality. You think more carefully about what really needs to change, leading to fewer bugs and easier concurrent programming. &lt;strong&gt;This also enables better compiler optimizations&lt;&#x2F;strong&gt; since the compiler can make stronger assumptions about your data.&lt;&#x2F;p&gt;
&lt;p&gt;Many developers find they write better code in all languages after working with Rust’s immutability model.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;rethinking-null&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#rethinking-null&quot; aria-label=&quot;Anchor link for: rethinking-null&quot;&gt;Rethinking Null&lt;&#x2F;a&gt;&lt;&#x2F;h3&gt;
&lt;p&gt;Rust eliminates &lt;code&gt;null&lt;&#x2F;code&gt; entirely. Instead of &lt;code&gt;null&lt;&#x2F;code&gt; checks and &lt;code&gt;NullPointerExceptions&lt;&#x2F;code&gt;, you work with &lt;code&gt;Option&amp;lt;T&amp;gt;&lt;&#x2F;code&gt;. This type makes uncertainty explicit in your code, forcing you to handle cases where values might not exist. The compiler ensures you handle both success and failure paths.&lt;&#x2F;p&gt;
&lt;p&gt;In Java, defensive programming requires null checks at every public interface. It adds overhead even when you know the value can’t be null. With Rust’s references and ownership system, you can guarantee non-null values without runtime checks, making your interfaces both safer and faster.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;from-inheritance-to-composition&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#from-inheritance-to-composition&quot; aria-label=&quot;Anchor link for: from-inheritance-to-composition&quot;&gt;From Inheritance to Composition&lt;&#x2F;a&gt;&lt;&#x2F;h3&gt;
&lt;p&gt;&lt;strong&gt;Rust doesn’t have class inheritance at all.&lt;&#x2F;strong&gt; There’s no equivalent to extending a class in Java. Instead, Rust uses traits, which are much closer to Java interfaces than to inheritance.&lt;&#x2F;p&gt;
&lt;p&gt;This is actually the better approach. &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;softwareengineering.stackexchange.com&#x2F;a&#x2F;370519&quot;&gt;Even James Gosling, Java’s creator, has said he would have preferred pure interfaces over class inheritance if he could redesign Java.&lt;&#x2F;a&gt; Rust implements this vision through traits. You can even have trait inheritance by requiring one trait to implement another, but it’s all trait-based composition rather than implementation inheritance.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;strong&gt;Traits encourage more flexible and maintainable code design.&lt;&#x2F;strong&gt; Rather than building rigid inheritance hierarchies, you &lt;strong&gt;compose behavior&lt;&#x2F;strong&gt; through trait implementations. This leads to systems that are easier to test, modify, and extend.&lt;&#x2F;p&gt;
&lt;p&gt;It takes a while to get used to that approach. The key is to think in terms of capabilities (traits). For example, instead of a &lt;code&gt;Dog&lt;&#x2F;code&gt; class extending an &lt;code&gt;Animal&lt;&#x2F;code&gt; class, you might have a &lt;code&gt;Bark&lt;&#x2F;code&gt; trait that both &lt;code&gt;Dog&lt;&#x2F;code&gt; and &lt;code&gt;Wolf&lt;&#x2F;code&gt; implement. This leads to more reusable and modular code.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;compiler-as-collaborator&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#compiler-as-collaborator&quot; aria-label=&quot;Anchor link for: compiler-as-collaborator&quot;&gt;Compiler as Collaborator&lt;&#x2F;a&gt;&lt;&#x2F;h3&gt;
&lt;p&gt;The Rust compiler catches far more issues than Java’s. It identifies race conditions, memory leaks, and thread safety problems before they reach production. While its strictness can feel frustrating initially, the detailed error messages actually help you learn. Most teams find that working with the compiler rather than against it leads to faster development in the long run.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;memory-management-mindset&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#memory-management-mindset&quot; aria-label=&quot;Anchor link for: memory-management-mindset&quot;&gt;Memory Management Mindset&lt;&#x2F;a&gt;&lt;&#x2F;h3&gt;
&lt;p&gt;Instead of relying on garbage collection, Rust makes you think explicitly about memory lifecycles. You consider who owns data and how long it needs to live. The borrow checker ensures these decisions are correct at compile time. This leads to more efficient resource usage and eliminates many common runtime errors. Despite the learning curve, most developers find this explicit memory model makes them better programmers overall.&lt;&#x2F;p&gt;
&lt;p&gt;These changes take time to internalize. Plan for an adjustment period, but know that the investment typically pays off in more reliable and efficient code. The key is understanding these differences upfront so you can help your team adapt effectively.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;tip-1-flatten-the-learning-curve&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#tip-1-flatten-the-learning-curve&quot; aria-label=&quot;Anchor link for: tip-1-flatten-the-learning-curve&quot;&gt;Tip 1: Flatten The Learning Curve&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;p&gt;Migrating to a new language is always tough at first, and Rust is no exception.
It has a &lt;a href=&quot;&#x2F;blog&#x2F;flattening-rusts-learning-curve&#x2F;&quot;&gt;famously steep learning curve&lt;&#x2F;a&gt; and requires a different mindset from Java.
Plan 4-6 months for your engineers to get comfortable with Rust, and expect a few bumps along the way.&lt;&#x2F;p&gt;
&lt;p&gt;That said, there’s plenty of material to help your team get up to speed.
Resources like &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;rust-lang&#x2F;rustlings&quot;&gt;Rustlings&lt;&#x2F;a&gt;, &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;doc.rust-lang.org&#x2F;rust-by-example&#x2F;&quot;&gt;Rust By Example&lt;&#x2F;a&gt;,
&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;mainmatter&#x2F;100-exercises-to-learn-rust&quot;&gt;100 Exercises To Learn Rust&lt;&#x2F;a&gt;, and
&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.rustfinity.com&#x2F;&quot;&gt;Rustfinity&lt;&#x2F;a&gt; are all great for self-learning.&lt;&#x2F;p&gt;
&lt;p&gt;If you’re looking for a more structured approach, &lt;a href=&quot;&#x2F;services&quot;&gt;consider hiring a Rust consultant or trainer&lt;&#x2F;a&gt;.
Bringing in experts can make the transition even faster and smoother.
Your team will not only learn Rust but also feel more confident working with it in production.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;tip-2-have-a-clear-migration-plan&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#tip-2-have-a-clear-migration-plan&quot; aria-label=&quot;Anchor link for: tip-2-have-a-clear-migration-plan&quot;&gt;Tip 2: Have A Clear Migration Plan&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;p&gt;Migrating to Rust comes with some risks, but careful planning will minimize them. Here’s how to ensure success:&lt;&#x2F;p&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Start Small&lt;&#x2F;strong&gt;&lt;br &#x2F;&gt;
Pick a small, non-critical part of your application for the first Rust implementation. This lets your team experiment and build confidence without affecting core systems. Expand gradually as you see results.&lt;&#x2F;p&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Prepare Your Team&lt;&#x2F;strong&gt;&lt;br &#x2F;&gt;
Don’t just decide this for your developers—decide together. Get the team ready with training or external expertise, and focus on integration with your existing Java system. Rust will likely need new dependencies, so research the ecosystem and be ready to roll up your sleeves to contribute if necessary.
Take a look at &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;blessed.rs&quot;&gt;blessed.rs&lt;&#x2F;a&gt;, &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;lib.rs&#x2F;std&quot;&gt;lib.rs&lt;&#x2F;a&gt;, and &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;rust-unofficial&#x2F;awesome-rust&quot;&gt;awesome-rust&lt;&#x2F;a&gt; for a curated list of libraries.&lt;&#x2F;p&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Evaluate Dependencies Upfront&lt;&#x2F;strong&gt;&lt;br &#x2F;&gt;
Consider potential constraints like proprietary tools or databases that may complicate integration with Rust. Make sure the libraries you need are available, or be prepared to write your own.&lt;&#x2F;p&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Have a Plan B&lt;&#x2F;strong&gt;&lt;br &#x2F;&gt;
Rust migration doesn’t need to be all-or-nothing. Keep Java components running while testing and migrating. If issues arise, you can scale back or swap components as needed.&lt;&#x2F;p&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Set Clear KPIs&lt;&#x2F;strong&gt;&lt;br &#x2F;&gt;
Establish your own definition of success—don’t just follow industry benchmarks. Whether it’s performance, resource savings, or developer experience, make sure you know what you want from Rust and measure it.&lt;&#x2F;p&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Training Pays Off&lt;&#x2F;strong&gt;&lt;br &#x2F;&gt;
Even if you eventually decide against Rust, the training will improve your team’s programming skills. It’s an investment that pays dividends in the long run.&lt;&#x2F;p&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Monitor and Test&lt;&#x2F;strong&gt;&lt;br &#x2F;&gt;
Use monitoring and automated tests throughout the migration. Rust’s safety guarantees help, but you still need to test thoroughly and catch any issues early.&lt;&#x2F;p&gt;
&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;h2 id=&quot;tip-3-choose-the-right-migration-strategy&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#tip-3-choose-the-right-migration-strategy&quot; aria-label=&quot;Anchor link for: tip-3-choose-the-right-migration-strategy&quot;&gt;Tip 3: Choose The Right Migration Strategy&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;p&gt;Initially, you will likely be dealing with a mix of Java and Rust.
Where should you start?
&lt;strong&gt;Look at the boundaries in your application—network layers, APIs, or microservices.&lt;&#x2F;strong&gt;
These natural seams are perfect places to migrate first.&lt;&#x2F;p&gt;
&lt;p&gt;For Java-to-Rust migration, you have a few options:&lt;&#x2F;p&gt;
&lt;ol&gt;
&lt;li&gt;Set up inter-process communication (IPC) via &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;grpc.io&#x2F;&quot;&gt;gRPC&lt;&#x2F;a&gt; between Java and Rust services.&lt;&#x2F;li&gt;
&lt;li&gt;Use a message broker like &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;kafka.apache.org&#x2F;&quot;&gt;Kafka&lt;&#x2F;a&gt; or &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;nats.io&#x2F;&quot;&gt;NATS&lt;&#x2F;a&gt; in between the two languages.&lt;&#x2F;li&gt;
&lt;li&gt;Use a REST API as the communication layer.&lt;&#x2F;li&gt;
&lt;li&gt;Use &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;docs.rs&#x2F;jni&#x2F;latest&#x2F;jni&#x2F;&quot;&gt;JNI&lt;&#x2F;a&gt; to call Rust functions from Java.&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;p&gt;Each approach has its pros and cons, so choose the one that fits your use case best.
How do you decide?
This is something you should discuss with your team and possibly a Rust consultant.
They can help you weigh the trade-offs and make the right choice.&lt;&#x2F;p&gt;
&lt;p&gt;If you’d like to get a primer on Java-to-Rust interop, check out &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.youtube.com&#x2F;watch?v=fYaaBoKbDQs&quot;&gt;this talk&lt;&#x2F;a&gt;
from Rust Nation UK 2024 by Konstantin Grechishchev.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;tip-4-partial-migration-might-be-enough&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#tip-4-partial-migration-might-be-enough&quot; aria-label=&quot;Anchor link for: tip-4-partial-migration-might-be-enough&quot;&gt;Tip 4: Partial Migration Might Be Enough&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;p&gt;Big organizations often have large, complex Java codebases.
A full rewrite is not feasible and can be risky.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;strong&gt;Consider rewriting the most CPU- or memory-hungry parts of your application in Rust while leaving the rest untouched.&lt;&#x2F;strong&gt;&lt;&#x2F;p&gt;
&lt;p&gt;Perhaps you find that you only need to migrate a tiny portion, say 10-20%, to Rust for a significant performance boost.
In that case, you can keep the rest of the application in Java and gradually migrate more parts over time if you see benefits.
This incremental approach ensures that your team can slowly adapt to Rust and share some quick wins along the way, which is great for morale.&lt;&#x2F;p&gt;
&lt;p&gt;A good way to test the waters is with isolated components — CLI tools or monitoring sidecars. These smaller parts let your team gain experience with Rust without affecting critical system functions.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;tip-5-evaluate-the-ecosystem&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#tip-5-evaluate-the-ecosystem&quot; aria-label=&quot;Anchor link for: tip-5-evaluate-the-ecosystem&quot;&gt;Tip 5: Evaluate The Ecosystem&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;p&gt;When migrating to a different language, the new tooling is just as important as the language itself.
However, it’s often overlooked in the decision-making process.&lt;&#x2F;p&gt;
&lt;p&gt;Rust’s tooling is excellent, and among the most loved advantages of the language.
The tooling is best in class, mature and easy to adopt. Here’s how it stacks up:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Package Management&lt;&#x2F;strong&gt;: Rust’s package manager, cargo, simplifies dependencies and builds. No more convoluted Gradle configurations.&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;IDEs&lt;&#x2F;strong&gt;: Rust’s integration with VS Code and IntelliJ (via rust-analyzer) is seamless, making it easy for your developers to dive right in.&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;CI&#x2F;CD&lt;&#x2F;strong&gt;: GitHub Actions and other CI tools work beautifully with Rust, with dedicated actions for testing and deployment.&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Debugging&lt;&#x2F;strong&gt;: Debugging tools work out of the box, and IDE integrations are robust by now.&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Linting and Formatting&lt;&#x2F;strong&gt;: &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;rust-lang.github.io&#x2F;rust-clippy&#x2F;&quot;&gt;Rustfmt&lt;&#x2F;a&gt; and &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;rust-lang.github.io&#x2F;rust-clippy&#x2F;stable&#x2F;index.html&quot;&gt;clippy&lt;&#x2F;a&gt; ensure consistent code style and catch common errors early. They actively help your team write better code.&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;However, also consider the constraints and risks your project might face—proprietary tools, unusual databases, or special dependencies.
Do the research upfront to avoid surprises.
And if you need new libraries, be prepared to get your hands dirty and write your own.&lt;&#x2F;p&gt;
&lt;p&gt;For example, if you’re building a web application, Rust has several frameworks to choose from, with the most popular being &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;tokio-rs&#x2F;axum&quot;&gt;axum&lt;&#x2F;a&gt;, but none as mature as Spring Boot. Projects like &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;LukeMathWalker&#x2F;pavex&quot;&gt;Pavex&lt;&#x2F;a&gt; or &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;loco.rs&#x2F;&quot;&gt;Loco&lt;&#x2F;a&gt; could fill this gap, but they’re still in early stages.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;tip-6-simplify-your-deployment-pipeline&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#tip-6-simplify-your-deployment-pipeline&quot; aria-label=&quot;Anchor link for: tip-6-simplify-your-deployment-pipeline&quot;&gt;Tip 6: Simplify Your Deployment Pipeline&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;p&gt;Rust shines when it comes to cross-platform builds. Unlike Java, where you often need to install a runtime (like the JVM) on every machine, Rust’s binaries are small, self-contained, and ready to run anywhere.&lt;&#x2F;p&gt;
&lt;p&gt;Rust compiles directly to machine code, which means you don’t need to worry about dependencies that are typically required by dynamic runtimes. The only consideration might be system libraries (like OpenSSL), but this is manageable with established solutions. &lt;sup class=&quot;footnote-reference&quot; id=&quot;fr-1-1&quot;&gt;&lt;a href=&quot;#fn-1&quot;&gt;1&lt;&#x2F;a&gt;&lt;&#x2F;sup&gt;&lt;&#x2F;p&gt;
&lt;p&gt;In containerized environments, Docker works just as well with Rust as with any other language, and it’s easier to scale because of Rust’s low overhead. Whether you’re running on AWS, Cloud Run, or any other platform, the experience is reliable and consistent.&lt;&#x2F;p&gt;
&lt;p&gt;Rust supports a &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;doc.rust-lang.org&#x2F;nightly&#x2F;rustc&#x2F;platform-support.html&quot;&gt;wide variety of platforms&lt;&#x2F;a&gt;, including ARM and x64, and can be used seamlessly across development machines, servers, and the cloud.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;tip-7-don-t-focus-on-raw-performance-alone&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#tip-7-don-t-focus-on-raw-performance-alone&quot; aria-label=&quot;Anchor link for: tip-7-don-t-focus-on-raw-performance-alone&quot;&gt;Tip 7: Don’t Focus On Raw Performance Alone&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;p&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.sergetoro.com&#x2F;microbench-go-java-rust-js-python&#x2F;&quot;&gt;Yes, Rust has awesome runtime performance.&lt;&#x2F;a&gt; But you shouldn’t focus on raw numbers alone.
Thanks to technologies like &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.graalvm.org&#x2F;&quot;&gt;GraalVM&lt;&#x2F;a&gt;, Java can be
very fast as well, especially for long-running applications.&lt;&#x2F;p&gt;
&lt;a href=&quot;https:&#x2F;&#x2F;blog.consol.de&#x2F;software-engineering&#x2F;web-application-development&#x2F;rust-vs-quarkus-native-vs-spring-native&#x2F;&quot;&gt;
    &lt;img src=&quot;bench.png&quot; alt=&quot;Rust vs Quarkus&quot;&gt;
&lt;&#x2F;a&gt;
&lt;p&gt;The image above shows a comparison between Rust, Quarkus-Native, and Spring-Native.
In terms of raw performance, Rust is the clear winner.
Rust uses 12 MB RAM and less than a third of the CPU power of both Quarkus-Native and Spring-Native.&lt;&#x2F;p&gt;
&lt;p&gt;When you migrate to Rust, also consider the secondary effects of improved performance:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Lower Latency&lt;&#x2F;strong&gt;: Rust doesn’t have the pauses or unpredictability that garbage collection introduces in Java. This makes it easier to predict system performance, especially during peak load.&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Higher Throughput&lt;&#x2F;strong&gt;: Rust’s memory model and zero-cost abstractions make it ideal for handling high-volume, high-concurrency applications. Expect performance boosts, often between 2x and 3x, depending on the workload.&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Lower Resource Usage&lt;&#x2F;strong&gt;: After migrating to Rust, you’ll likely need fewer CPUs or instances to handle the same load. This means less infrastructure to manage and lower costs in production.&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Fast Scalability&lt;&#x2F;strong&gt;: Rust’s low overhead means you can scale up or down quickly. Whether you’re running on Kubernetes or a traditional VM, Rust’s efficiency makes it easier to manage your infrastructure. In contrast, this is a common pain point for Java applications in the cloud. It can take 30 seconds or more until a new JVM instance &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.ibm.com&#x2F;docs&#x2F;en&#x2F;sdk-java-technology&#x2F;8?topic=reference-jit-compiler&quot;&gt;JIT-compiles&lt;&#x2F;a&gt; your code, which can lead to cold start issues.&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;Based on my experience helping teams migrate to Rust, here are some ballpark improvements you might see:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Memory Usage&lt;&#x2F;strong&gt;: For data-heavy applications, expect to see 30-50% reduction in heap size for most services.
This is a very conservative estimate. Depending on your workload, you might see even more significant improvements.&lt;&#x2F;p&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Startup Time&lt;&#x2F;strong&gt;: While Java services often need 20-30 seconds to warm up in production, equivalent Rust services typically start in under a second. This makes a big difference for scaling containerized deployments.&lt;&#x2F;p&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Latency&lt;&#x2F;strong&gt;: The exact numbers vary widely, but you’ll often see P95 latency improve by 40-60%. The biggest win is usually in tail latencies (P99.9) due to the lack of GC pauses.&lt;&#x2F;p&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Throughput&lt;&#x2F;strong&gt;: Again, this depends heavily on your workload, but teams I’ve worked with typically see:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;CPU-bound tasks: 2-3x improvement&lt;&#x2F;li&gt;
&lt;li&gt;I&#x2F;O-bound tasks with high concurrency: 1.5-2x improvement&lt;&#x2F;li&gt;
&lt;li&gt;Most importantly, throughput becomes more consistent and predictable&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Resource Costs&lt;&#x2F;strong&gt;: Several teams have managed to cut their cloud costs by 40-60% after migration, mainly due to lower CPU and memory requirements.&lt;&#x2F;p&gt;
&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;These are rough numbers from my consulting experience, and your results may vary significantly depending on your specific use case. The key takeaway isn’t the exact numbers, but rather that teams consistently see meaningful improvements across different metrics.&lt;&#x2F;p&gt;
&lt;p&gt;Rust helps you get more done with less, making it easier to scale and manage your infrastructure.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;tip-8-fearless-concurrency&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#tip-8-fearless-concurrency&quot; aria-label=&quot;Anchor link for: tip-8-fearless-concurrency&quot;&gt;Tip 8: Fearless Concurrency&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;p&gt;Rust’s concurrency model is a major advantage.
Traditional Java applications tend to be thread-heavy, and while this works on modern Linux systems, Rust offers more flexibility.
On top of that, concurrency in Java can be tricky to get right and is therefore often avoided.&lt;&#x2F;p&gt;
&lt;p&gt;Rust gives you both thread-based concurrency and async execution. With libraries like Tokio, you can use async&#x2F;await without worrying about the underlying mechanics. It scales incredibly well, often in ways that Java simply can’t match due to its reliance on threads.&lt;&#x2F;p&gt;
&lt;p&gt;What’s powerful about Rust’s concurrency is how it’s baked into the language itself. It’s not something your team has to think about too much. The libraries handle most of the heavy lifting, and once you structure your code properly, Rust’s runtime handles the rest.&lt;&#x2F;p&gt;
&lt;p&gt;Rust’s memory management ensures that concurrency is safe, so you won’t need to worry about thread synchronization issues like you would in Java.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;tip-9-reliable-production-environments&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#tip-9-reliable-production-environments&quot; aria-label=&quot;Anchor link for: tip-9-reliable-production-environments&quot;&gt;Tip 9: Reliable Production Environments&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;p&gt;One of Rust’s underrated strengths is developer ergonomics.&lt;&#x2F;p&gt;
&lt;p&gt;With Rust’s strict compiler checks, a lot of potential bugs are caught during development, meaning fewer bugs in production. This leads to fewer code reviews and a smoother development process overall. You can move faster with more confidence.&lt;&#x2F;p&gt;
&lt;p&gt;Over time, this leads to &lt;strong&gt;more reliable code in production&lt;&#x2F;strong&gt;. Rust’s emphasis on memory safety and strict typing means that, once your system is built, you’re less likely to face random crashes or bugs.
This saves on-call costs and reduces the risk of downtime.&lt;&#x2F;p&gt;
&lt;p&gt;There are no garbage collector pauses to worry about, and the code has a predictable performance profile.
You’ll have a “boring” production environment in the best way possible — things will work consistently and predictably.&lt;&#x2F;p&gt;
&lt;p&gt;Rust is committed to stability. While some core libraries haven’t reached a stable 1.0 version yet, the 0.x versions are highly reliable, with breaking changes becoming less frequent over time. When Rust releases new versions, they follow &lt;strong&gt;semantic versioning&lt;&#x2F;strong&gt;, so updates are usually predictable and don’t introduce surprises.&lt;&#x2F;p&gt;
&lt;p&gt;If you’re worried about future-proofing your application, Rust’s ecosystem is built with long-term support in mind. If you do encounter missing functionality, you’ll often need to contribute back to the community—this is part of the Rust philosophy.&lt;&#x2F;p&gt;
&lt;p&gt;Training your team in Rust isn’t just about the immediate migration. Even if you eventually decide to stick with Java, Rust’s focus on good practices will make your developers better overall.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;tip-10-make-the-decision-together&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#tip-10-make-the-decision-together&quot; aria-label=&quot;Anchor link for: tip-10-make-the-decision-together&quot;&gt;Tip 10: Make The Decision Together&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;p&gt;Adopting Rust is a big commitment.
Don’t make the decision in a vacuum — involve your team in the process.
They’re the ones who will be working with Rust day in and day out, so their input is crucial.&lt;&#x2F;p&gt;
&lt;p&gt;If you’re considering a migration, start by discussing the benefits and challenges of Rust.
What are your hopes for Rust? What are the alternatives considered? What are your key KPIs for success?
What is the skill level of your team, and how can you support them in learning Rust?
It helps to put your thoughts into writing and share them with the team.&lt;&#x2F;p&gt;
&lt;p&gt;On that note, hiring Rust developers can be challenging. It’s a relatively new language, and most Rust developers
don’t have any production experience yet. Instead, consider upskilling your existing Java developers.
They already know your systems and can learn Rust with the right training and support.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;conclusion&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#conclusion&quot; aria-label=&quot;Anchor link for: conclusion&quot;&gt;Conclusion&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;p&gt;At the end of the day, Rust’s investment pays off. Even if you don’t go full Rust, the knowledge gained will make your developers better programmers.&lt;&#x2F;p&gt;
&lt;p&gt;If you’d like to discuss this further, feel free to book a call with me.
I offer consulting services to help you make the right decisions for your project – even if that means sticking with Java.&lt;&#x2F;p&gt;
&lt;div class=&quot;info&quot;&gt;
  
  &lt;div class=&quot;info-header&quot;&gt;
    
      &lt;span class=&quot;icon icon-crab&quot;&gt;&lt;&#x2F;span&gt;
    
    &lt;h4&gt;&lt;p&gt;Make the most of Rust&lt;&#x2F;p&gt;
&lt;&#x2F;h4&gt;
  &lt;&#x2F;div&gt;
  
  &lt;p&gt;Is your company considering to migrate from Java to Rust?
I offer consulting services to get you up to speed with your Rust projects, from training your team to code reviews and architecture consulting.
&lt;a href=&quot;&#x2F;services&quot;&gt;Get in touch for a free consultation&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;

&lt;&#x2F;div&gt;
&lt;section class=&quot;footnotes&quot;&gt;
&lt;ol class=&quot;footnotes-list&quot;&gt;
&lt;li id=&quot;fn-1&quot;&gt;
&lt;p&gt;For example, you can &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;docs.rs&#x2F;openssl&#x2F;latest&#x2F;openssl&#x2F;#vendored&quot;&gt;vendor OpenSSL to build it statically&lt;&#x2F;a&gt;. &lt;a href=&quot;#fr-1-1&quot;&gt;↩&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;&#x2F;section&gt;
</description>
      </item>
      <item>
          <title>Migrating from Scala to Rust</title>
          <pubDate>Mon, 09 Dec 2024 00:00:00 +0000</pubDate>
          <author>Matthias Endler</author>
          <link>https://corrode.dev/learn/migration-guides/scala-to-rust/</link>
          <guid>https://corrode.dev/learn/migration-guides/scala-to-rust/</guid>
          <description xml:base="https://corrode.dev/learn/migration-guides/scala-to-rust/">&lt;p&gt;There’s been increasing &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;degoes.net&#x2F;articles&#x2F;scala-resurrection&quot;&gt;discussion about companies moving from Scala to Rust&lt;&#x2F;a&gt;). The Scala ecosystem faces, and while solutions are proposed, many organizations are evaluating Rust as an alternative path forward.&lt;&#x2F;p&gt;
&lt;p&gt;Even former Scala advocates like Twitter or LinkedIn have &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=13478361&quot;&gt;expressed concerns about their choice of Scala&lt;&#x2F;a&gt;:&lt;&#x2F;p&gt;
&lt;blockquote&gt;
&lt;p&gt;“We’ve recently made the decision to minimize our dependence on Scala in our next generation front end infrastructure which is rolling out this year.” — LinkedIn’s SVP of Eng Kevin Scott&lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
&lt;p&gt;People are looking for guidance on how to navigate this transition, which is why I’ve written this guide for organizations considering migrating from Scala or Clojure to Rust. We will take a cold hard look at the benefits and challenges of moving to Rust, and provide practical advice for making the switch.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;why-consider-rust&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#why-consider-rust&quot; aria-label=&quot;Anchor link for: why-consider-rust&quot;&gt;Why Consider Rust?&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;h3 id=&quot;industry-adoption-and-momentum&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#industry-adoption-and-momentum&quot; aria-label=&quot;Anchor link for: industry-adoption-and-momentum&quot;&gt;Industry Adoption and Momentum&lt;&#x2F;a&gt;&lt;&#x2F;h3&gt;
&lt;p&gt;The most striking difference between Rust and JVM functional languages is the &lt;strong&gt;pace of adoption&lt;&#x2F;strong&gt;. Rust has seen extraordinary growth, with over 2.8 million developers using it professionally. &lt;a href=&quot;&#x2F;blog&#x2F;why-rust&quot;&gt;Major tech companies including Microsoft, Google, and Meta have embraced Rust&lt;&#x2F;a&gt;, particularly for performance-critical systems. This widespread adoption has created a virtuous cycle: the larger talent pool makes hiring easier, which encourages more companies to adopt Rust, which in turn drives more developers to learn the language. The ecosystem grows more robust by the day, with new tools and libraries constantly emerging to solve real-world problems.&lt;&#x2F;p&gt;
&lt;p&gt;In comparison, Scala and Clojure have seen slower growth and more limited industry adoption. While both languages have passionate communities and are well-suited to certain domains like data processing and Spark applications, they lack the broad appeal and momentum that Rust has achieved. This difference in adoption rates can affect your organization’s ability to hire and retain talent, which is a risk factor for any company.&lt;&#x2F;p&gt;
&lt;p&gt;In fairness, the RedMonk rankings show that Scala has maintained a consistent position in the top 20 languages, while Rust has just recently broken into the top 20.&lt;&#x2F;p&gt;
&lt;a href=&quot;https:&#x2F;&#x2F;redmonk.com&#x2F;rstephens&#x2F;2024&#x2F;09&#x2F;12&#x2F;top20-jun2024&#x2F;&quot;&gt;
    &lt;img src=&quot;redmonk-jun-2024.png&quot; alt=&quot;RedMonk Language Popularity&quot;&gt;
&lt;&#x2F;a&gt;
&lt;h3 id=&quot;stability-and-backward-compatibility&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#stability-and-backward-compatibility&quot; aria-label=&quot;Anchor link for: stability-and-backward-compatibility&quot;&gt;Stability and Backward Compatibility&lt;&#x2F;a&gt;&lt;&#x2F;h3&gt;
&lt;p&gt;One of Rust’s strongest selling points is its commitment to stability. Since its 1.0 release in 2015, Rust has maintained backward compatibility across &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;releases.rs&#x2F;&quot;&gt;&lt;strong&gt;more than 105 releases&lt;&#x2F;strong&gt;&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;Releases are cut every six weeks and roughly every 3 years a new edition is released, which allows the language to evolve while preserving compatibility with existing code. This stability is a significant advantage for organizations that need to maintain long-lived codebases or have strict requirements around backward compatibility.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;strong&gt;Rust’s stability is a fundamental business advantage.&lt;&#x2F;strong&gt;&lt;&#x2F;p&gt;
&lt;p&gt;Code written in Rust 1.0 continues to compile and run today, protecting your investment in both code and developer training. Documentation and learning resources remain relevant for years, significantly reducing the ongoing cost of maintaining expertise in your organization. This stands in stark contrast to the breaking changes that have characterized many language ecosystems, including Scala’s transition from 2.x to 3.x.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;superior-tooling-experience&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#superior-tooling-experience&quot; aria-label=&quot;Anchor link for: superior-tooling-experience&quot;&gt;Superior Tooling Experience&lt;&#x2F;a&gt;&lt;&#x2F;h3&gt;
&lt;p&gt;Rust’s tooling ecosystem, centered around Cargo, provides a remarkably smooth developer experience. Cargo unifies building, testing, and dependency management into a single, coherent tool that just works. The compiler’s error messages are legendary for their clarity and helpfulness, often telling developers exactly how to fix issues. IDE support through rust-analyzer and RustRover is rock-solid, providing a reliable development experience that boosts productivity. This tooling excellence isn’t an accident — it’s the result of deliberate design decisions and years of community investment.&lt;&#x2F;p&gt;
&lt;p&gt;In Scala, build tools like sbt and dependency management tools like Maven can be complex and error-prone. IDE support, while improving, can be inconsistent across different editors and might not support all language features. &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;users.scala-lang.org&#x2F;t&#x2F;what-are-some-of-the-advantages-of-using-scala-over-rust-c-and-other-native-languages&#x2F;2556&#x2F;10&quot;&gt;The overall developer experience in Rust is more polished and consistent.&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;h3 id=&quot;performance-with-safety&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#performance-with-safety&quot; aria-label=&quot;Anchor link for: performance-with-safety&quot;&gt;Performance with Safety&lt;&#x2F;a&gt;&lt;&#x2F;h3&gt;
&lt;p&gt;While Scala and Clojure offer good performance for JVM languages, Rust provides performance comparable to C&#x2F;C++ while guaranteeing memory safety at compile time. This combination is particularly valuable in an era of cloud computing, where every millisecond of latency and every megabyte of memory directly affects operating costs. However, Scala developers should note that writing truly immutable code can actually be more challenging in Rust than in Scala.&lt;&#x2F;p&gt;
&lt;p&gt;Rust’s predictable resource usage and lack of garbage collection pauses make it ideal for systems that require consistent performance. Organizations often find that moving performance-critical components to &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;corrode.dev&#x2F;blog&#x2F;why-rust&#x2F;#cost-savings&quot;&gt;Rust can significantly reduce their infrastructure costs&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;making-the-business-case&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#making-the-business-case&quot; aria-label=&quot;Anchor link for: making-the-business-case&quot;&gt;Making the Business Case&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;p&gt;The business case for Rust extends beyond technical merits.&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Infrastructure costs often decrease&lt;&#x2F;strong&gt; due to better performance and resource utilization.&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Maintenance becomes more predictable&lt;&#x2F;strong&gt; thanks to superior tooling and compile-time guarantees.&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;The risk of production issues decreases&lt;&#x2F;strong&gt; due to Rust’s strong type system and ownership model catching many common bugs at compile time.&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;Scala and Clojure developers typically transition well to Rust because the languages share many fundamental concepts. The emphasis on strong type systems, functional programming patterns, and correctness creates a natural bridge. While Rust’s ownership system presents a learning curve, developers coming from functional programming backgrounds often find they already think in ways that align well with Rust’s model.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;migration-strategy&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#migration-strategy&quot; aria-label=&quot;Anchor link for: migration-strategy&quot;&gt;Migration Strategy&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;p&gt;A successful migration to Rust typically starts small and grows organically. New microservices or standalone components are excellent candidates for initial Rust projects. Performance-critical systems that would benefit from lower latency or reduced resource usage are another natural starting point. Command-line tools and utilities offer low-risk opportunities to build team expertise.&lt;&#x2F;p&gt;
&lt;p&gt;The key to successful migration is maintaining optionality. Rust’s excellent interop capabilities mean you can gradually introduce it alongside existing JVM services. This allows teams to learn and validate Rust’s benefits in your specific context without committing to a wholesale rewrite.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;addressing-challenges&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#addressing-challenges&quot; aria-label=&quot;Anchor link for: addressing-challenges&quot;&gt;Addressing Challenges&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;p&gt;The transition to Rust does present challenges. The ownership and borrowing concepts take time to master, though the compiler’s excellent error messages help guide developers through the learning process. The ecosystem, while growing rapidly, may not yet have direct equivalents for all specialized JVM libraries. Some internal tooling may need to be rebuilt or adapted.&lt;&#x2F;p&gt;
&lt;p&gt;However, these challenges should be viewed in context. The learning curve, while steep, is finite — developers
with a strong functional programming background typically become productive in Rust within a few months. The ecosystem limitations often push teams toward simpler, more maintainable solutions. And the need to rebuild tools can be an opportunity to improve and modernize development workflows.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;conclusion&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#conclusion&quot; aria-label=&quot;Anchor link for: conclusion&quot;&gt;Conclusion&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;p&gt;The decision to migrate from Scala&#x2F;Clojure to Rust should be driven by specific business needs rather than following trends.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;strong&gt;Consider Rust when performance and resource efficiency are crucial, when you need predictable latency and memory usage, when your team is ready for a new technical challenge, or when long-term stability and maintenance are priorities.&lt;&#x2F;strong&gt;&lt;&#x2F;p&gt;
&lt;p&gt;The transition requires investment, but Rust’s growing ecosystem, excellent tooling, and strong industry adoption make it an increasingly attractive option for organizations looking to move beyond the JVM while maintaining the benefits of strong typing and functional programming paradigms.&lt;&#x2F;p&gt;
&lt;div class=&quot;info&quot;&gt;
  
  &lt;div class=&quot;info-header&quot;&gt;
    
      &lt;span class=&quot;icon icon-info&quot;&gt;&lt;&#x2F;span&gt;
    
    &lt;h4&gt;&lt;p&gt;Is Your Team Considering a Migration to Rust?&lt;&#x2F;p&gt;
&lt;&#x2F;h4&gt;
  &lt;&#x2F;div&gt;
  
  &lt;p&gt;I can help you evaluate your current systems, design a migration strategy, and
help you make an informed decision about moving to Rust. I offer consulting
services to help you assess the technical and business implications of a
migration, and I can train your developers to succeed with Rust.
&lt;a href=&quot;&#x2F;services&quot;&gt;Get in touch for a free consultation&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;

&lt;&#x2F;div&gt;
</description>
      </item>
      <item>
          <title>Rust Conferences 2025</title>
          <pubDate>Tue, 03 Dec 2024 00:00:00 +0000</pubDate>
          <author>Matthias Endler</author>
          <link>https://corrode.dev/blog/rust-conferences-2025/</link>
          <guid>https://corrode.dev/blog/rust-conferences-2025/</guid>
          <description xml:base="https://corrode.dev/blog/rust-conferences-2025/">&lt;div class=&quot;info&quot;&gt;
  
  &lt;div class=&quot;info-header&quot;&gt;
    
      &lt;span class=&quot;icon icon-ferris&quot;&gt;&lt;&#x2F;span&gt;
    
    &lt;h4&gt;&lt;p&gt;Looking for upcoming Rust conferences?&lt;&#x2F;p&gt;
&lt;&#x2F;h4&gt;
  &lt;&#x2F;div&gt;
  
  &lt;p&gt;This page covers Rust conferences in 2025. For upcoming events, check out our &lt;a href=&quot;&#x2F;blog&#x2F;rust-conferences-2026&#x2F;&quot;&gt;Rust Conferences 2026&lt;&#x2F;a&gt; page with dates, locations, ticket prices, CFP deadlines, and more.&lt;&#x2F;p&gt;

&lt;&#x2F;div&gt;
&lt;p&gt;Rustaceans like to mingle, learn, and share their knowledge at conferences.
With 13 conferences happening in 2025, it was a busy year for the Rust community.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;q1-2025&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#q1-2025&quot; aria-label=&quot;Anchor link for: q1-2025&quot;&gt;Q1 2025&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;h3 id=&quot;rust-nation-london-uk&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#rust-nation-london-uk&quot; aria-label=&quot;Anchor link for: rust-nation-london-uk&quot;&gt;Rust Nation (London, UK)&lt;&#x2F;a&gt;&lt;&#x2F;h3&gt;
&lt;a href=&quot;https:&#x2F;&#x2F;www.rustnationuk.com&#x2F;&quot; target=&quot;_blank&quot;&gt;
  &lt;img src=&quot;rustnation.jpg&quot; alt=&quot;Rust Nation&quot; &#x2F;&gt;
&lt;&#x2F;a&gt;
&lt;p&gt;Rust Nation has evolved into a staple event in the Rust community.
The organization, speaker lineup, and recordings are always top-notch.
It’s a great conference for Rust developers of all levels.
As per tradition, they kick off the year of Rust conferences.&lt;&#x2F;p&gt;
&lt;button onclick=&quot;window.open(&#x27;https:&#x2F;&#x2F;www.youtube.com&#x2F;watch?v=fmtykJT1acM&amp;list=PL1AoGvxomykSSFFL4Qav3wKzL-dsi9I5L&#x27;, &#x27;_blank&#x27;)&quot; class=&quot;button&quot; style=&quot;display: inline-flex; align-items: center; gap: 8px;&quot;&gt;
  &lt;svg width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;currentColor&quot;&gt;
    &lt;path d=&quot;M8 5v14l11-7z&quot;&#x2F;&gt;
  &lt;&#x2F;svg&gt;
  Recordings Available
&lt;&#x2F;button&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;When&lt;&#x2F;strong&gt;: February 19-20, 2025&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Where&lt;&#x2F;strong&gt;: &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;maps.app.goo.gl&#x2F;QakezC3gjkyo7sNr9&quot;&gt;The Brewery, 52 Chiswell Street, London, EC1Y 4SD, UK&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Format&lt;&#x2F;strong&gt;: 2 days (workshops + conference)&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Focus&lt;&#x2F;strong&gt;: Rust ecosystem and community&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Pricing&lt;&#x2F;strong&gt;:
&lt;ul&gt;
&lt;li&gt;Conference: $304 (early bird)&lt;&#x2F;li&gt;
&lt;li&gt;Workshops: Starting at $300&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;CFP&lt;&#x2F;strong&gt;: Closed&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Links&lt;&#x2F;strong&gt;: &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.rustnationuk.com&#x2F;&quot;&gt;Website&lt;&#x2F;a&gt; | &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.rustnationuk.com&#x2F;schedule&quot;&gt;Schedule&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Social&lt;&#x2F;strong&gt;: &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;x.com&#x2F;rustnationuk&quot;&gt;Twitter&lt;&#x2F;a&gt; | &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;hachyderm.io&#x2F;@Rustnationuk&quot;&gt;Mastodon&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h3 id=&quot;rust-in-paris-france&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#rust-in-paris-france&quot; aria-label=&quot;Anchor link for: rust-in-paris-france&quot;&gt;Rust in Paris (France)&lt;&#x2F;a&gt;&lt;&#x2F;h3&gt;
&lt;a href=&quot;https:&#x2F;&#x2F;rustinparis.com&#x2F;&quot; target=&quot;_blank&quot;&gt;
  &lt;img src=&quot;rustinparis.jpg&quot; alt=&quot;Rust in Paris&quot; &#x2F;&gt;
&lt;&#x2F;a&gt;
&lt;p&gt;“When Safety Meets Elegance” is the tagline for Rust in Paris.
It features 12 speakers, 1 day of talks, and 250 attendees.&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;When&lt;&#x2F;strong&gt;: March 14, 2025&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Where&lt;&#x2F;strong&gt;: &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;maps.app.goo.gl&#x2F;VDAktMFd8KHMeZ36A&quot;&gt;Maison.A Verso, 52 rue de la victoire, 75009 Paris - France&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Format&lt;&#x2F;strong&gt;: 1 day conference&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Focus&lt;&#x2F;strong&gt;: Building secure, high-performing software with Rust&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Pricing&lt;&#x2F;strong&gt;:
&lt;ul&gt;
&lt;li&gt;Standard: $311 (early bird)&lt;&#x2F;li&gt;
&lt;li&gt;Student: $124&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;CFP&lt;&#x2F;strong&gt;: Closed&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Links&lt;&#x2F;strong&gt;: &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;rustinparis.com&#x2F;&quot;&gt;Website&lt;&#x2F;a&gt; | &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;rustinparis.com&#x2F;schedule&quot;&gt;Schedule&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h3 id=&quot;rustmeet-gliwice-poland&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#rustmeet-gliwice-poland&quot; aria-label=&quot;Anchor link for: rustmeet-gliwice-poland&quot;&gt;RUSTMEET (Gliwice, Poland)&lt;&#x2F;a&gt;&lt;&#x2F;h3&gt;
&lt;a href=&quot;https:&#x2F;&#x2F;rustmeet.eu&#x2F;&quot; target=&quot;_blank&quot;&gt;
  &lt;img src=&quot;rustmeet.jpg&quot; alt=&quot;RUSTMEET&quot; &#x2F;&gt;
&lt;&#x2F;a&gt;
&lt;p&gt;An event in Poland, actively co-created by Rust enthusiasts.&lt;&#x2F;p&gt;
&lt;button onclick=&quot;window.open(&#x27;https:&#x2F;&#x2F;www.youtube.com&#x2F;watch?v=v3bpw7fcjp0&amp;list=PLp10ZrVkzfVqLOjf9KXe25igeZXPNCwhL&#x27;, &#x27;_blank&#x27;)&quot; class=&quot;button&quot; style=&quot;display: inline-flex; align-items: center; gap: 8px;&quot;&gt;
  &lt;svg width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;currentColor&quot;&gt;
    &lt;path d=&quot;M8 5v14l11-7z&quot;&#x2F;&gt;
  &lt;&#x2F;svg&gt;
  Recordings Available
&lt;&#x2F;button&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;When&lt;&#x2F;strong&gt;: March 15-16, 2025&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Where&lt;&#x2F;strong&gt;: &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;maps.app.goo.gl&#x2F;38cqAgQBnDG7nNvM7&quot;&gt;Gliwice, Poland&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Format&lt;&#x2F;strong&gt;: 2 days (talks + workshops)&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Focus&lt;&#x2F;strong&gt;: Rust programming language&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Pricing&lt;&#x2F;strong&gt;:
&lt;ul&gt;
&lt;li&gt;Standard: $120&lt;&#x2F;li&gt;
&lt;li&gt;Student: $20&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;CFP&lt;&#x2F;strong&gt;: &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;rustmeet.confreg.pl&#x2F;events&#x2F;30-rustmeet-2025&quot;&gt;Closed&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Links&lt;&#x2F;strong&gt;: &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;rustmeet.eu&#x2F;&quot;&gt;Website&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Social&lt;&#x2F;strong&gt;: &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.linkedin.com&#x2F;company&#x2F;rustmeet&#x2F;&quot;&gt;LinkedIn&lt;&#x2F;a&gt; | &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;c.im&#x2F;@rustmeet&quot;&gt;Mastodon&lt;&#x2F;a&gt; | &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;bsky.app&#x2F;profile&#x2F;rustmeet.bsky.social&quot;&gt;BlueSky&lt;&#x2F;a&gt; | &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;discord.com&#x2F;invite&#x2F;CsVnFrYVzm&quot;&gt;Discord&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h3 id=&quot;rustikon-warsaw-poland&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#rustikon-warsaw-poland&quot; aria-label=&quot;Anchor link for: rustikon-warsaw-poland&quot;&gt;Rustikon (Warsaw, Poland)&lt;&#x2F;a&gt;&lt;&#x2F;h3&gt;
&lt;a href=&quot;https:&#x2F;&#x2F;www.rustikon.dev&#x2F;&quot; target=&quot;_blank&quot;&gt;
  &lt;img src=&quot;rustikon.jpg&quot; alt=&quot;Rustikon&quot; &#x2F;&gt;
&lt;&#x2F;a&gt;
&lt;p&gt;Aims to bring together Rust developers from the region and beyond.
Expect a developer-friendly atmosphere with ~15 expert talks in a single-track format, perfect for staying connected and engaged. After a day of learning, unwind with us in a local pub and network with fellow devs.&lt;&#x2F;p&gt;
&lt;button onclick=&quot;window.open(&#x27;https:&#x2F;&#x2F;www.youtube.com&#x2F;watch?v=4QkLD7JhD_I&amp;list=PL8NC5lCgGs6MnMLJvhFH2jLa8bLYwCzmI&#x27;, &#x27;_blank&#x27;)&quot; class=&quot;button&quot; style=&quot;display: inline-flex; align-items: center; gap: 8px;&quot;&gt;
  &lt;svg width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;currentColor&quot;&gt;
    &lt;path d=&quot;M8 5v14l11-7z&quot;&#x2F;&gt;
  &lt;&#x2F;svg&gt;
  Recordings Available
&lt;&#x2F;button&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;When&lt;&#x2F;strong&gt;: March 26, 2025&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Where&lt;&#x2F;strong&gt;: &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;maps.app.goo.gl&#x2F;XKR76zuE2D8XbZMp6&quot;&gt;POLIN Conference Centre, Warsaw&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Format&lt;&#x2F;strong&gt;: 1 day conference&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Focus&lt;&#x2F;strong&gt;: Rust adoption in Poland and beyond&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Pricing&lt;&#x2F;strong&gt;:
&lt;ul&gt;
&lt;li&gt;Standard: $172&lt;&#x2F;li&gt;
&lt;li&gt;Student: $12&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;CFP&lt;&#x2F;strong&gt;: Closed&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Links&lt;&#x2F;strong&gt;: &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.rustikon.dev&#x2F;&quot;&gt;Website&lt;&#x2F;a&gt; | &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.rustikon.dev&#x2F;tickets&quot;&gt;Tickets&lt;&#x2F;a&gt; | &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;softwaremill.com&#x2F;why-attend-a-rust-conference-for-developers-rustikon&#x2F;&quot;&gt;Announcement&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Social&lt;&#x2F;strong&gt;: &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;x.com&#x2F;rustikonconf&quot;&gt;Twitter&lt;&#x2F;a&gt; | &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;mastodon.social&#x2F;@Rustikon&quot;&gt;Mastodon&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h3 id=&quot;rustasia-hong-kong&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#rustasia-hong-kong&quot; aria-label=&quot;Anchor link for: rustasia-hong-kong&quot;&gt;RUSTAsia (Hong Kong)&lt;&#x2F;a&gt;&lt;&#x2F;h3&gt;
&lt;a target=&quot;_blank&quot;&gt;
  &lt;img src=&quot;rustasia.jpg&quot; alt=&quot;RUSTAsia&quot; &#x2F;&gt;
&lt;&#x2F;a&gt;
&lt;p&gt;Another first-time event, RUSTAsia is a conference for Rust developers in Asia.
After many years without a Rust conference in Asia (the last one being RustCon Asia in 2019), the community is excited to have a new event in Hong Kong.&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;When&lt;&#x2F;strong&gt;: March 28, 2025&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Where&lt;&#x2F;strong&gt;: &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;maps.app.goo.gl&#x2F;fcQqo9YCpnDgjjnP6&quot;&gt;InnoCentre, Kowloon Tong, Hong Kong&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Format&lt;&#x2F;strong&gt;: Hybrid (in-person + online)&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Focus&lt;&#x2F;strong&gt;: Rust in Asia&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Pricing&lt;&#x2F;strong&gt;:
&lt;ul&gt;
&lt;li&gt;Online: $68&lt;&#x2F;li&gt;
&lt;li&gt;Standard: $245 (early bird)&lt;&#x2F;li&gt;
&lt;li&gt;VIP: $375&lt;&#x2F;li&gt;
&lt;li&gt;Corporate: $450&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;CFP&lt;&#x2F;strong&gt;: Closed&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Links&lt;&#x2F;strong&gt;: Website offline&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Social&lt;&#x2F;strong&gt;: &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;x.com&#x2F;rustasiaconf&quot;&gt;Twitter&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h2 id=&quot;q2-2025&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#q2-2025&quot; aria-label=&quot;Anchor link for: q2-2025&quot;&gt;Q2 2025&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;h3 id=&quot;rust-konf-turkiye-istanbul&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#rust-konf-turkiye-istanbul&quot; aria-label=&quot;Anchor link for: rust-konf-turkiye-istanbul&quot;&gt;Rust Konf Türkiye (Istanbul)&lt;&#x2F;a&gt;&lt;&#x2F;h3&gt;
&lt;a href=&quot;https:&#x2F;&#x2F;kommunity.com&#x2F;turkiye-rust-community&#x2F;events&#x2F;rust-konf-turkiye-@-april-20-2025&quot; target=&quot;_blank&quot;&gt;
  &lt;img src=&quot;rustkonf-turkiye.jpg&quot; alt=&quot;Rust Konf Türkiye&quot; &#x2F;&gt;
&lt;&#x2F;a&gt;
&lt;p&gt;The first-ever Rust conference in Turkey, bringing together Rust developers and enthusiasts
for a day of technical talks, workshops, and networking. The event will feature in-depth
technical sessions on low-level programming, performance optimization, system-level
development, and eBPF.&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;When&lt;&#x2F;strong&gt;: April 20, 2025&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Where&lt;&#x2F;strong&gt;: Istanbul, Turkey (venue TBA)&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Format&lt;&#x2F;strong&gt;: 1 day (talks + workshops)&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Focus&lt;&#x2F;strong&gt;: Low-level programming, system development, and Rust ecosystem&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Pricing&lt;&#x2F;strong&gt;: Free&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;CFP&lt;&#x2F;strong&gt;: Closed&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Links&lt;&#x2F;strong&gt;: &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;kommunity.com&#x2F;turkiye-rust-community&#x2F;events&#x2F;rust-konf-turkiye-91f7b3a6&quot;&gt;Website&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Social&lt;&#x2F;strong&gt;: &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;x.com&#x2F;turkiyerustcom&quot;&gt;Twitter&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h3 id=&quot;rustweek-utrecht-netherlands&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#rustweek-utrecht-netherlands&quot; aria-label=&quot;Anchor link for: rustweek-utrecht-netherlands&quot;&gt;RustWeek (Utrecht, Netherlands)&lt;&#x2F;a&gt;&lt;&#x2F;h3&gt;
&lt;a href=&quot;https:&#x2F;&#x2F;rustweek.org&#x2F;&quot; target=&quot;_blank&quot;&gt;
  &lt;img src=&quot;rustweek.jpg&quot; alt=&quot;RustWeek&quot; &#x2F;&gt;
&lt;&#x2F;a&gt;
&lt;p&gt;RustWeek is a week-long event that combines talks, workshops, and social events.
It’s located in cozy Utrecht, the fourth-largest city in the Netherlands.
This is organized by the team behind RustNL. RustWeek takes place during the 10 year
anniversary of Rust 1.0. All Rustaceans are welcome to attend and submit talks.&lt;&#x2F;p&gt;
&lt;button onclick=&quot;window.open(&#x27;https:&#x2F;&#x2F;www.youtube.com&#x2F;playlist?list=PL8Q1w7Ff68DCEXiGidlM0DMn8ztjlUlez&#x27;, &#x27;_blank&#x27;)&quot; class=&quot;button&quot; style=&quot;display: inline-flex; align-items: center; gap: 8px;&quot;&gt;
  &lt;svg width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;currentColor&quot;&gt;
    &lt;path d=&quot;M8 5v14l11-7z&quot;&#x2F;&gt;
  &lt;&#x2F;svg&gt;
  Recordings Available
&lt;&#x2F;button&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;When&lt;&#x2F;strong&gt;: May 12-17, 2025&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Where&lt;&#x2F;strong&gt;: &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;maps.app.goo.gl&#x2F;NfdQrMmPHEpy3ZZMA&quot;&gt;Kinepolis Utrecht&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Format&lt;&#x2F;strong&gt;: Full week (2 days talks + 1 day workshops + social events)&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Focus&lt;&#x2F;strong&gt;: Broad, open to everyone&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Pricing&lt;&#x2F;strong&gt; (Early Bird):
&lt;ul&gt;
&lt;li&gt;Standard: $197&lt;&#x2F;li&gt;
&lt;li&gt;Company: $390&lt;&#x2F;li&gt;
&lt;li&gt;Conference + Workshop: $343 (Individual) &#x2F; $592 (Company)&lt;&#x2F;li&gt;
&lt;li&gt;Student: $31&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;CfP&lt;&#x2F;strong&gt;: &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.papercall.io&#x2F;rust-week&quot;&gt;Closed&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Links&lt;&#x2F;strong&gt;: &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;rustweek.org&#x2F;&quot;&gt;Website&lt;&#x2F;a&gt; | &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.youtube.com&#x2F;@rustnederlandrustnl&quot;&gt;Past Talks&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Social&lt;&#x2F;strong&gt;: &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;bsky.app&#x2F;profile&#x2F;rustnl.bsky.social&quot;&gt;BlueSky&lt;&#x2F;a&gt; | &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;fosstodon.org&#x2F;@rustnl&quot;&gt;Mastodon&lt;&#x2F;a&gt; | &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.linkedin.com&#x2F;company&#x2F;rustnl&#x2F;&quot;&gt;LinkedIn&lt;&#x2F;a&gt; | &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;x.com&#x2F;Rust_NL&quot;&gt;Twitter&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h3 id=&quot;rust-summit-belgrade-serbia&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#rust-summit-belgrade-serbia&quot; aria-label=&quot;Anchor link for: rust-summit-belgrade-serbia&quot;&gt;Rust Summit (Belgrade, Serbia)&lt;&#x2F;a&gt;&lt;&#x2F;h3&gt;
&lt;a href=&quot;https:&#x2F;&#x2F;rustsummit.com&#x2F;&quot; target=&quot;_blank&quot;&gt;
  &lt;img src=&quot;rustsummit.jpg&quot; alt=&quot;Rust Summit&quot; &#x2F;&gt;
&lt;&#x2F;a&gt;
&lt;p&gt;The first conference for Rust blockchain professionals.&lt;&#x2F;p&gt;
&lt;p&gt;The Rust Summit is first-of-its-kind chain-agnostic conference, featuring expert
talks, workshops, and networking opportunities for Rust blockchain
professionals. It is open to all Rust developers active in the web3 and
blockchain sectors and those who are interested in it.&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;When&lt;&#x2F;strong&gt;: June 7, 2025&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Where&lt;&#x2F;strong&gt;: Belgrade, Serbia&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Format&lt;&#x2F;strong&gt;: 1 day conference&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Focus&lt;&#x2F;strong&gt;: Blockchain&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Pricing&lt;&#x2F;strong&gt;: $73 (General Admission)&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;CFP&lt;&#x2F;strong&gt;: &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;forms.gle&#x2F;3VTuvYHhXmzwTLeU9&quot;&gt;Closed&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Links&lt;&#x2F;strong&gt;: &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;rustsummit.com&#x2F;&quot;&gt;Website&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Social&lt;&#x2F;strong&gt;: &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;x.com&#x2F;rust_summit&quot;&gt;Twitter&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h2 id=&quot;q3-2025&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#q3-2025&quot; aria-label=&quot;Anchor link for: q3-2025&quot;&gt;Q3 2025&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;h3 id=&quot;rustforge-wellington-new-zealand&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#rustforge-wellington-new-zealand&quot; aria-label=&quot;Anchor link for: rustforge-wellington-new-zealand&quot;&gt;RustForge (Wellington, New Zealand)&lt;&#x2F;a&gt;&lt;&#x2F;h3&gt;
&lt;a href=&quot;https:&#x2F;&#x2F;rustforgeconf.com&#x2F;&quot; target=&quot;_blank&quot;&gt;
  &lt;img src=&quot;rustforge.jpg&quot; alt=&quot;RustForge&quot; &#x2F;&gt;
&lt;&#x2F;a&gt;
&lt;p&gt;RustForge is the first conference in the Asia&#x2F;Pacific region that focuses on Rust.&lt;&#x2F;p&gt;
&lt;button onclick=&quot;window.open(&#x27;https:&#x2F;&#x2F;www.youtube.com&#x2F;watch?v=es48dmNWMVQ&#x27;, &#x27;_blank&#x27;)&quot; class=&quot;button&quot; style=&quot;display: inline-flex; align-items: center; gap: 8px;&quot;&gt;
  &lt;svg width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;currentColor&quot;&gt;
    &lt;path d=&quot;M8 5v14l11-7z&quot;&#x2F;&gt;
  &lt;&#x2F;svg&gt;
  Recordings Available
&lt;&#x2F;button&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;When&lt;&#x2F;strong&gt;: August 27-30, 2025&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Where&lt;&#x2F;strong&gt;: &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;maps.app.goo.gl&#x2F;PDbFTB5Gqs5iVmeNA&quot;&gt;Shed 6, Wellington, New Zealand&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Format&lt;&#x2F;strong&gt;: 4 days (2 days workshops + 2 days conference)&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Focus&lt;&#x2F;strong&gt;: Community-focused conference with emphasis on hallway track&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Pricing&lt;&#x2F;strong&gt;:
&lt;ul&gt;
&lt;li&gt;Conference: $225&lt;&#x2F;li&gt;
&lt;li&gt;Workshops: $425&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;rust-forge-2025.lilregie.com&#x2F;booking&#x2F;attendees&#x2F;new&quot;&gt;Get tickets here&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;CFP&lt;&#x2F;strong&gt;: &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;pretalx.com&#x2F;rust-forge-2025&#x2F;cfp&quot;&gt;Closed&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Links&lt;&#x2F;strong&gt;: &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;rustforgeconf.com&#x2F;&quot;&gt;Website&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Social&lt;&#x2F;strong&gt;: &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;x.com&#x2F;rustforgeconf&quot;&gt;Twitter&lt;&#x2F;a&gt; | &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.linkedin.com&#x2F;company&#x2F;rustforgeconf&#x2F;&quot;&gt;LinkedIn&lt;&#x2F;a&gt; | &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.instagram.com&#x2F;rustforgeconf&#x2F;&quot;&gt;Instagram&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h3 id=&quot;rustconf-seattle-washington-usa&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#rustconf-seattle-washington-usa&quot; aria-label=&quot;Anchor link for: rustconf-seattle-washington-usa&quot;&gt;RustConf (Seattle, Washington, USA)&lt;&#x2F;a&gt;&lt;&#x2F;h3&gt;
&lt;a href=&quot;https:&#x2F;&#x2F;rustconf.com&#x2F;&quot; target=&quot;_blank&quot;&gt;
  &lt;img src=&quot;rustconf.jpg&quot; alt=&quot;RustConf&quot; &#x2F;&gt;
&lt;&#x2F;a&gt;
&lt;p&gt;RustConf is the official Rust conference organized by the Rust Foundation.
It’s a great place to meet the Rust core team and other community members.
The last edition was held in Montreal, Canada and the 2025 edition will be announced soon.&lt;&#x2F;p&gt;
&lt;button onclick=&quot;window.open(&#x27;https:&#x2F;&#x2F;www.youtube.com&#x2F;watch?v=dA-uv3yCMZc&amp;list=PL2b0df3jKKiRFEuVNk76ufXagOgEJ9sBZ&#x27;, &#x27;_blank&#x27;)&quot; class=&quot;button&quot; style=&quot;display: inline-flex; align-items: center; gap: 8px;&quot;&gt;
  &lt;svg width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;currentColor&quot;&gt;
    &lt;path d=&quot;M8 5v14l11-7z&quot;&#x2F;&gt;
  &lt;&#x2F;svg&gt;
  Recordings Available
&lt;&#x2F;button&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;When&lt;&#x2F;strong&gt;: September 2-5, 2025&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Where&lt;&#x2F;strong&gt;: Seattle, Washington, USA&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Format&lt;&#x2F;strong&gt;: 4 days (1 day workshops + 3 days talks)&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Focus&lt;&#x2F;strong&gt;: Official Rust conference&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Pricing&lt;&#x2F;strong&gt;:
&lt;ul&gt;
&lt;li&gt;Regular: $525&lt;&#x2F;li&gt;
&lt;li&gt;Corporate: $775&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;rustconf.com&#x2F;register&#x2F;&quot;&gt;Get tickets here&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;CFP&lt;&#x2F;strong&gt;: Closed&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Links&lt;&#x2F;strong&gt;: &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;rustconf.com&#x2F;&quot;&gt;Website&lt;&#x2F;a&gt; | &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.youtube.com&#x2F;@rustfoundation&quot;&gt;Past Talks&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Social&lt;&#x2F;strong&gt;: &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;hachyderm.io&#x2F;@rustconf&quot;&gt;Mastodon&lt;&#x2F;a&gt;, &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;bsky.app&#x2F;profile&#x2F;rustconf.com&quot;&gt;BlueSky&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h3 id=&quot;oxidize-berlin-germany&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#oxidize-berlin-germany&quot; aria-label=&quot;Anchor link for: oxidize-berlin-germany&quot;&gt;Oxidize (Berlin, Germany)&lt;&#x2F;a&gt;&lt;&#x2F;h3&gt;
&lt;a href=&quot;https:&#x2F;&#x2F;oxidizeconf.com&#x2F;&quot; target=&quot;_blank&quot;&gt;
  &lt;img src=&quot;oxidize.jpg&quot; alt=&quot;Oxidize&quot; &#x2F;&gt;
&lt;&#x2F;a&gt;
&lt;p&gt;Two days of applied Rust insights from industry innovators.
Topics range from cross-platform GUI development to Rust in safety-critical systems.&lt;&#x2F;p&gt;
&lt;button onclick=&quot;window.open(&#x27;https:&#x2F;&#x2F;www.youtube.com&#x2F;watch?v=jyGVk2aMEjE&amp;list=PLilpJp3WAOvcn5_VDv3VIkQzniMWl_BfO&#x27;, &#x27;_blank&#x27;)&quot; class=&quot;button&quot; style=&quot;display: inline-flex; align-items: center; gap: 8px;&quot;&gt;
  &lt;svg width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;currentColor&quot;&gt;
    &lt;path d=&quot;M8 5v14l11-7z&quot;&#x2F;&gt;
  &lt;&#x2F;svg&gt;
  Recordings Available
&lt;&#x2F;button&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;When&lt;&#x2F;strong&gt;: September 16-18, 2025&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Where&lt;&#x2F;strong&gt;: &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;maps.app.goo.gl&#x2F;Q3SzoU7EDJv4kxnHA&quot;&gt;Tagungswerk, Berlin, Germany&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Format&lt;&#x2F;strong&gt;: 3 days (1 day workshops + 2 days talks)&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Focus&lt;&#x2F;strong&gt;: Applied Rust insights&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Pricing&lt;&#x2F;strong&gt;:
&lt;ul&gt;
&lt;li&gt;Conference only: €505.75&lt;&#x2F;li&gt;
&lt;li&gt;Workshop + Conference: €653.31&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;ti.to&#x2F;asquera-event-ug&#x2F;oxidize-conference-2025&quot;&gt;Get tickets here&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;CFP&lt;&#x2F;strong&gt;: Closed&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Links&lt;&#x2F;strong&gt;: &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;oxidizeconf.com&#x2F;&quot;&gt;Website&lt;&#x2F;a&gt; | &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.youtube.com&#x2F;@OxidizeConf&quot;&gt;Past Talks&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Social&lt;&#x2F;strong&gt;: &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;x.com&#x2F;OxidizeConf&quot;&gt;Twitter&lt;&#x2F;a&gt; | &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;social.ferrous-systems.com&#x2F;@oxidize&quot;&gt;Mastodon&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h2 id=&quot;q4-2025&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#q4-2025&quot; aria-label=&quot;Anchor link for: q4-2025&quot;&gt;Q4 2025&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;h3 id=&quot;eurorust-paris-france&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#eurorust-paris-france&quot; aria-label=&quot;Anchor link for: eurorust-paris-france&quot;&gt;EuroRust (Paris, France)&lt;&#x2F;a&gt;&lt;&#x2F;h3&gt;
&lt;a href=&quot;https:&#x2F;&#x2F;eurorust.eu&#x2F;&quot; target=&quot;_blank&quot;&gt;
  &lt;img src=&quot;eurorust.jpg&quot; alt=&quot;EuroRust&quot; &#x2F;&gt;
&lt;&#x2F;a&gt;
&lt;p&gt;One of the largest Rust conferences in Europe and a well-established event in
the Rust community. It’s a 2 day conference that covers all things Rust: from
Rust patterns and idioms to system programming and CLI tooling, servers WASM and
embedded systems.&lt;&#x2F;p&gt;
&lt;p&gt;The conference travels to a different European city each year.
This time, it’s in Paris, France. 🥖&lt;&#x2F;p&gt;
&lt;button onclick=&quot;window.open(&#x27;https:&#x2F;&#x2F;www.youtube.com&#x2F;watch?v=4sYzxv6YijI&amp;list=PLH6-VpZ3SvUUO_lfxniFmyKxUMngBOWFg&#x27;, &#x27;_blank&#x27;)&quot; class=&quot;button&quot; style=&quot;display: inline-flex; align-items: center; gap: 8px;&quot;&gt;
  &lt;svg width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;currentColor&quot;&gt;
    &lt;path d=&quot;M8 5v14l11-7z&quot;&#x2F;&gt;
  &lt;&#x2F;svg&gt;
  Recordings Available
&lt;&#x2F;button&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;When&lt;&#x2F;strong&gt;: October 9-10, 2025&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Where&lt;&#x2F;strong&gt;: &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;maps.app.goo.gl&#x2F;4SNzfvFVF3VqMDY5A&quot;&gt;Cité des Sciences et de l’Industrie, Paris, France&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Format&lt;&#x2F;strong&gt;: 2 days talks&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Focus&lt;&#x2F;strong&gt;: Rust patterns, idioms, system programming, CLI tooling, servers, WASM, embedded systems&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Pricing&lt;&#x2F;strong&gt;: &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;ti.to&#x2F;events-matter&#x2F;eurorust-2025&quot;&gt;Get tickets here&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;CFP&lt;&#x2F;strong&gt;: &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.papercall.io&#x2F;eurorust-2025&quot;&gt;Closed&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Links&lt;&#x2F;strong&gt;: &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;eurorust.eu&#x2F;&quot;&gt;Website&lt;&#x2F;a&gt; | &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.youtube.com&#x2F;@eurorust&quot;&gt;Past Talks&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Social&lt;&#x2F;strong&gt;: &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;x.com&#x2F;euro_rust&quot;&gt;Twitter&lt;&#x2F;a&gt; | &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;fosstodon.org&#x2F;@eurorust&quot;&gt;Mastodon&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h3 id=&quot;rustlab-florence-italy&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#rustlab-florence-italy&quot; aria-label=&quot;Anchor link for: rustlab-florence-italy&quot;&gt;RustLab (Florence, Italy)&lt;&#x2F;a&gt;&lt;&#x2F;h3&gt;
&lt;a href=&quot;https:&#x2F;&#x2F;rustlab.it&#x2F;&quot; target=&quot;_blank&quot;&gt;
  &lt;img src=&quot;rustlab.jpg&quot; alt=&quot;RustLab&quot; &#x2F;&gt;
&lt;&#x2F;a&gt;
&lt;p&gt;The Italian Rust conference traditionally takes place in Florence.
It’s lovingly organized featuring delicious italian food and a great community.&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;When&lt;&#x2F;strong&gt;: November 2-4, 2025&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Where&lt;&#x2F;strong&gt;: &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;goo.gl&#x2F;maps&#x2F;8ZRuugSHEfebowwi7&quot;&gt;Grand Hotel Mediterraneo Lungarno del Tempio, 44, 50121 Florence, Italy&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Format&lt;&#x2F;strong&gt;: 3 days (1 day workshops + 2 days talks)&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Focus&lt;&#x2F;strong&gt;: Rust in Italy and beyond&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Pricing&lt;&#x2F;strong&gt;:
&lt;ul&gt;
&lt;li&gt;270€ Regular Ticket&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;rustlab.it&#x2F;tickets25&quot;&gt;Get tickets here&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;CFP&lt;&#x2F;strong&gt;: &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;sessionize.com&#x2F;rustlab-2025&#x2F;&quot;&gt;Closed&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Links&lt;&#x2F;strong&gt;: &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;rustlab.it&#x2F;&quot;&gt;Website&lt;&#x2F;a&gt; | &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.youtube.com&#x2F;@rustlabconference3671&quot;&gt;Past Talks&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Social&lt;&#x2F;strong&gt;: &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;x.com&#x2F;rustlab_conf&quot;&gt;Twitter&lt;&#x2F;a&gt; | &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;mastodon.uno&#x2F;@rustlab&quot;&gt;Mastodon&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;hr &#x2F;&gt;
&lt;p&gt;That was the complete lineup of Rust conferences for 2025! From London to Hong Kong to Seattle, there was something for every Rustacean.
See you at the next conference! 🦀&lt;&#x2F;p&gt;
</description>
      </item>
      <item>
          <title>GitButler</title>
          <pubDate>Thu, 28 Nov 2024 00:00:00 +0000</pubDate>
          <author>Matthias Endler</author>
          <link>https://corrode.dev/podcast/s03e04-gitbutler/</link>
          <guid>https://corrode.dev/podcast/s03e04-gitbutler/</guid>
          <description xml:base="https://corrode.dev/podcast/s03e04-gitbutler/">&lt;div&gt;&lt;script id=&quot;letscast-player-4553b0d1&quot; src=&quot;https:&#x2F;&#x2F;letscast.fm&#x2F;podcasts&#x2F;rust-in-production-82281512&#x2F;episodes&#x2F;gitbutler-with-scott-chacon-and-kiril-videlov&#x2F;player.js?size=s&quot;&gt;&lt;&#x2F;script&gt;&lt;&#x2F;div&gt;
Version control is a critical part of any modern software project
and git is the most popular tool for the job. But it can be complex and
confusing, especially for beginners.
&lt;p&gt;The team behind GitButler believes there is a better way.&lt;&#x2F;p&gt;
&lt;p&gt;They are building a modern Git client that streamlines the process
of managing branches, backing up your work, and more. We hear from co-founders
Scott Chacon and Kiril Videlov about how they’re making Git easier for everyone
– all without sacrificing the power and flexibility that makes Git so popular in
the first place.&lt;&#x2F;p&gt;</description>
      </item>
      <item>
          <title>Oxide</title>
          <pubDate>Thu, 14 Nov 2024 00:00:00 +0000</pubDate>
          <author>Matthias Endler</author>
          <link>https://corrode.dev/podcast/s03e03-oxide/</link>
          <guid>https://corrode.dev/podcast/s03e03-oxide/</guid>
          <description xml:base="https://corrode.dev/podcast/s03e03-oxide/">&lt;div&gt;&lt;script id=&quot;letscast-player-97aa1056&quot; src=&quot;https:&#x2F;&#x2F;letscast.fm&#x2F;podcasts&#x2F;rust-in-production-82281512&#x2F;episodes&#x2F;oxide-s-steve-klabnik&#x2F;player.js?size=s&quot;&gt;&lt;&#x2F;script&gt;&lt;&#x2F;div&gt;
&lt;p&gt;What’s even cooler than writing your own &lt;a href=&quot;&#x2F;podcast&#x2F;s03e01-zed&#x2F;&quot;&gt;text editor&lt;&#x2F;a&gt; or your own &lt;a href=&quot;&#x2F;podcast&#x2F;s02e07-system76&#x2F;&quot;&gt;operating system&lt;&#x2F;a&gt;? Building your own hardware from scratch with all the software written in Rust – including firmware, the scheduler, and the hypervisor.
Oxide Computer Company is one of the most admired companies in the Rust community. They are building “servers as they should be” with a focus on security and performance to serve the needs of modern on-premise data centers.&lt;&#x2F;p&gt;
&lt;p&gt;In this episode, I talk to Steve Klabnik, a software engineer at Oxide and renowned Rustacean, about the advantages of building hardware and software in tandem, the benefits of using Rust for systems programming, and the state of the Rust ecosystem.&lt;&#x2F;p&gt;</description>
      </item>
      <item>
          <title>InfinyOn</title>
          <pubDate>Thu, 31 Oct 2024 00:00:00 +0000</pubDate>
          <author>Matthias Endler</author>
          <link>https://corrode.dev/podcast/s03e02-infinyon/</link>
          <guid>https://corrode.dev/podcast/s03e02-infinyon/</guid>
          <description xml:base="https://corrode.dev/podcast/s03e02-infinyon/">&lt;div&gt;&lt;script id=&quot;letscast-player-6790863d&quot; src=&quot;https:&#x2F;&#x2F;letscast.fm&#x2F;podcasts&#x2F;rust-in-production-82281512&#x2F;episodes&#x2F;infinyon-s-debadyuti-roy-chowdhury&#x2F;player.js?size=s&quot;&gt;&lt;&#x2F;script&gt;&lt;&#x2F;div&gt;
&lt;p&gt;Picture this: Your organization’s data infrastructure resembles a busy kitchen with too many cooks. You’re juggling Kafka for messaging, Flink for processing, Spark for analytics, Airflow for orchestration, and various Lambda functions scattered about. Each tool excellent at its job, but together they’ve created a complex feast of integration challenges. Your data teams are spending more time managing tools than extracting value from data.&lt;&#x2F;p&gt;
&lt;p&gt;InfinyOn reimagines this chaos with a radically simple approach: a unified system for data streaming that runs everywhere.
Unlike traditional solutions that struggle at the edge, InfinyOn gracefully handles data streams from IoT devices to cloud servers.
And instead of cobbling together different tools, developers can build complete data pipelines using their preferred languages - be it Rust, Python, or SQL - with built-in state management.&lt;&#x2F;p&gt;
&lt;p&gt;At the heart of InfinyOn is Fluvio, a Rust-based data streaming platform that’s fast, reliable, and easy to use.&lt;&#x2F;p&gt;</description>
      </item>
      <item>
          <title>Zed</title>
          <pubDate>Thu, 17 Oct 2024 00:00:00 +0000</pubDate>
          <author>Matthias Endler</author>
          <link>https://corrode.dev/podcast/s03e01-zed/</link>
          <guid>https://corrode.dev/podcast/s03e01-zed/</guid>
          <description xml:base="https://corrode.dev/podcast/s03e01-zed/">&lt;div&gt;&lt;script id=&quot;letscast-player-b1a26f96&quot; src=&quot;https:&#x2F;&#x2F;letscast.fm&#x2F;podcasts&#x2F;rust-in-production-82281512&#x2F;episodes&#x2F;zed-with-conrad-irwin&#x2F;player.js?size=s&quot;&gt;&lt;&#x2F;script&gt;&lt;&#x2F;div&gt;
&lt;p&gt;&lt;a href=&quot;&#x2F;podcast&#x2F;s02e07-system76&#x2F;&quot;&gt;Next to writing their own operating system&lt;&#x2F;a&gt;, another dream shared by many developers is building their own text editor. Conrad Irwin, a software engineer at Zed, is doing just that. Zed is a fully extensible, open-source text editor written entirely in Rust. It’s fast, lightweight, and comes with excellent language support out of the box.&lt;&#x2F;p&gt;
&lt;p&gt;In the first episode of the third season, I sit down with Conrad to discuss Zed’s mission to build a next-generation text editor and why it was necessary to rebuild the very foundation of text editing software from scratch to achieve their goals.&lt;&#x2F;p&gt;</description>
      </item>
      <item>
          <title>Don&#x27;t Unwrap Options: There Are Better Ways</title>
          <pubDate>Thu, 29 Aug 2024 00:00:00 +0000</pubDate>
          <author>Matthias Endler</author>
          <link>https://corrode.dev/blog/rust-option-handling-best-practices/</link>
          <guid>https://corrode.dev/blog/rust-option-handling-best-practices/</guid>
          <description xml:base="https://corrode.dev/blog/rust-option-handling-best-practices/">&lt;p&gt;I noticed that handling the &lt;code&gt;None&lt;&#x2F;code&gt; variant of &lt;code&gt;Option&lt;&#x2F;code&gt; without falling back on &lt;code&gt;unwrap()&lt;&#x2F;code&gt; is a common papercut in Rust.
More specifically, the problem arises when you want to return early from a function that returns a &lt;code&gt;Result&lt;&#x2F;code&gt; if you encounter &lt;code&gt;None&lt;&#x2F;code&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;It has been discussed a million times already, but, surprisingly, not even the Rust book mentions my favorite approach to handling that, and many forum posts are outdated.&lt;&#x2F;p&gt;
&lt;p&gt;With a bit of practice, robust handling of &lt;code&gt;None&lt;&#x2F;code&gt; can become as easy as &lt;code&gt;unwrap()&lt;&#x2F;code&gt;, but safer.&lt;&#x2F;p&gt;
&lt;p&gt;Jump to the end if you’re in a hurry and just need a quick recommendation.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;the-problem&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#the-problem&quot; aria-label=&quot;Anchor link for: the-problem&quot;&gt;The Problem&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;p&gt;Very commonly, people write code like this:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;&#x2F;&#x2F; Assume that this fetches the user from somewhere&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;fn&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; get_user&lt;&#x2F;span&gt;&lt;span&gt;()&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; -&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Option&lt;&#x2F;span&gt;&lt;span&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;String&lt;&#x2F;span&gt;&lt;span&gt;&amp;gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;    None&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;fn&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; get_user_name&lt;&#x2F;span&gt;&lt;span&gt;()&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; -&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Result&lt;&#x2F;span&gt;&lt;span&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;String&lt;&#x2F;span&gt;&lt;span&gt;&amp;gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    let&lt;&#x2F;span&gt;&lt;span&gt; user&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; get_user&lt;&#x2F;span&gt;&lt;span&gt;()&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;?&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;    &#x2F;&#x2F; Do something with `user`&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;    &#x2F;&#x2F; ...&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;    Ok&lt;&#x2F;span&gt;&lt;span&gt;(user)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;The goal here is to return early if you encounter &lt;code&gt;None&lt;&#x2F;code&gt; in an &lt;code&gt;Option&lt;&#x2F;code&gt;, so
they use the &lt;code&gt;?&lt;&#x2F;code&gt; operator to propagate errors.&lt;&#x2F;p&gt;
&lt;p&gt;Alas, this code doesn’t compile. Instead, you get a dreaded error message:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;error[&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;E0277&lt;&#x2F;span&gt;&lt;span&gt;]&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span&gt; the `&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;?&lt;&#x2F;span&gt;&lt;span&gt;` operator can only be used on `&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;Result&lt;&#x2F;span&gt;&lt;span&gt;`s, not `&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;Option&lt;&#x2F;span&gt;&lt;span&gt;`s,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; in&lt;&#x2F;span&gt;&lt;span&gt; a function that returns `&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;Result&lt;&#x2F;span&gt;&lt;span&gt;`&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;  --&amp;gt;&lt;&#x2F;span&gt;&lt;span&gt; src&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;&#x2F;&lt;&#x2F;span&gt;&lt;span&gt;lib&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span&gt;rs&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt;10&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt;26&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;   |&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt;9&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;  | fn&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; get_user_name&lt;&#x2F;span&gt;&lt;span&gt;()&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; -&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Result&lt;&#x2F;span&gt;&lt;span&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;String&lt;&#x2F;span&gt;&lt;span&gt;&amp;gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;   | ------------------------------------&lt;&#x2F;span&gt;&lt;span&gt; this function returns a `&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;Result&lt;&#x2F;span&gt;&lt;span&gt;`&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt;10&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; |     let&lt;&#x2F;span&gt;&lt;span&gt; user&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; get_user&lt;&#x2F;span&gt;&lt;span&gt;()&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;?&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;   |                          ^ use&lt;&#x2F;span&gt;&lt;span&gt; `&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span&gt;ok_or(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;...&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;?&lt;&#x2F;span&gt;&lt;span&gt;` to provide an error compatible with `std&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span&gt;result&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;Result&lt;&#x2F;span&gt;&lt;span&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;String&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Box&lt;&#x2F;span&gt;&lt;span&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;dyn&lt;&#x2F;span&gt;&lt;span&gt; std&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span&gt;error&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;Error&lt;&#x2F;span&gt;&lt;span&gt;&amp;gt;&amp;gt;`&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;   |&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;   =&lt;&#x2F;span&gt;&lt;span&gt; help&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span&gt; the &lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;trait&lt;&#x2F;span&gt;&lt;span&gt; `&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;FromResidual&lt;&#x2F;span&gt;&lt;span&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;Option&lt;&#x2F;span&gt;&lt;span&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;Infallible&lt;&#x2F;span&gt;&lt;span&gt;&amp;gt;&amp;gt;` is not implemented &lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;for&lt;&#x2F;span&gt;&lt;span&gt; `std&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span&gt;result&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;Result&lt;&#x2F;span&gt;&lt;span&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;String&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Box&lt;&#x2F;span&gt;&lt;span&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;dyn&lt;&#x2F;span&gt;&lt;span&gt; std&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span&gt;error&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;Error&lt;&#x2F;span&gt;&lt;span&gt;&amp;gt;&amp;gt;`&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;   =&lt;&#x2F;span&gt;&lt;span&gt; help&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span&gt; the following other types implement &lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;trait&lt;&#x2F;span&gt;&lt;span&gt; `&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;FromResidual&lt;&#x2F;span&gt;&lt;span&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;R&lt;&#x2F;span&gt;&lt;span&gt;&amp;gt;`&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;             &amp;lt;std&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span&gt;result&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;Result&lt;&#x2F;span&gt;&lt;span&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;T&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; F&lt;&#x2F;span&gt;&lt;span&gt;&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; as&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; FromResidual&lt;&#x2F;span&gt;&lt;span&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;Yeet&lt;&#x2F;span&gt;&lt;span&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;E&lt;&#x2F;span&gt;&lt;span&gt;&amp;gt;&amp;gt;&amp;gt;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;             &amp;lt;std&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span&gt;result&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;Result&lt;&#x2F;span&gt;&lt;span&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;T&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; F&lt;&#x2F;span&gt;&lt;span&gt;&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; as&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; FromResidual&lt;&#x2F;span&gt;&lt;span&gt;&amp;lt;std&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span&gt;result&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;Result&lt;&#x2F;span&gt;&lt;span&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;Infallible&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; E&lt;&#x2F;span&gt;&lt;span&gt;&amp;gt;&amp;gt;&amp;gt;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;(&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;play.rust-lang.org&#x2F;?version=stable&amp;amp;mode=debug&amp;amp;edition=2021&amp;amp;gist=7001ff6af6c0bcbf44249691d65b086f&quot;&gt;Rust Playground&lt;&#x2F;a&gt;)&lt;&#x2F;p&gt;
&lt;p&gt;Ouch. This is scary-looking!&lt;&#x2F;p&gt;
&lt;p&gt;There’s a lot of visual noise in this error message. The &lt;code&gt;FromResidual&lt;&#x2F;code&gt; and &lt;code&gt;Yeet&lt;&#x2F;code&gt; are implementation details which could be confusing to a new user, and the relevant details are somewhat obscured.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;strong&gt;And all we did was try to use the &lt;code&gt;?&lt;&#x2F;code&gt; operator for our &lt;code&gt;Option&lt;&#x2F;code&gt;.&lt;&#x2F;strong&gt;&lt;&#x2F;p&gt;
&lt;p&gt;My main gripe with this error message is that it doesn’t explain &lt;em&gt;why&lt;&#x2F;em&gt; the &lt;code&gt;?&lt;&#x2F;code&gt; operator doesn’t work with &lt;code&gt;Option&lt;&#x2F;code&gt; in that case… just that it doesn’t.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;what-people-end-up-doing&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#what-people-end-up-doing&quot; aria-label=&quot;Anchor link for: what-people-end-up-doing&quot;&gt;What People End Up Doing&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;p&gt;The most common approach I see is this:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;People are confused for a bit.&lt;&#x2F;li&gt;
&lt;li&gt;They try to understand the error message.&lt;&#x2F;li&gt;
&lt;li&gt;Eventually, they give up and just add &lt;code&gt;unwrap()&lt;&#x2F;code&gt;.&lt;&#x2F;li&gt;
&lt;li&gt;They make a mental note to come back to it later.&lt;&#x2F;li&gt;
&lt;li&gt;‘Later’ never comes.&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;Here’s what they end up with:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;fn&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; get_user_name&lt;&#x2F;span&gt;&lt;span&gt;()&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; -&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Result&lt;&#x2F;span&gt;&lt;span&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;String&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; String&lt;&#x2F;span&gt;&lt;span&gt;&amp;gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    let&lt;&#x2F;span&gt;&lt;span&gt; user&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; get_user&lt;&#x2F;span&gt;&lt;span&gt;()&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;unwrap&lt;&#x2F;span&gt;&lt;span&gt;();&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;    &#x2F;&#x2F; Do something with `user`&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;    Ok&lt;&#x2F;span&gt;&lt;span&gt;(user)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;In trainings, I noticed that people are often too embarrassed to ask for help.
They think people are supposed to &lt;em&gt;“get this”&lt;&#x2F;em&gt; and they are the only ones who don’t.&lt;&#x2F;p&gt;
&lt;p&gt;This just defers the problem.
The user of the function might hit a &lt;code&gt;panic&lt;&#x2F;code&gt; at runtime. That user might be their future self.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;code&gt;unwrap&lt;&#x2F;code&gt; is fine in many cases, but it shouldn’t be the first intuition for dealing with unexpected situations.
Especially when you’re writing a library or a function that is part of a larger codebase, you should strive to handle
such situations gracefully.
And in production code, it sets a bad example:
one &lt;code&gt;unwrap&lt;&#x2F;code&gt; attracts another and the codebase becomes more fragile as you continue down this path. &lt;sup class=&quot;footnote-reference&quot; id=&quot;fr-2-1&quot;&gt;&lt;a href=&quot;#fn-2&quot;&gt;1&lt;&#x2F;a&gt;&lt;&#x2F;sup&gt;&lt;&#x2F;p&gt;
&lt;p&gt;Okay, I’ve kept you waiting long enough. Let’s demystify this error message.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;the-actual-problem&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#the-actual-problem&quot; aria-label=&quot;Anchor link for: the-actual-problem&quot;&gt;The Actual Problem&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;p&gt;What the compiler is trying to tell us is that &lt;strong&gt;you can’t propagate optionals within functions which return &lt;code&gt;Result&lt;&#x2F;code&gt;&lt;&#x2F;strong&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;Everything works just fine if you’re returning an &lt;code&gt;Option&lt;&#x2F;code&gt; instead:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;fn&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; get_user_name&lt;&#x2F;span&gt;&lt;span&gt;()&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; -&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Option&lt;&#x2F;span&gt;&lt;span&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;String&lt;&#x2F;span&gt;&lt;span&gt;&amp;gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;    &#x2F;&#x2F; Works :)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    let&lt;&#x2F;span&gt;&lt;span&gt; user&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; get_user&lt;&#x2F;span&gt;&lt;span&gt;()&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;?&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;    &#x2F;&#x2F; Do something with `user`&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;    &#x2F;&#x2F; ...&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;    Some&lt;&#x2F;span&gt;&lt;span&gt;(user)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;So if you can change the outer function to return an &lt;code&gt;Option&lt;&#x2F;code&gt; instead, you won’t run into the above error message.
There’s more info in the Rust documentation &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;doc.rust-lang.org&#x2F;std&#x2F;option&#x2F;index.html#the-question-mark-operator-&quot;&gt;here&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;But what if the final return type of your function has to be a &lt;code&gt;Result&lt;&#x2F;code&gt;
or if you want to convey more information about the missing value to the caller?
After all, communicating the distinction between different &lt;code&gt;None&lt;&#x2F;code&gt; values can be helpful to the user of your function.&lt;&#x2F;p&gt;
&lt;p&gt;So, what if you &lt;em&gt;really&lt;&#x2F;em&gt; want your code to look like this?&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;fn&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; get_user_name&lt;&#x2F;span&gt;&lt;span&gt;()&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; -&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Result&lt;&#x2F;span&gt;&lt;span&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;String&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; String&lt;&#x2F;span&gt;&lt;span&gt;&amp;gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;    &#x2F;&#x2F; Doesn&amp;#39;t work because we return a `Result`&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    let&lt;&#x2F;span&gt;&lt;span&gt; user&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; get_user&lt;&#x2F;span&gt;&lt;span&gt;()&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;?&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;    &#x2F;&#x2F; Some more, fallible operations, here&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;    &#x2F;&#x2F; ...&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;    &#x2F;&#x2F; Return a `Result`&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;    Ok&lt;&#x2F;span&gt;&lt;span&gt;(user)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Well, that’s just a type error: &lt;code&gt;get_user()&lt;&#x2F;code&gt; returns an &lt;code&gt;Option&lt;&#x2F;code&gt;, but the outer function expects a &lt;code&gt;Result&lt;&#x2F;code&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;Our problem statement becomes easier:&lt;br &#x2F;&gt;
&lt;strong&gt;How to return a helpful error message when an &lt;code&gt;Option&lt;&#x2F;code&gt; is &lt;code&gt;None&lt;&#x2F;code&gt; in this case?&lt;&#x2F;strong&gt;&lt;&#x2F;p&gt;
&lt;p&gt;Turns out, there are multiple solutions!&lt;&#x2F;p&gt;
&lt;h2 id=&quot;solution-1-change-the-return-type&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#solution-1-change-the-return-type&quot; aria-label=&quot;Anchor link for: solution-1-change-the-return-type&quot;&gt;Solution 1: change the return type&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;p&gt;If “not having a value” is truly an error condition in your program’s logic, you should use &lt;code&gt;Result&lt;&#x2F;code&gt; instead of &lt;code&gt;Option&lt;&#x2F;code&gt;. &lt;code&gt;Option&lt;&#x2F;code&gt; is best used when the absence of a value is a normal, expected possibility, not an error state.&lt;&#x2F;p&gt;
&lt;p&gt;In our case, if you can change &lt;code&gt;get_user()&lt;&#x2F;code&gt; to return a &lt;code&gt;Result&lt;&#x2F;code&gt; instead of an &lt;code&gt;Option&lt;&#x2F;code&gt;, you can use the &lt;code&gt;?&lt;&#x2F;code&gt; operator as you intended:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;fn&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; get_user&lt;&#x2F;span&gt;&lt;span&gt;()&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; -&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Result&lt;&#x2F;span&gt;&lt;span&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;String&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; String&lt;&#x2F;span&gt;&lt;span&gt;&amp;gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;    &#x2F;&#x2F; ...&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;    Ok&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt;&amp;quot;Alice&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;to_string&lt;&#x2F;span&gt;&lt;span&gt;())&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;fn&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; get_user_name&lt;&#x2F;span&gt;&lt;span&gt;()&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; -&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Result&lt;&#x2F;span&gt;&lt;span&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;String&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; String&lt;&#x2F;span&gt;&lt;span&gt;&amp;gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    let&lt;&#x2F;span&gt;&lt;span&gt; user&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; get_user&lt;&#x2F;span&gt;&lt;span&gt;()&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;?&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;    &#x2F;&#x2F; Do something with `user`&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;    &#x2F;&#x2F; ...&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;    Ok&lt;&#x2F;span&gt;&lt;span&gt;(user)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;However, you might not be able to change &lt;code&gt;get_user()&lt;&#x2F;code&gt; to return a &lt;code&gt;Result&lt;&#x2F;code&gt; for various reasons,
for example, if it’s part of a library or if it’s used in many places
or if other callers don’t treat the absence of a user as an error.&lt;&#x2F;p&gt;
&lt;p&gt;In that case, read on!&lt;&#x2F;p&gt;
&lt;h2 id=&quot;solution-2-ok-or-else-ok-or&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#solution-2-ok-or-else-ok-or&quot; aria-label=&quot;Anchor link for: solution-2-ok-or-else-ok-or&quot;&gt;Solution 2: &lt;code&gt;ok_or_else&lt;&#x2F;code&gt; &#x2F; &lt;code&gt;ok_or&lt;&#x2F;code&gt;&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;p&gt;The initial error message, while cryptic, gave us a hint:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;use&lt;&#x2F;span&gt;&lt;span&gt; `&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span&gt;ok_or(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;...&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;?&lt;&#x2F;span&gt;&lt;span&gt;` to provide an error compatible with `&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;Result&lt;&#x2F;span&gt;&lt;span&gt;&amp;lt;(),&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Box&lt;&#x2F;span&gt;&lt;span&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;dyn&lt;&#x2F;span&gt;&lt;span&gt; std&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span&gt;error&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;Error&lt;&#x2F;span&gt;&lt;span&gt;&amp;gt;&amp;gt;`&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;The &lt;code&gt;ok_or&lt;&#x2F;code&gt; method converts an &lt;code&gt;Option&lt;&#x2F;code&gt; into a &lt;code&gt;Result&lt;&#x2F;code&gt; and allows us to specify what error should be returned when the &lt;code&gt;Option&lt;&#x2F;code&gt; is &lt;code&gt;None&lt;&#x2F;code&gt;:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;fn&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; process_user&lt;&#x2F;span&gt;&lt;span&gt;()&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; -&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Result&lt;&#x2F;span&gt;&lt;span&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;String&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; String&lt;&#x2F;span&gt;&lt;span&gt;&amp;gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;    &#x2F;&#x2F; Convert Option to Result with a descriptive error&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    let&lt;&#x2F;span&gt;&lt;span&gt; user&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; get_user&lt;&#x2F;span&gt;&lt;span&gt;()&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;ok_or&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt;&amp;quot;User not found&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;to_string&lt;&#x2F;span&gt;&lt;span&gt;())&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;?&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;    &#x2F;&#x2F; Continue processing with the unwrapped value&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;    Ok&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;format!&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt;&amp;quot;Processing user: {}&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;, user))&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;This pattern is particularly useful when working with functions that return &lt;code&gt;Result&lt;&#x2F;code&gt; but need to handle values from functions that return &lt;code&gt;Option&lt;&#x2F;code&gt;. It also chains well in sequential operations:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;fn&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; get_user_settings&lt;&#x2F;span&gt;&lt;span&gt;()&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; -&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Result&lt;&#x2F;span&gt;&lt;span&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;Settings&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; String&lt;&#x2F;span&gt;&lt;span&gt;&amp;gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    let&lt;&#x2F;span&gt;&lt;span&gt; user&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; get_user&lt;&#x2F;span&gt;&lt;span&gt;()&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;ok_or&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt;&amp;quot;User not found&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;to_string&lt;&#x2F;span&gt;&lt;span&gt;())&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;?&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    let&lt;&#x2F;span&gt;&lt;span&gt; profile&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; get_profile&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;&amp;amp;&lt;&#x2F;span&gt;&lt;span&gt;user)&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;ok_or&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt;&amp;quot;Profile not available&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;to_string&lt;&#x2F;span&gt;&lt;span&gt;())&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;?&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    let&lt;&#x2F;span&gt;&lt;span&gt; settings&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; profile&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;settings&lt;&#x2F;span&gt;&lt;span&gt;()&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;ok_or&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt;&amp;quot;Settings missing&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;to_string&lt;&#x2F;span&gt;&lt;span&gt;())&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;?&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;    Ok&lt;&#x2F;span&gt;&lt;span&gt;(settings)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;(&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;play.rust-lang.org&#x2F;?version=stable&amp;amp;mode=debug&amp;amp;edition=2021&amp;amp;gist=d7d36e61c154e0380cce1f855c1e5067&quot;&gt;Playground&lt;&#x2F;a&gt;)&lt;&#x2F;p&gt;
&lt;p&gt;For cases where creating the error value involves expensive operations or side effects, prefer &lt;code&gt;ok_or_else&lt;&#x2F;code&gt; instead. It takes a closure that’s only evaluated if the &lt;code&gt;Option&lt;&#x2F;code&gt; is &lt;code&gt;None&lt;&#x2F;code&gt;:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;fn&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; authenticate_user&lt;&#x2F;span&gt;&lt;span&gt;()&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; -&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Result&lt;&#x2F;span&gt;&lt;span&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;User&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; String&lt;&#x2F;span&gt;&lt;span&gt;&amp;gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    let&lt;&#x2F;span&gt;&lt;span&gt; user&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; get_user&lt;&#x2F;span&gt;&lt;span&gt;()&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;ok_or_else&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;||&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;        &#x2F;&#x2F; This code only runs if get_user() returns None&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;        log_auth_failure&lt;&#x2F;span&gt;&lt;span&gt;();&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;        format!&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt;&amp;quot;Authentication failed at {}&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; current_timestamp&lt;&#x2F;span&gt;&lt;span&gt;())&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    })&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;?&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;    Ok&lt;&#x2F;span&gt;&lt;span&gt;(user)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;If in doubt, use &lt;code&gt;ok_or_else&lt;&#x2F;code&gt;, because it only evaluates the closure if the &lt;code&gt;Option&lt;&#x2F;code&gt; is &lt;code&gt;None&lt;&#x2F;code&gt;, which is typically more efficient.&lt;&#x2F;p&gt;
&lt;p&gt;The name &lt;code&gt;ok_or&lt;&#x2F;code&gt; might not be immediately intuitive to everyone. I find it a bit confusing myself and needed to look it up many times. That’s because &lt;code&gt;Ok&lt;&#x2F;code&gt; is commonly associated with the &lt;code&gt;Result&lt;&#x2F;code&gt; type, not &lt;code&gt;Option&lt;&#x2F;code&gt;. There’s &lt;code&gt;Option::Some&lt;&#x2F;code&gt;, so it could have been called &lt;code&gt;some_or&lt;&#x2F;code&gt;, which was &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;rust-lang&#x2F;rust&#x2F;pull&#x2F;17469#issuecomment-56919911&quot;&gt;actually suggested in 2014&lt;&#x2F;a&gt;, but the name &lt;code&gt;ok_or&lt;&#x2F;code&gt; won out, because &lt;code&gt;ok_or(MyError)&lt;&#x2F;code&gt; reads nicely. Guess we have to live with the minor inconsistency now.&lt;&#x2F;p&gt;
&lt;p&gt;I think &lt;code&gt;ok_or&lt;&#x2F;code&gt; and &lt;code&gt;ok_or_else&lt;&#x2F;code&gt; are quick solutions to the problem, but there are alternatives that might be more readable.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;strong&gt;Side note:&lt;&#x2F;strong&gt; If you want to provide a fallback value (rather than propagate an error) when an &lt;code&gt;Option&lt;&#x2F;code&gt; is &lt;code&gt;None&lt;&#x2F;code&gt;, use &lt;code&gt;unwrap_or&lt;&#x2F;code&gt; or &lt;code&gt;unwrap_or_else&lt;&#x2F;code&gt;:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;&#x2F;&#x2F; Use a fallback value without error propagation&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;let&lt;&#x2F;span&gt;&lt;span&gt; username&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; get_user&lt;&#x2F;span&gt;&lt;span&gt;()&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;unwrap_or_else&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;||&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; get_default_username&lt;&#x2F;span&gt;&lt;span&gt;());&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;&lt;h2 id=&quot;solution-3-match&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#solution-3-match&quot; aria-label=&quot;Anchor link for: solution-3-match&quot;&gt;Solution 3: &lt;code&gt;match&lt;&#x2F;code&gt;&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;p&gt;In the past, I used to recommend people to not be clever and just use a &lt;code&gt;match&lt;&#x2F;code&gt; statement.&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;let&lt;&#x2F;span&gt;&lt;span&gt; user&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; = match&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; get_user&lt;&#x2F;span&gt;&lt;span&gt;() {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;    Some&lt;&#x2F;span&gt;&lt;span&gt;(user)&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&amp;gt;&lt;&#x2F;span&gt;&lt;span&gt; user,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;    None&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&amp;gt; return&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Err&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt;&amp;quot;No user&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;into&lt;&#x2F;span&gt;&lt;span&gt;()),&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;};&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;&lt;code&gt;match&lt;&#x2F;code&gt; works in combination with &lt;code&gt;Option&lt;&#x2F;code&gt;, because it’s just an enum and we can pattern match on it.
As long as we cover all cases, the compiler is happy. In this situation, we only have two cases: &lt;code&gt;Some&lt;&#x2F;code&gt; and &lt;code&gt;None&lt;&#x2F;code&gt;.
In the &lt;code&gt;None&lt;&#x2F;code&gt; case, we return early with an error. In the &lt;code&gt;Some&lt;&#x2F;code&gt; case, we continue with the value.
(&lt;code&gt;match&lt;&#x2F;code&gt; is an expression and the value of the last expression in the block is returned. In our case it’s &lt;code&gt;user&lt;&#x2F;code&gt; and it
gets assigned to the &lt;code&gt;user&lt;&#x2F;code&gt; variable in the outer scope.)&lt;&#x2F;p&gt;
&lt;p&gt;This is already more explicit and easier to understand for beginners.
The one issue I had when teaching this was that it looked a bit more verbose for simple cases.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;solution-4-let-else&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#solution-4-let-else&quot; aria-label=&quot;Anchor link for: solution-4-let-else&quot;&gt;Solution 4: &lt;code&gt;let-else&lt;&#x2F;code&gt;&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;p&gt;With Rust 1.65, &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;blog.rust-lang.org&#x2F;2022&#x2F;11&#x2F;03&#x2F;Rust-1.65.0.html#let-else-statements&quot;&gt;the &lt;code&gt;let-else&lt;&#x2F;code&gt; expression was stabilized&lt;&#x2F;a&gt;, so now you can write this:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;let&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Some&lt;&#x2F;span&gt;&lt;span&gt;(user)&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; get_user&lt;&#x2F;span&gt;&lt;span&gt;()&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; else&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    return&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Err&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt;&amp;quot;No user&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;into&lt;&#x2F;span&gt;&lt;span&gt;());&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;};&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;&#x2F;&#x2F; Do something with `user`&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;In my opinion, that’s the best of both worlds: it’s compact while still being easy to understand.
It’s unanimously loved by beginners and experienced Rustaceans alike.&lt;&#x2F;p&gt;
&lt;p&gt;For some explanation: if &lt;code&gt;get_user()&lt;&#x2F;code&gt; returns &lt;code&gt;Some&lt;&#x2F;code&gt;, the &lt;code&gt;let&lt;&#x2F;code&gt; statement will destructure the &lt;code&gt;Some&lt;&#x2F;code&gt; variant and assign the value to the &lt;code&gt;user&lt;&#x2F;code&gt; variable. If &lt;code&gt;get_user()&lt;&#x2F;code&gt; returns &lt;code&gt;None&lt;&#x2F;code&gt;, the &lt;code&gt;else&lt;&#x2F;code&gt; block will be executed and we return early with an error.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;strong&gt;My favorite thing about &lt;code&gt;let-else&lt;&#x2F;code&gt; is that it clearly highlights the ‘happy path’ of your code.&lt;&#x2F;strong&gt;&lt;&#x2F;p&gt;
&lt;p&gt;Unlike a &lt;code&gt;match&lt;&#x2F;code&gt; statement where you need to read both arms to understand the intended flow, &lt;code&gt;let-else&lt;&#x2F;code&gt; makes it immediately clear what the expected case is, with the &lt;code&gt;else&lt;&#x2F;code&gt; block handling the exceptional case.&lt;&#x2F;p&gt;
&lt;p&gt;This is a clear winner.
It is way more intuitive for beginners; once they understand the pattern, they use it all the time!&lt;&#x2F;p&gt;
&lt;h2 id=&quot;bonus-anyhow&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#bonus-anyhow&quot; aria-label=&quot;Anchor link for: bonus-anyhow&quot;&gt;Bonus: &lt;code&gt;anyhow&lt;&#x2F;code&gt;&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;p&gt;I wanted to add one honorable mention here.&lt;&#x2F;p&gt;
&lt;p&gt;If you’re writing an application (not a library) and you’re using the
&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;dtolnay&#x2F;anyhow&quot;&gt;&lt;code&gt;anyhow&lt;&#x2F;code&gt;&lt;&#x2F;a&gt; crate already, you can also use their &lt;code&gt;context&lt;&#x2F;code&gt;
method to handle &lt;code&gt;None&lt;&#x2F;code&gt;:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;use&lt;&#x2F;span&gt;&lt;span&gt; anyhow&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span&gt;{&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;Context&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Result&lt;&#x2F;span&gt;&lt;span&gt;};&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;fn&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; get_user_name&lt;&#x2F;span&gt;&lt;span&gt;()&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; -&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Result&lt;&#x2F;span&gt;&lt;span&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;String&lt;&#x2F;span&gt;&lt;span&gt;&amp;gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    let&lt;&#x2F;span&gt;&lt;span&gt; user&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; get_user&lt;&#x2F;span&gt;&lt;span&gt;()&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;context&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt;&amp;quot;No user&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;?&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;    &#x2F;&#x2F; Do something with `user`&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;    Ok&lt;&#x2F;span&gt;&lt;span&gt;(user)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;It’s slightly less verbose than &lt;code&gt;let-else&lt;&#x2F;code&gt;, which makes it appealing.
Just remember that &lt;code&gt;anyhow&lt;&#x2F;code&gt; is an external dependency.
It’s probably fine for applications, but you might not want to use it in a library as users of
your library can no longer match on the concrete error variant then.&lt;&#x2F;p&gt;
&lt;p&gt;That’s why I believe that &lt;code&gt;let-else&lt;&#x2F;code&gt; is the best solution for handling &lt;code&gt;None&lt;&#x2F;code&gt; in most cases.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;conclusion&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#conclusion&quot; aria-label=&quot;Anchor link for: conclusion&quot;&gt;Conclusion&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;p&gt;For most cases, I prefer this syntax:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;let&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Some&lt;&#x2F;span&gt;&lt;span&gt;(value)&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; some_function&lt;&#x2F;span&gt;&lt;span&gt;()&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; else&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    return&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Err&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt;&amp;quot;Descriptive error message&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;into&lt;&#x2F;span&gt;&lt;span&gt;());&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;};&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;To me, &lt;code&gt;let-else&lt;&#x2F;code&gt; is the best solution for handling &lt;code&gt;None&lt;&#x2F;code&gt; because:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;It’s part of the standard library.&lt;&#x2F;li&gt;
&lt;li&gt;It works for both libraries and applications.&lt;&#x2F;li&gt;
&lt;li&gt;It’s easy to understand for beginners.&lt;&#x2F;li&gt;
&lt;li&gt;It’s reasonably compact.&lt;&#x2F;li&gt;
&lt;li&gt;It allows for more complex error handling logic in the &lt;code&gt;else&lt;&#x2F;code&gt; block if needed.&lt;&#x2F;li&gt;
&lt;li&gt;Learning the mechanics behind it is helpful in other places in Rust.&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;I hope this helps more people handle &lt;code&gt;Option&lt;&#x2F;code&gt; in a more robust way.
If it helps a single person avoid one &lt;code&gt;unwrap&lt;&#x2F;code&gt;, it was already worth it.&lt;&#x2F;p&gt;
&lt;section class=&quot;footnotes&quot;&gt;
&lt;ol class=&quot;footnotes-list&quot;&gt;
&lt;li id=&quot;fn-2&quot;&gt;
&lt;p&gt;Sometimes, &lt;code&gt;unwrap()&lt;&#x2F;code&gt; can make code more readable by reducing noise, especially when the success case is overwhelmingly likely.
It’s okay to use &lt;code&gt;unwrap()&lt;&#x2F;code&gt; when you can prove that a failure is impossible or when a panic is actually the desired behavior for failures. Andrew Gallant &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;blog.burntsushi.net&#x2F;unwrap&#x2F;&quot;&gt;wrote an article on this&lt;&#x2F;a&gt; where he goes into more detail. &lt;a href=&quot;#fr-2-1&quot;&gt;↩&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;&#x2F;section&gt;
</description>
      </item>
      <item>
          <title>Rust vs C++: A Real-World Perspective</title>
          <pubDate>Wed, 14 Aug 2024 00:00:00 +0000</pubDate>
          <author>Matthias Endler</author>
          <link>https://corrode.dev/blog/cpp-rust-interop/</link>
          <guid>https://corrode.dev/blog/cpp-rust-interop/</guid>
          <description xml:base="https://corrode.dev/blog/cpp-rust-interop/">&lt;p&gt;The real-world implications of choosing a programming language over another are often nuanced.
This is especially true for the ongoing debate between Rust and C++.
It’s easy to get lost in theoretical arguments about safety, performance, and language features,
but what does it really boil down to when rubber hits the road?&lt;&#x2F;p&gt;
&lt;p&gt;I recently sat down with &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;tylerjw.dev&quot;&gt;Tyler Weaver&lt;&#x2F;a&gt;,
Co-Organizer of the &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.meetup.com&#x2F;boulder-rust-meetup&#x2F;&quot;&gt;Boulder Rust Meetup&lt;&#x2F;a&gt;
and software engineer with a decade of C++ experience and several years of Rust under his belt. He shared some great insights on the practical aspects of working with both languages in production, which I thought would be valuable to share.&lt;&#x2F;p&gt;
&lt;p&gt;While Tyler’s perspective is based on his personal experience, I believe his insights are quite valuable for anyone looking for hands-on experiences with both languages.
The quotes below are taken verbatim from our conversation.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;rust-is-a-force-multiplier&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#rust-is-a-force-multiplier&quot; aria-label=&quot;Anchor link for: rust-is-a-force-multiplier&quot;&gt;Rust is a Force Multiplier&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;p&gt;One of Tyler’s most striking observations is that “Rust is a force multiplier.” In C++ projects, developers often find themselves barely having time to get things working, let alone optimizing or improving their code. Rust, on the other hand, handles many low-level details by design, allowing developers to focus on higher-level concerns instead.
As Tyler puts it, you can “spend more time on useful things because Rust handles the details for you.”&lt;&#x2F;p&gt;
&lt;p&gt;This effect extends to code reviews as well. Tyler estimates that “code reviews take half the time” in Rust compared to C++. This efficiency gain is not just about saving time; it allows for more thorough reviews and potentially catches more issues before they make it into production.&lt;&#x2F;p&gt;
&lt;p&gt;This aligns well with an &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;youtu.be&#x2F;6mZRWFQRvmw?t=27012&quot;&gt;observation by Google&lt;&#x2F;a&gt; on re-writing C++ into Rust:&lt;&#x2F;p&gt;
&lt;blockquote&gt;
&lt;p&gt;In every case, we’ve seen a decrease by more than 2x in the amount of effort required to both
build the services written in Rust, as well as maintain and update those services. […]
C++ is very expensive for us to maintain.&lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
&lt;h2 id=&quot;painless-refactoring&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#painless-refactoring&quot; aria-label=&quot;Anchor link for: painless-refactoring&quot;&gt;Painless Refactoring&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;p&gt;Perhaps one of the areas where Rust shines the most is during large-scale refactoring.
Tyler emphasizes that “Rust makes refactoring painless” and allows developers to “trust your refactors.” This “worry-free refactoring” is a stark contrast to C++, where making significant changes can be risky and time-consuming.&lt;&#x2F;p&gt;
&lt;p&gt;“In C++, removing things is so expensive,” both in terms of development time and the potential for introducing bugs. Rust’s ownership system and compiler checks make it much easier to make sweeping changes with confidence. This capability is particularly valuable for large-scale projects where regular refactoring is essential for maintaining code quality and adapting to changing requirements.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=21980890&quot;&gt;Mozilla twice attempted to parallelize Firefox’s CSS layout engine in C++&lt;&#x2F;a&gt;, but abandoned both efforts.
Eventually, they succeeded on the third attempt using Rust in the Servo project, which was later integrated into Firefox as part of &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;hacks.mozilla.org&#x2F;2017&#x2F;08&#x2F;inside-a-super-fast-css-engine-quantum-css-aka-stylo&#x2F;&quot;&gt;Project Quantum&lt;&#x2F;a&gt;.
The team credited Rust’s safety guarantees as the reason why they were able to be successful on the third attempt. Here’s the section from the &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.youtube.com&#x2F;watch?v=Y6SSTRr2mFU&quot;&gt;talk&lt;&#x2F;a&gt; by Josh Matthews from the Servo team.&lt;&#x2F;p&gt;
&lt;p&gt;Jeremy Soller from System76 recently &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;corrode.dev&#x2F;podcast&#x2F;s02e07-system76&#x2F;?t=1%3A13%3A18&quot;&gt;shared a similar sentiment in our Rust in Production podcast&lt;&#x2F;a&gt;:&lt;&#x2F;p&gt;
&lt;blockquote&gt;
&lt;p&gt;Rust [has] capability [of] doing extremely, extremely concurrent things safely. There was no way to write this kind of code in C or C++ without considerable time planning beforehand.&lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
&lt;h2 id=&quot;the-cost-of-complexity&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#the-cost-of-complexity&quot; aria-label=&quot;Anchor link for: the-cost-of-complexity&quot;&gt;The Cost of Complexity&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;p&gt;Tyler points out that “accidental complexity is quite high in C++.” This complexity often manifests in subtle ways that can accumulate over time, making codebases increasingly difficult to maintain.
In our conversation, Tyler mentioned that there is a lot of upfront knowledge required to be productive in C++.
One has to read a lot of books and watch talks to become an expert because a lot of the best practices are passed on
as tribal knowledge and there is a lot of historical baggage in C++.&lt;&#x2F;p&gt;
&lt;p&gt;In contrast, Rust’s design encourages simplicity and clarity from the start, allowing developers to “focus on the right things.”&lt;&#x2F;p&gt;
&lt;p&gt;Tyler emphasizes that “none of our software projects are as simple as they could be.” Rust’s approach to memory management and its emphasis on explicit handling of side effects can lead to simpler, more maintainable code structures.&lt;&#x2F;p&gt;
&lt;p&gt;If you are curious to learn more about maintaining large C++ codebases and migrating to Rust, listen to &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;corrode.dev&#x2F;podcast&#x2F;s02e03-thunderbird&quot;&gt;this interview with Brendan Abolivier from Thunderbird&lt;&#x2F;a&gt; from our “Rust in Production” podcast series.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;tooling&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#tooling&quot; aria-label=&quot;Anchor link for: tooling&quot;&gt;Tooling&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;p&gt;Better tooling leads to better projects, and Rust has a significant edge in this area. From cargo, Rust’s package manager and build tool, to the language server protocol implementation, Rust’s tooling ecosystem is modern and integrated. This cohesive tooling environment contributes to more efficient development workflows and higher-quality output.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;acknowledging-rust-s-current-limitations&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#acknowledging-rust-s-current-limitations&quot; aria-label=&quot;Anchor link for: acknowledging-rust-s-current-limitations&quot;&gt;Acknowledging Rust’s Current Limitations&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;p&gt;While Tyler’s perspective paints a very positive picture of Rust, it’s important to address some common criticisms of the language:&lt;&#x2F;p&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Learning Curve&lt;&#x2F;strong&gt;: Rust is known for having a steeper learning curve than C++, particularly for developers accustomed to more traditional programming paradigms. The borrow checker, while powerful, can be frustrating for newcomers.
However, according to Google’s experience, more than 2&#x2F;3 of respondents are confident in contributing to a Rust codebase within two months or less when learning Rust. Further, a third of respondents become as productive using Rust as other languages in two months or less. Within four months, that number increased to over 50%.
Read more about the learning curve in &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;corrode.dev&#x2F;blog&#x2F;why-rust&#x2F;&quot;&gt;Why Rust&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Ecosystem Maturity&lt;&#x2F;strong&gt;: Rust’s ecosystem is still not as mature yet as C++’s in some domains. Certain specialized libraries or frameworks may not be available or as feature-complete in Rust.&lt;&#x2F;p&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Industry Adoption&lt;&#x2F;strong&gt;: Despite growing interest, Rust has not yet achieved the same level of industry-wide adoption as C++, which may be a consideration for some projects or companies. C++ is still dominant in domains like game development, high-performance computing, and embedded systems.&lt;&#x2F;p&gt;
&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;h2 id=&quot;c-and-rust-interop&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#c-and-rust-interop&quot; aria-label=&quot;Anchor link for: c-and-rust-interop&quot;&gt;C++ and Rust Interop&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;p&gt;Recognizing that a complete switch from C++ to Rust is not always feasible or desirable, Tyler suggests that “dumb interop is the best strategy for C++ and Rust to work together.” This approach allows teams to gradually introduce Rust into existing C++ codebases, leveraging the strengths of both languages. He mentioned, that while people often raise concerns about C++&#x2F;Rust interop, it’s rarely an issue in practice.&lt;&#x2F;p&gt;
&lt;p&gt;Tyler wrote a series of blog posts on &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;tylerjw.dev&#x2F;posts&#x2F;rust-cpp-interop&#x2F;&quot;&gt;Rust and C++ interop&lt;&#x2F;a&gt; that go into great detail about integrating Rust into C++ projects, which covers FFI bindings, CMake (a build system generator for C++ projects), Cxx (a code generation tool), Conan (a C++ package manager), and more.&lt;&#x2F;p&gt;
&lt;p&gt;For an up-to-date, step-by-step guide on the tooling and strategies involved in this process, see &lt;a href=&quot;&#x2F;blog&#x2F;rust-ffi-incremental-migration&#x2F;&quot;&gt;How to Introduce Rust into a C++ Codebase&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;It is recommended to start with the most safety-critical or unreliable parts of your codebase:&lt;&#x2F;p&gt;
&lt;blockquote&gt;
&lt;p&gt;What you have to do is think about how important security is at each level of the stack and how to address it in small incremental ways. - &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;corrode.dev&#x2F;podcast&#x2F;s02e07-system76&#x2F;?t=47%3A52&quot;&gt;Jeremy Soller in the Rust in Production podcast&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
&lt;h2 id=&quot;summary&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#summary&quot; aria-label=&quot;Anchor link for: summary&quot;&gt;Summary&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;p&gt;Here are some key takeaways from Tyler’s experiences with Rust and C++:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;You have more time to focus on the big picture when using Rust.&lt;&#x2F;li&gt;
&lt;li&gt;Refactoring is easier and less risky in Rust.&lt;&#x2F;li&gt;
&lt;li&gt;Removing things is hard in C++. It’s easier in Rust thanks to the borrow checker.&lt;&#x2F;li&gt;
&lt;li&gt;Rust doesn’t have the historical baggage of C++. It comes with sane defaults.&lt;&#x2F;li&gt;
&lt;li&gt;Rust’s integrated tooling contributes to more efficient development workflows.&lt;&#x2F;li&gt;
&lt;li&gt;Interop between Rust and C++ is best done by keeping interfaces simple.&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;As Tyler’s experiences illustrate, the benefits of Rust often become most apparent in the “day two operations” of software development – in code reviews, refactoring, and managing complexity.&lt;&#x2F;p&gt;
&lt;div class=&quot;info&quot;&gt;
  
  &lt;div class=&quot;info-header&quot;&gt;
    
      &lt;span class=&quot;icon icon-crab&quot;&gt;&lt;&#x2F;span&gt;
    
    &lt;h4&gt;&lt;p&gt;Make the most of Rust&lt;&#x2F;p&gt;
&lt;&#x2F;h4&gt;
  &lt;&#x2F;div&gt;
  
  &lt;p&gt;Is your company considering to migrate from C++ to Rust?
I offer consulting services to get you up to speed with your Rust projects, from training your team to code reviews and architecture consulting.
Check out my &lt;a href=&quot;&#x2F;services&quot;&gt;services page&lt;&#x2F;a&gt; to learn more.&lt;&#x2F;p&gt;

&lt;&#x2F;div&gt;
&lt;h2 id=&quot;recommended-reading&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#recommended-reading&quot; aria-label=&quot;Anchor link for: recommended-reading&quot;&gt;Recommended Reading&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;p&gt;For those interested in diving deeper into the topics discussed in this article, here are a few book recommendations:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.manning.com&#x2F;books&#x2F;grokking-simplicity&quot;&gt;“Grokking Simplicity”&lt;&#x2F;a&gt; by Eric Normand. Published by Manning.&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.oreilly.com&#x2F;library&#x2F;view&#x2F;programming-rust-2nd&#x2F;9781492052586&#x2F;&quot;&gt;“Programming Rust”&lt;&#x2F;a&gt; by Jim Blandy and Jason Orendorff. Published by O’Reilly.&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.oreilly.com&#x2F;library&#x2F;view&#x2F;effective-modern-c&#x2F;9781491908419&#x2F;&quot;&gt;“Effective Modern C++”&lt;&#x2F;a&gt; by Scott Meyers. Published by O’Reilly.&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;These three books teach you how to write clean, maintainable code no matter the language.&lt;&#x2F;p&gt;
&lt;p&gt;If you like to learn more about Tyler’s work, check out his &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;tylerjw.dev&#x2F;&quot;&gt;blog&lt;&#x2F;a&gt; and GitHub &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;tylerjw&quot;&gt;profile&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
</description>
      </item>
      <item>
          <title>Season 2 - Finale</title>
          <pubDate>Thu, 08 Aug 2024 00:00:00 +0000</pubDate>
          <author>Matthias Endler</author>
          <link>https://corrode.dev/podcast/s02e08-season-finale/</link>
          <guid>https://corrode.dev/podcast/s02e08-season-finale/</guid>
          <description xml:base="https://corrode.dev/podcast/s02e08-season-finale/">&lt;div&gt;&lt;script id=&quot;letscast-player-7ae4f95b&quot; src=&quot;https:&#x2F;&#x2F;letscast.fm&#x2F;podcasts&#x2F;rust-in-production-82281512&#x2F;episodes&#x2F;rust-in-production-ep-15-season-finale&#x2F;player.js?size=s&quot;&gt;&lt;&#x2F;script&gt;&lt;&#x2F;div&gt;
As we approach the finale of our second season, it&#x27;s time for another recap.
&lt;p&gt;Could we shed some light on the current state of Rust’s usage in the industry?
What has changed in our perception of Rust in production since our last season?&lt;&#x2F;p&gt;
&lt;p&gt;While more companies started to embrace Rust, some of the magic of Rust’s early days is gone.
I expect more ripple effects as the community clashes with the industry’s demands.&lt;&#x2F;p&gt;
&lt;p&gt;This episode takes on a more somber tone, as we peer into the massive tech debt we have accumulated as an industry.
And in the dark: a faint glow, a narrow golden path that points us towards a more hopeful future.&lt;&#x2F;p&gt;</description>
      </item>
      <item>
          <title>Don&#x27;t Use Preludes And Globs</title>
          <pubDate>Mon, 29 Jul 2024 00:00:00 +0000</pubDate>
          <author>Matthias Endler</author>
          <link>https://corrode.dev/blog/dont-use-preludes-and-globs/</link>
          <guid>https://corrode.dev/blog/dont-use-preludes-and-globs/</guid>
          <description xml:base="https://corrode.dev/blog/dont-use-preludes-and-globs/">&lt;p&gt;Have you ever wondered why you don’t have to import &lt;code&gt;std::result::Result&lt;&#x2F;code&gt; before you can use it?&lt;&#x2F;p&gt;
&lt;p&gt;The reason is Rust’s &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;doc.rust-lang.org&#x2F;std&#x2F;prelude&#x2F;index.html&quot;&gt;prelude&lt;&#x2F;a&gt;, which re-exports a bunch of types that automatically get added to your program’s namespace.
A more correct definition is: &lt;em&gt;Preludes are collections of names automatically brought into scope in every module of a crate.&lt;&#x2F;em&gt;&lt;&#x2F;p&gt;
&lt;p&gt;In fact, there are multiple preludes like
&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;doc.rust-lang.org&#x2F;std&#x2F;prelude&#x2F;v1&#x2F;index.html&quot;&gt;&lt;code&gt;std::prelude::v1&lt;&#x2F;code&gt;&lt;&#x2F;a&gt;, &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;doc.rust-lang.org&#x2F;std&#x2F;prelude&#x2F;rust_2015&#x2F;index.html&quot;&gt;&lt;code&gt;std::prelude::rust_2015&lt;&#x2F;code&gt;&lt;&#x2F;a&gt;, and &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;doc.rust-lang.org&#x2F;nightly&#x2F;std&#x2F;prelude&#x2F;rust_2024&#x2F;index.html&quot;&gt;&lt;code&gt;std::prelude::rust_2024&lt;&#x2F;code&gt;&lt;&#x2F;a&gt;, and more in the future.&lt;&#x2F;p&gt;
&lt;p&gt;It would be jarring to import those basic types over and over again so I’d say it’s a win to have a prelude for the standard library.&lt;&#x2F;p&gt;
&lt;p&gt;Maybe that’s the reason why popular libraries started to provide their own preludes: &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;docs.rs&#x2F;rayon&#x2F;latest&#x2F;rayon&#x2F;prelude&#x2F;index.html&quot;&gt;Rayon has one&lt;&#x2F;a&gt; and so do
&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;docs.rs&#x2F;pyo3&#x2F;latest&#x2F;pyo3&#x2F;prelude&#x2F;index.html&quot;&gt;pyo3&lt;&#x2F;a&gt; and &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;docs.rs&#x2F;bevy&#x2F;latest&#x2F;bevy&#x2F;prelude&#x2F;index.html&quot;&gt;bevy&lt;&#x2F;a&gt; and
&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;docs.rs&#x2F;ratatui&#x2F;latest&#x2F;ratatui&#x2F;prelude&#x2F;index.html&quot;&gt;ratatui&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;Some people consider preludes and glob imports&lt;sup class=&quot;footnote-reference&quot; id=&quot;fr-1-1&quot;&gt;&lt;a href=&quot;#fn-1&quot;&gt;1&lt;&#x2F;a&gt;&lt;&#x2F;sup&gt; to be antipatterns – I’m one of them. Let me explain why.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;i-don-t-like-preludes&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#i-don-t-like-preludes&quot; aria-label=&quot;Anchor link for: i-don-t-like-preludes&quot;&gt;I don’t like preludes&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;p&gt;Preludes help beginners start quickly and with zero boilerplate, but they also prevent users from understanding the full picture of a crate.
For larger projects, preludes can cause namespace pollution and naming conflicts.&lt;&#x2F;p&gt;
&lt;p&gt;I have a hard time reviewing code which uses preludes: looking up a definition might not work in my code review tool, and I’d have to manually track down where types came from.&lt;&#x2F;p&gt;
&lt;p&gt;Explicit imports bring clarity.&lt;&#x2F;p&gt;
&lt;p&gt;Speaking of which! A good compromise between convenience and clarity is to import whole modules instead of individual items, such as &lt;code&gt;use std::fmt&lt;&#x2F;code&gt;. Then you can say &lt;code&gt;fmt::Debug&lt;&#x2F;code&gt; instead of &lt;code&gt;std::fmt::Debug&lt;&#x2F;code&gt;. It’s a little easier on the eyes, but still provides clarity.&lt;&#x2F;p&gt;
&lt;p&gt;Unless you write a highly critical framework which uses well-established types, which are &lt;em&gt;absolutely positively always&lt;&#x2F;em&gt; mandatory in every (or at least most) interaction with your library, don’t add a prelude. Even then, make sure that prelude carries its own weight. &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;tokio-rs&#x2F;tokio&#x2F;issues&#x2F;3257&quot;&gt;Tokio removed their prelude because that wasn’t the case&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;An explicit import might not be that bad. In fact, it might even clear things up for your users, because it’s easier to see where imports come from.&lt;&#x2F;p&gt;
&lt;p&gt;If you’re worried about ergonomics, why not re-export common types in root? Then they can get imported with &lt;code&gt;use mycrate::SomeType;&lt;&#x2F;code&gt; instead of &lt;code&gt;use mycrate::mymodule::SomeType;&lt;&#x2F;code&gt;.&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;&#x2F;&#x2F; Re-export a type in your lib.rs&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;pub use&lt;&#x2F;span&gt;&lt;span&gt; mymodule&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;SomeType&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;On the same note, avoid glob imports (like &lt;code&gt;use prelude::*&lt;&#x2F;code&gt;
or &lt;code&gt;use mycrate::mymodule::*&lt;&#x2F;code&gt;).
The reasons are the same: they hide dependencies and make it harder to grep for usages of a type or function.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;common-arguments-for-preludes&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#common-arguments-for-preludes&quot; aria-label=&quot;Anchor link for: common-arguments-for-preludes&quot;&gt;Common Arguments for Preludes&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;p&gt;Let’s address some common arguments in favor of preludes and glob imports
and see if there’s a better way to achieve the same goal.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;preludes-in-examples&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#preludes-in-examples&quot; aria-label=&quot;Anchor link for: preludes-in-examples&quot;&gt;Preludes in examples&lt;&#x2F;a&gt;&lt;&#x2F;h3&gt;
&lt;p&gt;Some people like to use preludes in their documentation examples.&lt;&#x2F;p&gt;
&lt;p&gt;This can be sweet when you quickly want to show how to use your library without too much boilerplate. But at what cost?&lt;&#x2F;p&gt;
&lt;p&gt;Users &lt;em&gt;can and will&lt;&#x2F;em&gt; start to copy-paste that prelude into their code, at which point you’ll have to support it. It’s convenient in the beginning, but can result in a maintenance burden in the long run.&lt;&#x2F;p&gt;
&lt;p&gt;One way to avoid that is to hide code lines for imports in your documentation examples. With that, examples are still easy to read, while users can’t copy-paste the imports:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;&#x2F;&#x2F;! # Examples&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;&#x2F;&#x2F;!&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;&#x2F;&#x2F;! ```&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;&#x2F;&#x2F;! # use mycrate::SomeType;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;&#x2F;&#x2F;! # fn main() {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;&#x2F;&#x2F;! let t = SomeType::new(); &lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;&#x2F;&#x2F;! # }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;&#x2F;&#x2F;! ```&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;This will render as:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;let&lt;&#x2F;span&gt;&lt;span&gt; t&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; SomeType&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;new&lt;&#x2F;span&gt;&lt;span&gt;();&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;&lt;div class=&quot;info&quot;&gt;
  
  &lt;div class=&quot;info-header&quot;&gt;
    
      &lt;span class=&quot;icon icon-warning&quot;&gt;&lt;&#x2F;span&gt;
    
    &lt;h4&gt;&lt;p&gt;Caution When Hiding Code in Examples&lt;&#x2F;p&gt;
&lt;&#x2F;h4&gt;
  &lt;&#x2F;div&gt;
  
  &lt;p&gt;Be careful with this approach and don’t overdo it. Try to keep your examples simple and don’t hide too much code because it can be a frustrating experience for your users if they copy-paste your examples and they don’t work.&lt;&#x2F;p&gt;

&lt;&#x2F;div&gt;
&lt;p&gt;To address the root cause: If you feel the urge to add a prelude because your crate requires importing many modules to be usable, consider whether your public API is too large. Try reducing the number of modules and types by refactoring your public API. This way, you won’t need to hide imports in the first place.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;reducing-boilerplate&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#reducing-boilerplate&quot; aria-label=&quot;Anchor link for: reducing-boilerplate&quot;&gt;Reducing boilerplate&lt;&#x2F;a&gt;&lt;&#x2F;h3&gt;
&lt;p&gt;Another common argument for preludes is that they reduce friction when importing types.&lt;&#x2F;p&gt;
&lt;p&gt;I don’t think that’s true anymore. Editor support for Rust has made great strides in the last years. Nowadays, your editor will just auto-import the type for you. (Largely thanks to &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;rust-analyzer.github.io&#x2F;&quot;&gt;Rust Analyzer&lt;&#x2F;a&gt; and &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.jetbrains.com&#x2F;rust&#x2F;&quot;&gt;Rust Rover&lt;&#x2F;a&gt;). Problem solved! &lt;sup class=&quot;footnote-reference&quot; id=&quot;fr-editor-1&quot;&gt;&lt;a href=&quot;#fn-editor&quot;&gt;2&lt;&#x2F;a&gt;&lt;&#x2F;sup&gt;&lt;&#x2F;p&gt;
&lt;h3 id=&quot;trait-only-preludes&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#trait-only-preludes&quot; aria-label=&quot;Anchor link for: trait-only-preludes&quot;&gt;Trait-only preludes&lt;&#x2F;a&gt;&lt;&#x2F;h3&gt;
&lt;p&gt;Preludes which only bring traits into scope might be acceptable.
This trick is sometimes used in combination with extension traits, which add extra functionality to common types. &lt;code&gt;rayon&lt;&#x2F;code&gt; does that, for example, and it’s quite magical if you can suddenly parallelize an iterator by just swapping &lt;code&gt;iter&lt;&#x2F;code&gt; with &lt;code&gt;par_iter&lt;&#x2F;code&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;From their documentation:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;use&lt;&#x2F;span&gt;&lt;span&gt; rayon&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span&gt;prelude&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::*&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;fn&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; sum_of_squares&lt;&#x2F;span&gt;&lt;span&gt;(input&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;: &amp;amp;&lt;&#x2F;span&gt;&lt;span&gt;[&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;i32&lt;&#x2F;span&gt;&lt;span&gt;])&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; -&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; i32&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    input&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;par_iter&lt;&#x2F;span&gt;&lt;span&gt;()&lt;&#x2F;span&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt; &#x2F;&#x2F; &amp;lt;-- just change that!&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;         .&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;map&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;|&amp;amp;&lt;&#x2F;span&gt;&lt;span&gt;i&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;|&lt;&#x2F;span&gt;&lt;span&gt; i&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; *&lt;&#x2F;span&gt;&lt;span&gt; i)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;         .&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;sum&lt;&#x2F;span&gt;&lt;span&gt;()&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;I think that’s a solid use case for a prelude, but I’ve never had such a clear-cut case in my own libraries.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;flexibility-for-library-authors&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#flexibility-for-library-authors&quot; aria-label=&quot;Anchor link for: flexibility-for-library-authors&quot;&gt;Flexibility For Library Authors&lt;&#x2F;a&gt;&lt;&#x2F;h3&gt;
&lt;p&gt;Preludes can let library authors refactor their code without causing unnecessary churn for users:
If you often reorganize your internal structure, a prelude can provide a stable public API for common types.
The Bevy game engine uses this pattern, for example.&lt;&#x2F;p&gt;
&lt;p&gt;But hold on! This doesn’t mean the internal logic stays the same, and a prelude doesn’t guarantee API stability either.
These hidden changes might cause subtle bugs (e.g., when the prelude contains extension traits) which are hard to pin down.&lt;&#x2F;p&gt;
&lt;p&gt;Ask yourself: why does my public API change so much? There seems to be a deeper-rooted problem here.
For example, you might have leaked internal details into your public API, which you now want to change.&lt;&#x2F;p&gt;
&lt;p&gt;One way to provide stability without a prelude is to embrace semantic versioning. Before 1.0, you’re free to change your API frequently, with users expecting some churn. Once you’re happy with the API, switch to 1.0 and promise to maintain backwards compatibility. This approach gives you the flexibility of early prototyping paired with the stability guarantees of more mature libraries.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;sane-defaults-out-of-the-box&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#sane-defaults-out-of-the-box&quot; aria-label=&quot;Anchor link for: sane-defaults-out-of-the-box&quot;&gt;Sane Defaults Out of the Box&lt;&#x2F;a&gt;&lt;&#x2F;h3&gt;
&lt;p&gt;For complex libraries, a well-designed prelude can improve clarity by curating important types. This seems appealing in security-sensitive domains to prevent misuse of incorrect types.&lt;&#x2F;p&gt;
&lt;p&gt;For example, a crypto library might provide a prelude with only the most secure algorithms. This way, users are guided towards secure defaults without needing to understand the intricacies of each algorithm.&lt;&#x2F;p&gt;
&lt;p&gt;That’s a valid argument, but I’d argue that it’s a slippery slope. First off, switching an algorithm is still a breaking change and it might still require changes in user code. Second, a prelude is no substitute for good documentation, examples, and a “Getting Started” guide.&lt;&#x2F;p&gt;
&lt;p&gt;Consider using Rust’s &lt;code&gt;#[deprecated]&lt;&#x2F;code&gt; attribute to phase out old behavior. This way, users get time to adapt to the new API.
Leverage Rust’s type system: Use newtypes, &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;predr.ag&#x2F;blog&#x2F;definitive-guide-to-sealed-traits-in-rust&#x2F;&quot;&gt;sealed traits&lt;&#x2F;a&gt;, and visibility modifiers (like &lt;code&gt;pub(crate)&lt;&#x2F;code&gt;) to guide users towards correct usage without relying on a prelude.&lt;&#x2F;p&gt;
&lt;p&gt;My rule of thumb here is to avoid hiding complexity behind a prelude and err on the side of explicitness.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;common-arguments-for-glob-imports&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#common-arguments-for-glob-imports&quot; aria-label=&quot;Anchor link for: common-arguments-for-glob-imports&quot;&gt;Common Arguments for Glob Imports&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;p&gt;Now that we’ve covered preludes, let’s look at some common arguments for why people use glob imports
and why you should be careful.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;preludes-are-convenient-for-beginners&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#preludes-are-convenient-for-beginners&quot; aria-label=&quot;Anchor link for: preludes-are-convenient-for-beginners&quot;&gt;Preludes are convenient for beginners&lt;&#x2F;a&gt;&lt;&#x2F;h3&gt;
&lt;p&gt;Some people argue that preludes are beginner-friendly.
The argument goes that beginners don’t have to worry about importing types and can focus on learning the core concepts of a library.&lt;&#x2F;p&gt;
&lt;p&gt;As we will see, this can backfire quickly.&lt;&#x2F;p&gt;
&lt;p&gt;Here’s the catch: when you use glob imports, you’re opening yourself up to potential build breaks from minor version updates.
Adding new public items is considered a minor change according to &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;semver.org&quot;&gt;semantic versioning&lt;&#x2F;a&gt; rules. That means when a crate bumps its version from, say, 1.2.0 to 1.3.0, it’s allowed to add new public items without breaking backwards compatibility.&lt;&#x2F;p&gt;
&lt;p&gt;Now, picture this scenario: You’re using a crate with a glob import, bringing all its public items into scope. You update the crate to the latest minor version, and suddenly your code doesn’t compile anymore. Ouch.&lt;&#x2F;p&gt;
&lt;p&gt;Well, that new minor version might have added a new public item that conflicts with a name in your code.&lt;&#x2F;p&gt;
&lt;p&gt;Here’s a quick example to illustrate:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;&#x2F;&#x2F; In your code you update some_crate from 1.2.0 to 1.3.0&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;&#x2F;&#x2F; In 1.3.0, some_crate added a new public item called Ferris.&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;use&lt;&#x2F;span&gt;&lt;span&gt; some_crate&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::*&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;&#x2F;&#x2F; In your own code, you have a struct called Ferris&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;&#x2F;&#x2F; Now you have a naming conflict, and your code won&amp;#39;t compile!&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;pub struct&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Ferris&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;The crate author didn’t break any promises – adding new public items is allowed in minor versions. But because of the glob import, what should have been a harmless update turned into a breaking change for your codebase and a minor headache for you.&lt;&#x2F;p&gt;
&lt;p&gt;Explicit imports protect you from these unexpected conflicts and make your code more resilient to changes in your dependencies.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;glob-imports-in-tests&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#glob-imports-in-tests&quot; aria-label=&quot;Anchor link for: glob-imports-in-tests&quot;&gt;Glob imports in tests&lt;&#x2F;a&gt;&lt;&#x2F;h3&gt;
&lt;p&gt;It’s common to see &lt;code&gt;use super::*;&lt;&#x2F;code&gt; in tests to bring all functions from the parent module into scope. This can be a helpful mechanism to reduce boilerplate.
That’s the only exception I can think of where glob imports are acceptable.&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;fn&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; foo&lt;&#x2F;span&gt;&lt;span&gt;()&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; -&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; i32&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt;    42&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;mod&lt;&#x2F;span&gt;&lt;span&gt; tests {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    use&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;font-style: italic;&quot;&gt; super&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::*&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    #[test]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    fn&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; test_something&lt;&#x2F;span&gt;&lt;span&gt;() {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;        assert_eq!&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;foo&lt;&#x2F;span&gt;&lt;span&gt;(),&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt; 42&lt;&#x2F;span&gt;&lt;span&gt;);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;&lt;h2 id=&quot;conclusion&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#conclusion&quot; aria-label=&quot;Anchor link for: conclusion&quot;&gt;Conclusion&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;p&gt;In your own code, avoid preludes and, by extension, glob imports.&lt;&#x2F;p&gt;
&lt;p&gt;Here are the main disadvantages:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;Makes it harder to know where types and functions come from&lt;&#x2F;li&gt;
&lt;li&gt;Can lead to naming conflicts, especially in larger codebases and when using multiple crates&lt;&#x2F;li&gt;
&lt;li&gt;Complicates security audits because it’s hard to see where code came from&lt;&#x2F;li&gt;
&lt;li&gt;May hide module hierarchy and structure, which is useful if you want to learn how a crate is designed&lt;&#x2F;li&gt;
&lt;li&gt;Can make IDE name resolution less reliable: if you have a name conflict, the IDE might not know which one you mean or might not be able to find the definition&lt;&#x2F;li&gt;
&lt;li&gt;Hides imports in documentation examples, making it harder to understand&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;As you can see, the list of downsides is long. The only upside is that it saves a few keystrokes when writing code, which isn’t worth it in the long run.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;strong&gt;Pro tips:&lt;&#x2F;strong&gt;&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;Enable the &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;rust-lang.github.io&#x2F;rust-clippy&#x2F;master&#x2F;index.html#&#x2F;wildcard_imports&quot;&gt;clippy lint for wildcard imports&lt;&#x2F;a&gt; to catch glob imports in your code.&lt;&#x2F;li&gt;
&lt;li&gt;If you really want to create a prelude, at least use it for traits and macros only, not for types. Extending behavior of existing types (like adding a &lt;code&gt;par_iter&lt;&#x2F;code&gt; method to iterators with Rayon) is an acceptable use case for preludes if used in moderation. To avoid naming conflicts, consider using a unique prefix for extension traits like &lt;code&gt;CrateNameHashmapExt&lt;&#x2F;code&gt; instead of &lt;code&gt;HashMapExt&lt;&#x2F;code&gt;.&lt;&#x2F;li&gt;
&lt;li&gt;If you depend on a crate which has a prelude, consider not using it and instead importing the types you need explicitly. This way, you can avoid conflicts down the road and make it easier to see where a type comes from.&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;section class=&quot;footnotes&quot;&gt;
&lt;ol class=&quot;footnotes-list&quot;&gt;
&lt;li id=&quot;fn-1&quot;&gt;
&lt;p&gt;A glob import (also called a wildcard import) is an import that brings all items of a module into scope. For example, &lt;code&gt;use std::collections::HashMap;&lt;&#x2F;code&gt; vs &lt;code&gt;use std::collections::*;&lt;&#x2F;code&gt;. &lt;a href=&quot;#fr-1-1&quot;&gt;↩&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;&#x2F;li&gt;
&lt;li id=&quot;fn-editor&quot;&gt;
&lt;p&gt;I should mention that many modern editors can often show you the fully qualified path of a type, even when it’s imported via a prelude. This does away with some of the clarity concerns associated with preludes. &lt;a href=&quot;#fr-editor-1&quot;&gt;↩&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;&#x2F;section&gt;
</description>
      </item>
      <item>
          <title>System76</title>
          <pubDate>Thu, 25 Jul 2024 00:00:00 +0000</pubDate>
          <author>Matthias Endler</author>
          <link>https://corrode.dev/podcast/s02e07-system76/</link>
          <guid>https://corrode.dev/podcast/s02e07-system76/</guid>
          <description xml:base="https://corrode.dev/podcast/s02e07-system76/">&lt;div&gt;&lt;script id=&quot;letscast-player-e4782127&quot; src=&quot;https:&#x2F;&#x2F;letscast.fm&#x2F;podcasts&#x2F;rust-in-production-82281512&#x2F;episodes&#x2F;rust-in-production-ep-14-system76-s-jeremy-soller&#x2F;player.js?size=s&quot;&gt;&lt;&#x2F;script&gt;&lt;&#x2F;div&gt;
&lt;p&gt;Many devs dream of one day writing their own operating system. Ideally in their favorite language: Rust. For many of us, this dream remains just that: a dream.&lt;&#x2F;p&gt;
&lt;p&gt;Jeremy Soller from System76, however, didn’t just contribute kernel code for Pop!_OS, but also started his own operating system, RedoxOS, which is completely written in Rust. One might get the impression that he likes to tinker with low-level code!&lt;&#x2F;p&gt;
&lt;p&gt;In this episode of Rust in Production, Jeremy talks about his journey. From getting hired as a kernel developer at Denver-based company System76 after looking at the job ad for 1 month and finally applying, to being the maintainer of not one but two operating systems, additional system tools, and the Rust-based Cosmic desktop. We’ll talk about why it’s hard to write correct C code even for exceptional developers like Jeremy and why Rust is so great for refactoring and sharing code across different levels of abstraction.&lt;&#x2F;p&gt;</description>
      </item>
      <item>
          <title>How to Hire Rust Developers</title>
          <pubDate>Wed, 24 Jul 2024 00:00:00 +0000</pubDate>
          <author>Matthias Endler</author>
          <link>https://corrode.dev/blog/hiring-rust-engineers/</link>
          <guid>https://corrode.dev/blog/hiring-rust-engineers/</guid>
          <description xml:base="https://corrode.dev/blog/hiring-rust-engineers/">&lt;h2 id=&quot;the-rust-hiring-mismatch&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#the-rust-hiring-mismatch&quot; aria-label=&quot;Anchor link for: the-rust-hiring-mismatch&quot;&gt;The Rust Hiring Mismatch&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;p&gt;There’s a curious mismatch in the Rust hiring market where some companies
believe there’s a shortage of qualified candidates, while many Rust programmers struggle to find jobs. Why is that?&lt;&#x2F;p&gt;
&lt;p&gt;Most Rust jobs are for senior roles, leaving newcomers and mid-level devs out in the cold. Many of whom would be a great fit for these roles with a little bit of training.&lt;&#x2F;p&gt;
&lt;p&gt;The crypto industry is a notable exception, where Rust developers are in high demand, but not everyone wants to work in that space.
On top of that, crypto companies have inflated Rust developer salaries to unsustainable levels, making it difficult for other industries to compete for talent.&lt;&#x2F;p&gt;
&lt;p&gt;It’s not impossible, though! However, many companies want unicorns with years of Rust experience in an industry where that’s rare. Meanwhile, eager developers worldwide are ready to work but face barriers like location restrictions (US only), job security concerns (contract work only), or lack of “professional” Rust experience. It’s a classic case of supply and demand completely missing each other, with both sides frustrated and opportunities lost.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;but-isn-t-this-just-the-dev-job-market-in-general&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#but-isn-t-this-just-the-dev-job-market-in-general&quot; aria-label=&quot;Anchor link for: but-isn-t-this-just-the-dev-job-market-in-general&quot;&gt;But Isn’t this just the dev job market in general?&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;p&gt;Partially! However, I think it’s more pronounced in Rust because it’s a relatively new language and companies add it to their job ads because it generates interest.&lt;&#x2F;p&gt;
&lt;p&gt;The moment you try to get your foot in the door as a less experienced Rust developer, though, this mismatch becomes apparent. In tough market situations with fewer positions, companies tend to be more conservative and look for “safe bets” which means experts they are sure can hit the ground running – much to the detriment of less experienced developers.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;why-write-this-guide&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#why-write-this-guide&quot; aria-label=&quot;Anchor link for: why-write-this-guide&quot;&gt;Why Write This Guide?&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;p&gt;As a Rust consultant, it’s in my best interest to grow the hiring pool for Rust developers: if we want to grow the real-world usage of Rust, we need to get way more developers into the ecosystem. There are signs that this is happening, but with some tweaking, the process can be highly accelerated.&lt;&#x2F;p&gt;
&lt;p&gt;The broader consequence is that many companies are hesitant about adopting Rust and are therefore missing out on a rich ecosystem for building reliable and efficient services. This misconception is frustrating, as it often comes up when I talk to companies not yet using Rust.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;strong&gt;A common statement I hear is: “The community is still too small.”&lt;&#x2F;strong&gt;&lt;&#x2F;p&gt;
&lt;p&gt;In reality, the Rust community has more than tripled in size over the past two years and currently has &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.developernation.net&#x2F;resources&#x2F;reports&#x2F;state-of-the-developer-nation-24th-edition-q1-2023&quot;&gt;3.7M users, of which 0.6M joined in the last six months alone.&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;a href=&quot;https:&#x2F;&#x2F;www.developernation.net&#x2F;resources&#x2F;reports&#x2F;state-of-the-developer-nation-24th-edition-q1-2023&quot; target=&quot;_blank&quot;&gt;
&lt;img src=&quot;communities.svg&quot; class=&quot;invert&quot; alt=&quot;Programming Language Communities Size&quot;&gt;
&lt;&#x2F;a&gt;
&lt;p&gt;In contrast, companies that already use Rust in production rarely struggle with these issues and are generally very happy with their choice. If you’re still evaluating Rust for your organization, check out our guide on &lt;a href=&quot;&#x2F;blog&#x2F;why-rust&#x2F;&quot;&gt;Why Rust in Production&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;Here are some of the quotes from the &lt;a href=&quot;&#x2F;podcast&#x2F;s01e07-season-finale&#x2F;?t=23%3A06&quot;&gt;season 1 finale of the ‘Rust in Production’ podcast&lt;&#x2F;a&gt;:&lt;&#x2F;p&gt;
&lt;blockquote&gt;
&lt;p&gt;I announced that we’re working on this new core of the database in November of 2020 in a talk I did. And I said we were hiring and basically like we got a bunch of inbound interestbecause of the fact that it was written in Rust.
– Paul Dix, Founder and CTO of &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.influxdata.com&#x2F;&quot;&gt;InfluxData&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
&lt;blockquote&gt;
&lt;p&gt;Because as a small company, you can attract people because they want to work in Rust. And that’s a big incentive to work for you.
– Micah Wylde, Founder of &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;arroyo.dev&#x2F;&quot;&gt;Arroyo&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
&lt;p&gt;Because I saw many companies make the same mistakes over and over again, I wrote a guide to help companies find Rust talent.&lt;&#x2F;p&gt;
&lt;p&gt;If you are a hiring manager or a team lead looking to hire Rust developers, this guide is for you. Feel free to pass it on internally to help improve your hiring process.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;setting-talent-expectations&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#setting-talent-expectations&quot; aria-label=&quot;Anchor link for: setting-talent-expectations&quot;&gt;Setting Talent Expectations&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;h4 id=&quot;avoid-unrealistic-demands&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#avoid-unrealistic-demands&quot; aria-label=&quot;Anchor link for: avoid-unrealistic-demands&quot;&gt;Avoid Unrealistic Demands&lt;&#x2F;a&gt;&lt;&#x2F;h4&gt;
&lt;p&gt;Don’t expect 10 years of Rust experience, as Rust is a relatively new language. (Rust 1.0 was released in 2015.)
Such exaggerated expectations can significantly (and unnecessarily) narrow your pool of potential candidates. Even worse, experienced developers might consider this a red flag as it shows a lack of understanding of the Rust community.&lt;&#x2F;p&gt;
&lt;p&gt;Instead, it might be enough to look for the &lt;em&gt;willingness&lt;&#x2F;em&gt; to learn Rust or, at most, non-production experience with the language.&lt;&#x2F;p&gt;
&lt;h4 id=&quot;clearly-specify-tasks-and-responsibilities&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#clearly-specify-tasks-and-responsibilities&quot; aria-label=&quot;Anchor link for: clearly-specify-tasks-and-responsibilities&quot;&gt;Clearly Specify Tasks and Responsibilities&lt;&#x2F;a&gt;&lt;&#x2F;h4&gt;
&lt;p&gt;Don’t just add ‘Rust’ as a keyword to attract more candidates.
If you don’t (plan to) use Rust in any meaningful way, this will reflect poorly on your company and waste the time of both the candidate and the hiring team.&lt;&#x2F;p&gt;
&lt;p&gt;Will the candidate have to work with other languages or technologies?
Outline the specific tasks and responsibilities that involve Rust.
Ideally, even mention the specific Rust libraries or frameworks you are using.
This helps candidates understand what is expected of them and which other ecosystems they might need to interact with.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;finding-candidates&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#finding-candidates&quot; aria-label=&quot;Anchor link for: finding-candidates&quot;&gt;Finding Candidates&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;p&gt;Granted, the Rust job market is still relatively small compared to other languages like Python or JavaScript, but I found that most companies
limit themselves by only looking for senior Rust developers. That’s a mistake.&lt;&#x2F;p&gt;
&lt;p&gt;With some training, you can save a lot of time and money by hiring mid-level developers or smart juniors who are eager to learn Rust.
Yes, &lt;a href=&quot;&#x2F;blog&#x2F;flattening-rusts-learning-curve&#x2F;&quot;&gt;there is a learning curve&lt;&#x2F;a&gt;, but it’s probably less expensive to train a
junior&#x2F;mid-level developer in Rust compared to hiring a senior&#x2F;staff Rust developer. For training resources, see our curated list of &lt;a href=&quot;&#x2F;blog&#x2F;rust-learning-resources-2026&#x2F;&quot;&gt;Rust Learning Resources&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;Currently, the best way to find Rust devs is&lt;&#x2F;p&gt;
&lt;ol&gt;
&lt;li&gt;in your company (if you have a training program).&lt;&#x2F;li&gt;
&lt;li&gt;through your network (ask around).&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;p&gt;From experience, you probably won’t have a lot of trouble finding interested candidates as many developers are trying to move into Rust.
However, constraints like location, salary, industry, and job security can be a deal-breaker for many.&lt;&#x2F;p&gt;
&lt;p&gt;For more experienced Rust developers, perks like remote work, flexible hours, and a focus on work-life balance are often as important as the salary.
Being able to work on open source or attend conferences can also be a big bonus.
These folks are in high demand and can afford to be picky.
If you can’t pay crypto money, at least give them some of the other perks
and be willing to make compromises.&lt;&#x2F;p&gt;
&lt;p&gt;If you’re looking for senior people or require a bigger pool of candidates, you might also want to consider sponsoring Rust-focused events, &lt;a href=&quot;&#x2F;blog&#x2F;rust-conferences-2025&#x2F;&quot;&gt;conferences&lt;&#x2F;a&gt;, or &lt;a href=&quot;&#x2F;podcast&quot;&gt;podcasts&lt;&#x2F;a&gt;. I found that sponsoring is a relatively underutilized channel with a lot of potential.&lt;&#x2F;p&gt;
&lt;p&gt;You can post job listings on Rust-specific job boards like &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;filtra.io&#x2F;rust&quot;&gt;Filtra.io&lt;&#x2F;a&gt;, &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;rustjobs.dev&#x2F;&quot;&gt;RustJobs.dev&lt;&#x2F;a&gt; and &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.rustjobs.fyi&#x2F;&quot;&gt;RustJobs.fyi&lt;&#x2F;a&gt;, or boards with a dedicated Rust section like  and &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;remoteok.com&#x2F;remote-rust-jobs&quot;&gt;RemoteOK&lt;&#x2F;a&gt;.
Also post in the monthly “who is hiring” threads on &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;news.ycombinator.com&#x2F;&quot;&gt;Hacker News&lt;&#x2F;a&gt; or &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.reddit.com&#x2F;r&#x2F;rust&#x2F;comments&#x2F;182f6dv&#x2F;official_rrust_whos_hiring_thread_for_jobseekers&#x2F;&quot;&gt;Reddit&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;assessing-candidates-for-rust-roles&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#assessing-candidates-for-rust-roles&quot; aria-label=&quot;Anchor link for: assessing-candidates-for-rust-roles&quot;&gt;Assessing Candidates for Rust Roles&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;p&gt;Hiring itself is a very complex topic, so don’t make it harder than it needs to be.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;strong&gt;The number one mistake is to just look at raw Rust experience!&lt;&#x2F;strong&gt;
Instead, there are many other indicators that can help you identify great candidates who are a good fit for Rust work, even if they currently don’t have much experience with the language.&lt;&#x2F;p&gt;
&lt;img src=&quot;evaluation.svg&quot; alt=&quot;Diagram for assessing Rust candidates - details below&quot;&gt;
&lt;p&gt;Let’s look at the points in more detail:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Adaptability:&lt;&#x2F;strong&gt; Look for candidates who have a proven track record to quickly adapt and learn new technologies. For example, if they worked with many different languages and know more than one programming paradigm, they might be a good fit.&lt;&#x2F;p&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Systems Understanding:&lt;&#x2F;strong&gt; A strong grasp of fundamental concepts such as stack vs heap, threading, and data structures is a good indicator of a candidate who hits the ground running with Rust.&lt;&#x2F;p&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Evaluate Troubleshooting Skills:&lt;&#x2F;strong&gt; A good proxy for Rust knowledge is the ability to debug and reason about code in general. Assess a candidates’ ability to understand and resolve compile errors in Rust, focusing on common issues with ownership and borrowing. Provide scenarios that require light debugging and refactoring of Rust code.&lt;&#x2F;p&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Rust Reasoning:&lt;&#x2F;strong&gt; For those without Rust experience, test their ability to reason about Rust code. Provide sample Rust code and ask them to explain what it does. Looking up documentation is allowed. Ask clarifying questions to gauge their interest and to see how quickly they can learn.&lt;&#x2F;p&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Ask to use the Rust documentation:&lt;&#x2F;strong&gt; Rust takes documentation seriously. Show candidates some Rust documentation and ask follow-up questions to gauge their ability to understand basic concepts. Ask them to document a piece of code themselves or explain it in their own words.&lt;&#x2F;p&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Related Languages:&lt;&#x2F;strong&gt; Be open to candidates transitioning from C++, Java, Kotlin, or TypeScript, which have an equally strong emphasis on enterprise-grade software development. Haskell, OCaml, and other functional programming languages can also be a good fit, because of their focus on the type system and correctness. Rust has &lt;a href=&quot;&#x2F;blog&#x2F;paradigms&#x2F;&quot;&gt;functional aspects&lt;&#x2F;a&gt;, which are similar to these languages.&lt;&#x2F;p&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Industry and Domain Knowledge:&lt;&#x2F;strong&gt; Consider candidates with experience in Rust’s key domains, such as backend development, infrastructure, real-time data processing, and systems programming. Depending on your niche, assess their expertise in these areas.&lt;&#x2F;p&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Open Source Work&lt;&#x2F;strong&gt; (Optional): If a candidate mentions open source work, review the code quality and communication skills in issues and pull requests. Keep in mind that many great developers lack time for open source work, though.&lt;&#x2F;p&gt;
&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h2 id=&quot;takeaways&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#takeaways&quot; aria-label=&quot;Anchor link for: takeaways&quot;&gt;Takeaways&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;p&gt;&lt;strong&gt;If you’re a hiring manager&lt;&#x2F;strong&gt; don’t just look at raw Rust expertise; think outside the box and consider related skills and experience. The current hiring market is challenging, with an imbalance between eager developers and limited job opportunities. However, this presents a unique opportunity for forward-thinking companies to invest in talent. People exceed expectations when given trust and opportunity. For a comprehensive guide on adopting Rust in your organization, check out our &lt;a href=&quot;&#x2F;blog&#x2F;successful-rust-business-adoption-checklist&#x2F;&quot;&gt;Business Adoption Checklist&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;strong&gt;If you’re a professional Rust developer&lt;&#x2F;strong&gt; looking to improve the situation,
work with your hiring manager to help them understand how to hire more Rust devs. Perhaps this guide can help you get started.&lt;&#x2F;p&gt;
&lt;p&gt;Good luck with your Rust hiring process!&lt;&#x2F;p&gt;
&lt;div class=&quot;info&quot;&gt;
  
  &lt;div class=&quot;info-header&quot;&gt;
    
      &lt;span class=&quot;icon icon-crab&quot;&gt;&lt;&#x2F;span&gt;
    
    &lt;h4&gt;&lt;p&gt;Is your company adopting Rust?&lt;&#x2F;p&gt;
&lt;&#x2F;h4&gt;
  &lt;&#x2F;div&gt;
  
  &lt;p&gt;Let me help you make the most of Rust.
I offer consulting services to get you up to speed with your Rust projects, from training your team to code reviews and architecture consulting.
Check out my &lt;a href=&quot;&#x2F;services&quot;&gt;services page&lt;&#x2F;a&gt; to learn more.&lt;&#x2F;p&gt;

&lt;&#x2F;div&gt;
</description>
      </item>
      <item>
          <title>Fusion Engineering</title>
          <pubDate>Thu, 11 Jul 2024 00:00:00 +0000</pubDate>
          <author>Matthias Endler</author>
          <link>https://corrode.dev/podcast/s02e06-fusion-engineering/</link>
          <guid>https://corrode.dev/podcast/s02e06-fusion-engineering/</guid>
          <description xml:base="https://corrode.dev/podcast/s02e06-fusion-engineering/">&lt;div&gt;&lt;script id=&quot;letscast-player-446cf898&quot; src=&quot;https:&#x2F;&#x2F;letscast.fm&#x2F;podcasts&#x2F;rust-in-production-82281512&#x2F;episodes&#x2F;rust-in-production-ep-13-fusion-engineering-s-jakub-valtar&#x2F;player.js?size=s&quot;&gt;&lt;&#x2F;script&gt;&lt;&#x2F;div&gt;
&lt;p&gt;Rust can run everywhere, and by everywhere, we don’t just mean on all operating systems, but also in all kinds of harsh environments: from the depths of the ocean to the vastness of space. Today we talk to a company that is using Rust to conquer the air. Fusion Engineering is building drone control systems for the next generation of drones.&lt;&#x2F;p&gt;
&lt;p&gt;Jakub Valtar walks us through how Fusion Engineering came to use Rust as the foundation of their company. He explains why Rust is the safest choice for building drone control systems and what it takes to get into drone development.&lt;&#x2F;p&gt;</description>
      </item>
      <item>
          <title>OxidOS</title>
          <pubDate>Thu, 27 Jun 2024 00:00:00 +0000</pubDate>
          <author>Matthias Endler</author>
          <link>https://corrode.dev/podcast/s02e05-oxidos/</link>
          <guid>https://corrode.dev/podcast/s02e05-oxidos/</guid>
          <description xml:base="https://corrode.dev/podcast/s02e05-oxidos/">&lt;div&gt;&lt;script id=&quot;letscast-player-18346472&quot; src=&quot;https:&#x2F;&#x2F;letscast.fm&#x2F;podcasts&#x2F;rust-in-production-82281512&#x2F;episodes&#x2F;rust-in-production-ep-12-oxidos-alexandru-radovici&#x2F;player.js?size=s&quot;&gt;&lt;&#x2F;script&gt;&lt;&#x2F;div&gt;
&lt;p&gt;It has become a trope by now: “Cars are computers on wheels.” In modern cars, not only the infotainment system but also the engine, brakes, and steering wheel are controlled by software. Better make sure that software is safe.&lt;&#x2F;p&gt;
&lt;p&gt;Alexandru Radovici is a Software Engineer at OxidOS, a company that builds a secure, open-source operating system for cars built on Rust and &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;tockos.org&#x2F;&quot;&gt;Tock&lt;&#x2F;a&gt;.
We talk about the challenges of certifying Rust code for the automotive industry and the new possibilities with Rust-based car software.&lt;&#x2F;p&gt;</description>
      </item>
      <item>
          <title>Will Rust be alive in 10 years?</title>
          <pubDate>Mon, 24 Jun 2024 00:00:00 +0000</pubDate>
          <author>Matthias Endler</author>
          <link>https://corrode.dev/blog/rust-in-ten-years/</link>
          <guid>https://corrode.dev/blog/rust-in-ten-years/</guid>
          <description xml:base="https://corrode.dev/blog/rust-in-ten-years/">&lt;div class=&quot;info&quot;&gt;
  
  &lt;div class=&quot;info-header&quot;&gt;
    
      &lt;span class=&quot;icon icon-info&quot;&gt;&lt;&#x2F;span&gt;
    
    &lt;h4&gt;&lt;p&gt;Will Rust still exist, and have proper support, 10, 20 or even 30 years from now?&lt;&#x2F;p&gt;
&lt;&#x2F;h4&gt;
  &lt;&#x2F;div&gt;
  
  &lt;p&gt;We’ve been asked this question multiple times in the last year. It is a fair question, as adopting any new technology requires an investment and comes with uncertainties, one of them being the durability of the technology. This article explains why we expect Rust to stand the test of time.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;em&gt;This article is a friendly collaboration between Tweede golf (author: &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;tweedegolf.nl&#x2F;en&#x2F;about&#x2F;9&#x2F;hugo&quot;&gt;Hugo&lt;&#x2F;a&gt;) and corrode Rust Consulting (author: &lt;a href=&quot;&#x2F;services&#x2F;&quot;&gt;Matthias&lt;&#x2F;a&gt;). For more insights on Rust, also visit &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;tweedegolf.nl&#x2F;en&#x2F;blog&quot;&gt;the Tweede golf blog&lt;&#x2F;a&gt;.&lt;&#x2F;em&gt;&lt;&#x2F;p&gt;

&lt;&#x2F;div&gt;
&lt;p&gt;Wondering whether Rust will still be around is only relevant once you’ve determined that the language is technically the best solution for your project, so for the sake of this blog, we’re assuming that you have indeed already made this assessment. If you are still wondering whether Rust is for you, or how this potentially costly tech switch can actually save you money, check out &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;corrode.dev&#x2F;why-rust&#x2F;&quot;&gt;this blog post&lt;&#x2F;a&gt; instead.&lt;&#x2F;p&gt;
&lt;p&gt;In this article, we’ll go over the current state of the language (how old or young is it, really?), what we consider the three markers of longevity (spoiler, Rust does well on all three), and an honest disclaimer (what might still go wrong?).&lt;&#x2F;p&gt;
&lt;h2 id=&quot;is-it-hype-or-is-it-real&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#is-it-hype-or-is-it-real&quot; aria-label=&quot;Anchor link for: is-it-hype-or-is-it-real&quot;&gt;Is it hype or is it real?&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;p&gt;You might recognize the image below as the well-known  &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Technology_adoption_life_cycle&quot;&gt;Technology Adoption Lifecycle&lt;&#x2F;a&gt;. It goes without saying that Rust is still in the early stages.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;img src=&quot;https:&#x2F;&#x2F;corrode.dev&#x2F;blog&#x2F;rust-in-ten-years&#x2F;tech-adoption-lifecycle.svg&quot; alt=&quot;tech-adoption-lifecycle&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;p&gt;&lt;em&gt;Technology Adoption Lifecycle (&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;medium.com&#x2F;@shivayogiks&#x2F;what-is-technology-adoption-life-cycle-and-chasm-e07084e7991f&quot;&gt;image credits&lt;&#x2F;a&gt;)&lt;&#x2F;em&gt;&lt;&#x2F;p&gt;
&lt;p&gt;The question of Rust’s exact adoption status is too broad to answer with any precision or validity. This is because Rust is being used in many different industries, for various purposes, and each of these industries and uses has its own timeline.&lt;&#x2F;p&gt;
&lt;p&gt;Broadly speaking, we can say that Rust is somewhere in the Early Adopters stage in most domains like &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.theregister.com&#x2F;2024&#x2F;03&#x2F;31&#x2F;rust_google_c&#x2F;&quot;&gt;web&#x2F;backend&lt;&#x2F;a&gt; and systems programming, as companies like Google, Facebook, and Microsoft are heavily investing in Rust and have large systems written in it, powering their cloud offerings.  For instance, Mark Russinovich, CTO of Microsoft Azure, &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;x.com&#x2F;markrussinovich&#x2F;status&#x2F;1571995117233504257&quot;&gt;stated&lt;&#x2F;a&gt; that new projects should be written in Rust in preference to C or C++. Both the &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;docs.kernel.org&#x2F;rust&#x2F;&quot;&gt;Linux kernel&lt;&#x2F;a&gt; as well as the &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;x.com&#x2F;markrussinovich&#x2F;status&#x2F;1656416376125538304&quot;&gt;Windows kernel&lt;&#x2F;a&gt; contain Rust code now.&lt;&#x2F;p&gt;
&lt;p&gt;In embedded development, we have to separate the various industries. For example, in automotive projects, thanks to &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;ferrocene.dev&quot;&gt;Ferrocene&lt;&#x2F;a&gt; and &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;oxidos.io&quot;&gt;OxidOS&lt;&#x2F;a&gt;, Rust is past the Innovators stage and into the Early Adopters stage.  As for other industries like the aerospace, defense, and medical industries, Rust is still in the Innovators stage.&lt;&#x2F;p&gt;
&lt;p&gt;Some games like &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;store.steampowered.com&#x2F;app&#x2F;1110620&#x2F;Way_of_Rhea&#x2F;&quot;&gt;Way of Rhea&lt;&#x2F;a&gt; have been written in Rust and are available on Steam, but the gaming industry as a whole is still in the Innovators stage.&lt;&#x2F;p&gt;
&lt;p&gt;We do think that &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;blog.rust-lang.org&#x2F;2024&#x2F;02&#x2F;19&#x2F;2023-Rust-Annual-Survey-2023-results&#x2F;&quot;&gt;the broad penetration of Rust across industries&lt;&#x2F;a&gt; is rather impressive for a language that saw its first stable release just 9 years ago.&lt;&#x2F;p&gt;
&lt;p&gt;For a technology to cross the chasm, or to become mainstream, it needs to be recognized for being &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;youtu.be&#x2F;4RFBdcJRdbA?feature=shared&amp;amp;t=299&quot;&gt;highly effective&lt;&#x2F;a&gt; in a very specific area or use case.&lt;&#x2F;p&gt;
&lt;p&gt;And it is; Enter the relevance of memory safety in our digital infrastructure. It has been established (by &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;security.googleblog.com&#x2F;2019&#x2F;05&#x2F;queue-hardening-enhancements.html&quot;&gt;Google&lt;&#x2F;a&gt;, &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;msrc.microsoft.com&#x2F;blog&#x2F;2019&#x2F;07&#x2F;we-need-a-safer-systems-programming-language&#x2F;&quot;&gt;Microsoft&lt;&#x2F;a&gt;, &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;langui.sh&#x2F;2019&#x2F;07&#x2F;23&#x2F;apple-memory-safety&#x2F;&quot;&gt;Apple&lt;&#x2F;a&gt;, a.o.) that &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.chromium.org&#x2F;Home&#x2F;chromium-security&#x2F;memory-safety&#x2F;&quot;&gt;~70% of all security bugs in large C&#x2F;C++ code bases are memory safety issues&lt;&#x2F;a&gt;, which means that memory unsafety is a problem that needs to be addressed in all the software we rely on. &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;security.googleblog.com&#x2F;2022&#x2F;12&#x2F;memory-safe-languages-in-android-13.html&quot;&gt;Rust has proven to eliminate this class of bugs&lt;&#x2F;a&gt; and this is why it can now count organizations such as the &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.memorysafety.org&#x2F;docs&#x2F;memory-safety&#x2F;&quot;&gt;Internet Security Research Group&lt;&#x2F;a&gt;, &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;web.archive.org&#x2F;web&#x2F;2024*&#x2F;https:&#x2F;&#x2F;www.whitehouse.gov&#x2F;oncd&#x2F;briefing-room&#x2F;2024&#x2F;02&#x2F;26&#x2F;press-release-technical-report&#x2F;&quot;&gt;The White House&lt;&#x2F;a&gt;, and the German government-backed &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.sovereigntechfund.de&#x2F;news&#x2F;on-rust-memory-safety-open-source-infrastructure&quot;&gt;Sovereign Tech Fund&lt;&#x2F;a&gt; among its advocates.&lt;&#x2F;p&gt;
&lt;p&gt;Having established that Rust is at least ‘highly successful’ in solving the memory safety issues prevalent in our critical infrastructure, and thus capable of growing beyond the chasm, the question remains: will Rust be alive in 10 years?&lt;&#x2F;p&gt;
&lt;h2 id=&quot;why-rust-is-here-to-stay&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#why-rust-is-here-to-stay&quot; aria-label=&quot;Anchor link for: why-rust-is-here-to-stay&quot;&gt;Why Rust is here to stay&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;p&gt;In order to answer The Question, we first have to consider what we mean, exactly, when we refer to a programming language as being ‘alive’. What do we want from this language, 10 years down the line, that would make us feel confident in investing in it now?&lt;&#x2F;p&gt;
&lt;p&gt;We’ve narrowed our definition down to three criteria. A programming language is ‘alive’ if:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;there is significant usage by companies (and not just hobbyists);&lt;&#x2F;li&gt;
&lt;li&gt;there is a stable and mature ecosystem;&lt;&#x2F;li&gt;
&lt;li&gt;there is ongoing development not only in its core but also in peripheral tools and libraries.&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;We’ll go into each of these criteria to describe the status quo of Rust, as we see it.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;significant-usage&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#significant-usage&quot; aria-label=&quot;Anchor link for: significant-usage&quot;&gt;Significant usage&lt;&#x2F;a&gt;&lt;&#x2F;h3&gt;
&lt;p&gt;For a language to remain in significant usage in the long run, it needs to be adopted by industry leaders and applied across diverse fields, which would speak to its reliability and versatility respectively. A strong job market, an active community, and solid educational resources underscore its widespread acceptance and vitality. At this point, Rustaceans (that’s how Rust users are referred to in the community) are pointing at the screen, going ‘that’s us!’&lt;&#x2F;p&gt;
&lt;p&gt;Not all of these requirements are quantifiable, but let’s look at the ones that we can actually address.&lt;&#x2F;p&gt;
&lt;h4 id=&quot;investments-by-major-corporations&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#investments-by-major-corporations&quot; aria-label=&quot;Anchor link for: investments-by-major-corporations&quot;&gt;Investments by major corporations&lt;&#x2F;a&gt;&lt;&#x2F;h4&gt;
&lt;p&gt;Some major corporations (i.e. Google, Facebook, Microsoft, Amazon) are already betting big on Rust. Not only are they using the language in their code bases, they’re also investing in its ecosystem. This company backing is important for the long-term sustainability of the language.&lt;&#x2F;p&gt;
&lt;p&gt;Some examples of recent investments:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.reddit.com&#x2F;r&#x2F;rust&#x2F;comments&#x2F;1ajm56w&#x2F;google_donates_1m_to_the_rust_foundation_to&#x2F;&quot;&gt;Google donated $1M&lt;&#x2F;a&gt; to the Rust Foundation for the Interop Initiative, to improve the tooling for interoperability.&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;x.com&#x2F;dwizzzleMSFT&#x2F;status&#x2F;1720134540822520268&#x2F;photo&#x2F;2&quot;&gt;Microsoft invested in Rust&lt;&#x2F;a&gt;, including a $10M investment in Rust developer tooling and a $1M contribution to the Rust Foundation.&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h4 id=&quot;commercial-offerings-and-support&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#commercial-offerings-and-support&quot; aria-label=&quot;Anchor link for: commercial-offerings-and-support&quot;&gt;Commercial offerings and support&lt;&#x2F;a&gt;&lt;&#x2F;h4&gt;
&lt;p&gt;Several safety-aimed toolchains have been developed in and for Rust and they come with long-term commercial support.&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;ferrous-systems.com&#x2F;ferrocene&#x2F;&quot;&gt;Ferrocene&lt;&#x2F;a&gt; is a Rust compiler for safety-critical use in the automotive industry and has been ISO 26262 certified.&lt;&#x2F;li&gt;
&lt;li&gt;AdaCore developed &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.adacore.com&#x2F;gnatpro-rust&quot;&gt;Gnat Pro for Rust&lt;&#x2F;a&gt; and are targeting the aerospace industry.&lt;&#x2F;li&gt;
&lt;li&gt;HighTec has developed an ISO 26262-certified Rust compiler development platform for Infineon AURIX, which is essential for the automotive industry.&lt;&#x2F;li&gt;
&lt;li&gt;Just this month, &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;foundation.rust-lang.org&#x2F;news&#x2F;announcing-the-safety-critical-rust-consortium&#x2F;&quot;&gt;The Safety-Critical Rust Consortium&lt;&#x2F;a&gt; was founded by AdaCore, Arm, Woven by Toyota, and others, with the goal of supporting the responsible use of the Rust programming language in safety-critical software.&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h3 id=&quot;ecosystem-maturity&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#ecosystem-maturity&quot; aria-label=&quot;Anchor link for: ecosystem-maturity&quot;&gt;Ecosystem maturity&lt;&#x2F;a&gt;&lt;&#x2F;h3&gt;
&lt;p&gt;The maturity of the Rust ecosystem is difficult to quantify, but it has been growing steadily since its inception. It has gained attention, use, and support from ‘big tech’, professionals, and hobbyists alike. Driven by the idealistic goal of making software great again, Rust continues to evolve and thrive.&lt;&#x2F;p&gt;
&lt;h4 id=&quot;growth&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#growth&quot; aria-label=&quot;Anchor link for: growth&quot;&gt;Growth&lt;&#x2F;a&gt;&lt;&#x2F;h4&gt;
&lt;p&gt;Let’s quantify what we can.&lt;&#x2F;p&gt;
&lt;p&gt;As is widely known, Rust has been Stack Overflows ‘most loved language’ since 2016, and &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;stackoverflow.blog&#x2F;2024&#x2F;03&#x2F;04&#x2F;in-rust-we-trust-white-house-office-urges-memory-safety&#x2F;&quot;&gt;became ‘most admired’ in 2023&lt;&#x2F;a&gt;. In the same vein, Rust (together with Dart) was the fastest growing community (i.e. number of developers) in 2023, nearly doubling in size from 2022 to 2024:&lt;&#x2F;p&gt;
&lt;blockquote&gt;
&lt;p&gt;“Dart and Rust grew at an average annual rate of more than 30% in 2023.”&lt;br &#x2F;&gt;
— from &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;research.slashdata.co&#x2F;reports&#x2F;65b90140343d024fbe70f369&quot;&gt;SlashData’s State of the Developer Nation 25th Edition&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
&lt;blockquote&gt;
&lt;p&gt;“Rust has nearly doubled in size over the past two years, growing from 2M to 4M users.”&lt;br &#x2F;&gt;
— from &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;research.slashdata.co&#x2F;reports&#x2F;66546c6a78c13bcad12eac6e&quot;&gt;SlashData’s Sizing Programming Languages Communities&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
&lt;p&gt;In 2024 alone, there are 8 conferences dedicated to Rust: Rust Nation (London, UK), RustNL (Delft, the Netherlands), RustFest (Zürich, Switzerland), RustConf (Montreal, Canada), EuroRust (Vienna, Austria), RustLab (Florence, Italy), Oxidize (Berlin, Germany), Rust Summit (Belgrade, Serbia).&lt;&#x2F;p&gt;
&lt;p&gt;And the number of crates (libraries) downloaded from crates.io has grown exponentially:&lt;&#x2F;p&gt;
&lt;p&gt;&lt;img src=&quot;https:&#x2F;&#x2F;corrode.dev&#x2F;blog&#x2F;rust-in-ten-years&#x2F;crate-downloads.jpg&quot; alt=&quot;jakub-beranek-slides-package-downloads-v2&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;p&gt;&lt;em&gt;Slide from &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;tweedegolf.nl&#x2F;images&#x2F;jakub-beranek-rustnl2024-slides.pdf&quot;&gt;Jakub Beránek’s RustNL 2024 talk&lt;&#x2F;a&gt;&lt;&#x2F;em&gt;&lt;&#x2F;p&gt;
&lt;p&gt;As of today, there are &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;search?q=language%3Arust&amp;amp;type=repositories&quot;&gt;355k&lt;&#x2F;a&gt; Rust projects on GitHub (including archived repositories).&lt;&#x2F;p&gt;
&lt;h4 id=&quot;funding&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#funding&quot; aria-label=&quot;Anchor link for: funding&quot;&gt;Funding&lt;&#x2F;a&gt;&lt;&#x2F;h4&gt;
&lt;p&gt;Most programming languages are backed by a single big-tech giant. Consider Go, curated by Google, and Swift, supported by Apple.&lt;&#x2F;p&gt;
&lt;p&gt;Rust is a different story, intentionally so. After the COVID pandemic had hit language creator Mozilla hard, they realized that the vulnerable position of the company (a quarter of its employees had to be fired) could directly affect the language. Mozilla joined forces with four(!) other big tech names (AWS, Huawei, Google and Microsoft) to create &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;foundation.rust-lang.org&#x2F;&quot;&gt;the Rust Foundation&lt;&#x2F;a&gt;:&lt;&#x2F;p&gt;
&lt;blockquote&gt;
&lt;p&gt;“The Rust Foundation is an independent non-profit organization dedicated to stewarding the Rust programming language, nurturing the Rust ecosystem, and supporting the set of maintainers governing and developing the project.”&lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
&lt;p&gt;This means that there isn’t one company pulling all the strings. In addition, many of the volunteers who helped shape the language are now being employed by companies like Amazon and Huawei to work on the compiler full-time. The foundations that Rust is built on (both financial and technical) are thus much stronger and more diverse than those of most other languages.&lt;&#x2F;p&gt;
&lt;h4 id=&quot;memory-safety&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#memory-safety&quot; aria-label=&quot;Anchor link for: memory-safety&quot;&gt;Memory-safety&lt;&#x2F;a&gt;&lt;&#x2F;h4&gt;
&lt;p&gt;Rust is the only language that combines memory safety with C-like performance and the capabilities of a systems language. And we are seeing that the &lt;em&gt;need&lt;&#x2F;em&gt; for memory safety is becoming much more prevalent (dare we say, mainstream) in the software that we use and rely on on a daily basis. Consider the White House’s call to action:&lt;&#x2F;p&gt;
&lt;blockquote&gt;
&lt;p&gt;“We, as a nation, have the ability – and the responsibility – to reduce the attack surface in cyberspace and prevent entire classes of security bugs from entering the digital ecosystem but that means we need to tackle the hard problem of moving to memory safe programming languages.” - &lt;em&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;web.archive.org&#x2F;web&#x2F;2024*&#x2F;https:&#x2F;&#x2F;www.whitehouse.gov&#x2F;oncd&#x2F;briefing-room&#x2F;2024&#x2F;02&#x2F;26&#x2F;press-release-technical-report&#x2F;&quot;&gt;Harry Coker, US National Cyber Director&lt;&#x2F;a&gt;&lt;&#x2F;em&gt;&lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
&lt;p&gt;Clearly, memory safety is considered a national priority by the White House. (Of course, we’d like to argue that ‘The Internet’ and our digital infrastructure is never a mere national matter; the scope of this issue is far greater than that, but we understand that for the sake of politics, it sometimes must be reduced to a national issue.) It goes to show that awareness of the issue is no longer niche. It is a matter of time before the implications of it (actually writing memory safe software) will also become ‘mainstream’.&lt;&#x2F;p&gt;
&lt;p&gt;We’re not the only ones who expect that Rust will continue to grow because of this:&lt;&#x2F;p&gt;
&lt;blockquote&gt;
&lt;p&gt;The USA and its international partners have made the case in the last six months for adopting memory-safe languages. While Rust is not unique in this capability, its performance benefits alongside being memory-safe are likely to lead to further growth in this developer community. - &lt;em&gt;From &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;research.slashdata.co&#x2F;reports&#x2F;66546c6a78c13bcad12eac6e&quot;&gt;SlashData’s Sizing Programming Languages Communities&lt;&#x2F;a&gt;&lt;&#x2F;em&gt;&lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
&lt;h3 id=&quot;ongoing-development&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#ongoing-development&quot; aria-label=&quot;Anchor link for: ongoing-development&quot;&gt;Ongoing development&lt;&#x2F;a&gt;&lt;&#x2F;h3&gt;
&lt;p&gt;Rust is a language with a wide surface area; engineers use it for projects ranging from embedded devices over backend services to high-performance storage engines and even space projects. This is possible due to Rust’s high adaptability. It can be integrated into existing codebases thanks to its excellent C&#x2F;C++-compatible foreign function interface. It also has best-in-class WebAssembly support through multiple runtimes like Wasmtime and Cloudflare’s wrangler. And as we’re learning how to use the language to its full potential, new areas of Rust usage keep popping up, such as game development (e.g. &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;bevyengine.org&#x2F;&quot;&gt;Bevy&lt;&#x2F;a&gt;).&lt;&#x2F;p&gt;
&lt;p&gt;We previously noted that Rust package downloads are growing at an exponential rate, but creators are getting more productive too; The number of crates available &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;lib.rs&#x2F;stats&quot;&gt;doubles&lt;&#x2F;a&gt; each year! And traffic on crates.io is 2.8x higher on weekdays than over the weekend, which indicates that most Rust development takes place in work-related projects.&lt;&#x2F;p&gt;
&lt;p&gt;Continuous development doesn’t stop at the ecosystem level though. The language itself also keeps evolving.&lt;&#x2F;p&gt;
&lt;p&gt;Rust’s approach to steady innovation is meant to ensure stability and it is achieved through its edition system. Editions are Rust releases, which are allowed to deprecate features and introduce breaking changes. Editions are rare, though. They happen roughly every three years (2018, 2021, and later this year).&lt;&#x2F;p&gt;
&lt;h2 id=&quot;challenges-to-rust-s-longevity&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#challenges-to-rust-s-longevity&quot; aria-label=&quot;Anchor link for: challenges-to-rust-s-longevity&quot;&gt;Challenges to Rust’s longevity&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;p&gt;While it seems obvious to us that Rust does well on all three ‘markers of longevity’ - there is significant usage, the ecosystem is growing and rests on a solid foundation, and there is structural and ongoing development - we can’t predict the future. And ‘things happen’. So what could go wrong?&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;Sponsorship could dry up. As we’ve mentioned before, Rust’s sponsorship doesn’t rely on a single big tech company, but rather a consortium of them, so we don’t think this scenario is a likely one, but it isn’t impossible.&lt;&#x2F;li&gt;
&lt;li&gt;The ecosystem could split. It’s happened before to the Node ecosystem (and there already was a &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;crablang&#x2F;crab&quot;&gt;Rust fork&lt;&#x2F;a&gt;). This is certainly not something for us to make any predictions about.&lt;&#x2F;li&gt;
&lt;li&gt;Something better comes around, weakening Rust’s ‘raison d’être’. but that would actually be great! It would improve the status quo of our digital world (which is really what we Rust developers want most of all) and a rising tide lifts all. It’s highly unlikely that this would happen in the short term, as development of a language takes years. But we cannot guarantee that it won’t happen, of course (and we wouldn’t want to stop it if it did).&lt;&#x2F;li&gt;
&lt;li&gt;Rust might become too complex. While we acknowledge the potential for Rust to increase in complexity as it evolves, we have the impression that the Rust community actively works to balance new features with maintainability and usability. In fact, except for async Rust, the language has reached a point of relative maturity.&lt;&#x2F;li&gt;
&lt;li&gt;Hiring Rust devs is a challenge. This one, we have to cop to. The situation is getting better, there are solutions out there (train your own devs to use Rust, use educational materials like &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;rust-edu.org&#x2F;&quot;&gt;Rust Edu&lt;&#x2F;a&gt; and &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;tweedegolf&#x2F;teach-rs&quot;&gt;teach-rs&lt;&#x2F;a&gt;), and this is a growing market, underscoring the ecosystem maturity… But it still isn’t easy.&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h2 id=&quot;conclusion&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#conclusion&quot; aria-label=&quot;Anchor link for: conclusion&quot;&gt;Conclusion&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;p&gt;Rust is at an exciting point in its history. With large corporations investing heavily in Rust and engineers embracing the language, we believe Rust has a bright future ahead.&lt;&#x2F;p&gt;
&lt;p&gt;If your organization is considering migrating to Rust and is unsure about the language’s long-term viability, we hope this information (be sure to check out some of the resources&#x2F;links!) helps ease your decision-making process.&lt;&#x2F;p&gt;
&lt;p&gt;And if you need assistance along the way, why not reach out to &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;tweedegolf.nl&#x2F;en&#x2F;expertise&#x2F;rust-engineering&quot;&gt;Tweede golf&lt;&#x2F;a&gt; and &lt;a href=&quot;&#x2F;services&quot;&gt;corrode&lt;&#x2F;a&gt;?&lt;&#x2F;p&gt;
</description>
      </item>
      <item>
          <title>Making Your First Real-World Rust Project a Success</title>
          <pubDate>Fri, 14 Jun 2024 00:00:00 +0000</pubDate>
          <author>Matthias Endler</author>
          <link>https://corrode.dev/blog/successful-rust-business-adoption-checklist/</link>
          <guid>https://corrode.dev/blog/successful-rust-business-adoption-checklist/</guid>
          <description xml:base="https://corrode.dev/blog/successful-rust-business-adoption-checklist/">&lt;p&gt;Rust has quickly become a popular choice for teams seeking to write safe and efficient systems. Its unique blend of performance, safety, and concurrency makes it an attractive option for various applications, from embedded systems to web development.&lt;&#x2F;p&gt;
&lt;p&gt;However, adopting Rustlang for your first production project requires careful planning and strategy. After all, this is a big deal: betting on a new programming language could be a business decision that you base the next ten years of your company on.&lt;&#x2F;p&gt;
&lt;p&gt;The goal of this guide is to provide you with a comprehensive checklist and actionable advice to make your first real-world Rust project a success.&lt;&#x2F;p&gt;
&lt;div class=&quot;info&quot;&gt;
  
  &lt;div class=&quot;info-header&quot;&gt;
    
      &lt;span class=&quot;icon icon-crab&quot;&gt;&lt;&#x2F;span&gt;
    
    &lt;h4&gt;&lt;p&gt;Looking for a Detailed Rust Project Plan?&lt;&#x2F;p&gt;
&lt;&#x2F;h4&gt;
  &lt;&#x2F;div&gt;
  
  &lt;p&gt;Get my proven Rust project plan that I use for my consulting projects.&lt;br &#x2F;&gt;
&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;corrode.notion.site&#x2F;8e2457230e75438f95e0620fcf09b034&quot;&gt;Access it here&lt;&#x2F;a&gt; and customize it to fit your needs.&lt;&#x2F;p&gt;

&lt;&#x2F;div&gt;
&lt;h2&gt;Table of Contents&lt;&#x2F;h2&gt;
&lt;details class=&quot;toc&quot;&gt;
&lt;summary&gt;
Click here to expand the table of contents.
&lt;&#x2F;summary&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;https:&#x2F;&#x2F;corrode.dev&#x2F;blog&#x2F;successful-rust-business-adoption-checklist&#x2F;#know-why-you-are-considering-rust&quot;&gt;Know Why You Are Considering Rust&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a href=&quot;https:&#x2F;&#x2F;corrode.dev&#x2F;blog&#x2F;successful-rust-business-adoption-checklist&#x2F;#get-the-buy-in-from-stakeholders&quot;&gt;Get The Buy-In From Stakeholders&lt;&#x2F;a&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;https:&#x2F;&#x2F;corrode.dev&#x2F;blog&#x2F;successful-rust-business-adoption-checklist&#x2F;#your-team-must-be-on-board&quot;&gt;Your Team Must Be On Board&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a href=&quot;https:&#x2F;&#x2F;corrode.dev&#x2F;blog&#x2F;successful-rust-business-adoption-checklist&#x2F;#keep-an-eye-on-the-bus-factor&quot;&gt;Keep an Eye on The Bus Factor&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a href=&quot;https:&#x2F;&#x2F;corrode.dev&#x2F;blog&#x2F;successful-rust-business-adoption-checklist&#x2F;#find-a-rust-champion&quot;&gt;Find a Rust Champion&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a href=&quot;https:&#x2F;&#x2F;corrode.dev&#x2F;blog&#x2F;successful-rust-business-adoption-checklist&#x2F;#run-a-survey-to-gauge-interest-and-concerns&quot;&gt;Run a Survey to Gauge Interest and Concerns&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a href=&quot;https:&#x2F;&#x2F;corrode.dev&#x2F;blog&#x2F;successful-rust-business-adoption-checklist&#x2F;#address-concerns-and-answer-questions-in-a-relaxed-setting&quot;&gt;Address Concerns and Answer Questions in a Relaxed Setting&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a href=&quot;https:&#x2F;&#x2F;corrode.dev&#x2F;blog&#x2F;successful-rust-business-adoption-checklist&#x2F;#project-planning&quot;&gt;Project Planning&lt;&#x2F;a&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;https:&#x2F;&#x2F;corrode.dev&#x2F;blog&#x2F;successful-rust-business-adoption-checklist&#x2F;#finding-the-right-project&quot;&gt;Finding The Right Project&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a href=&quot;https:&#x2F;&#x2F;corrode.dev&#x2F;blog&#x2F;successful-rust-business-adoption-checklist&#x2F;#choose-the-right-integration-method&quot;&gt;Choose The Right Integration Method&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a href=&quot;https:&#x2F;&#x2F;corrode.dev&#x2F;blog&#x2F;successful-rust-business-adoption-checklist&#x2F;#check-the-ecosystem&quot;&gt;Check the Ecosystem&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a href=&quot;https:&#x2F;&#x2F;corrode.dev&#x2F;blog&#x2F;successful-rust-business-adoption-checklist&#x2F;#set-standards-for-crates&quot;&gt;Set Standards for Crates&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a href=&quot;https:&#x2F;&#x2F;corrode.dev&#x2F;blog&#x2F;successful-rust-business-adoption-checklist&#x2F;#establish-a-policy-on-async-rust&quot;&gt;Establish a Policy on Async Rust&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a href=&quot;https:&#x2F;&#x2F;corrode.dev&#x2F;blog&#x2F;successful-rust-business-adoption-checklist&#x2F;#have-a-migration-strategy&quot;&gt;Have a Migration Strategy&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a href=&quot;https:&#x2F;&#x2F;corrode.dev&#x2F;blog&#x2F;successful-rust-business-adoption-checklist&#x2F;#become-an-active-member-of-the-community&quot;&gt;Become An Active Member Of The Community&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a href=&quot;https:&#x2F;&#x2F;corrode.dev&#x2F;blog&#x2F;successful-rust-business-adoption-checklist&#x2F;#project-setup&quot;&gt;Project Setup&lt;&#x2F;a&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;https:&#x2F;&#x2F;corrode.dev&#x2F;blog&#x2F;successful-rust-business-adoption-checklist&#x2F;#fully-embrace-rust-tooling&quot;&gt;Fully Embrace Rust Tooling&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a href=&quot;https:&#x2F;&#x2F;corrode.dev&#x2F;blog&#x2F;successful-rust-business-adoption-checklist&#x2F;#consider-an-internal-styleguide&quot;&gt;Consider An Internal Styleguide&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a href=&quot;https:&#x2F;&#x2F;corrode.dev&#x2F;blog&#x2F;successful-rust-business-adoption-checklist&#x2F;#team-building&quot;&gt;Team Building&lt;&#x2F;a&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;https:&#x2F;&#x2F;corrode.dev&#x2F;blog&#x2F;successful-rust-business-adoption-checklist&#x2F;#start-with-a-small-team&quot;&gt;Start With a Small Team&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a href=&quot;https:&#x2F;&#x2F;corrode.dev&#x2F;blog&#x2F;successful-rust-business-adoption-checklist&#x2F;#start-a-team-channel&quot;&gt;Start a Team Channel&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a href=&quot;https:&#x2F;&#x2F;corrode.dev&#x2F;blog&#x2F;successful-rust-business-adoption-checklist&#x2F;#consider-expert-mentorship&quot;&gt;Consider Expert Mentorship&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a href=&quot;https:&#x2F;&#x2F;corrode.dev&#x2F;blog&#x2F;successful-rust-business-adoption-checklist&#x2F;#allocate-time-for-learning&quot;&gt;Allocate Time for Learning&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a href=&quot;https:&#x2F;&#x2F;corrode.dev&#x2F;blog&#x2F;successful-rust-business-adoption-checklist&#x2F;#learning-resources&quot;&gt;Learning Resources&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a href=&quot;https:&#x2F;&#x2F;corrode.dev&#x2F;blog&#x2F;successful-rust-business-adoption-checklist&#x2F;#budgeting&quot;&gt;Budgeting&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a href=&quot;https:&#x2F;&#x2F;corrode.dev&#x2F;blog&#x2F;successful-rust-business-adoption-checklist&#x2F;#on-hiring-talent&quot;&gt;On Hiring Talent&lt;&#x2F;a&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;https:&#x2F;&#x2F;corrode.dev&#x2F;blog&#x2F;successful-rust-business-adoption-checklist&#x2F;#people-with-production-experience-are-hard-to-find-and-expensive&quot;&gt;People with Production Experience Are Hard to Find and Expensive&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a href=&quot;https:&#x2F;&#x2F;corrode.dev&#x2F;blog&#x2F;successful-rust-business-adoption-checklist&#x2F;#source-talent-from-your-existing-teams-instead&quot;&gt;Source Talent From Your Existing Teams Instead&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a href=&quot;https:&#x2F;&#x2F;corrode.dev&#x2F;blog&#x2F;successful-rust-business-adoption-checklist&#x2F;#scaling-the-team&quot;&gt;Scaling The Team&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a href=&quot;https:&#x2F;&#x2F;corrode.dev&#x2F;blog&#x2F;successful-rust-business-adoption-checklist&#x2F;#ongoing-maintenance&quot;&gt;Ongoing Maintenance&lt;&#x2F;a&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;https:&#x2F;&#x2F;corrode.dev&#x2F;blog&#x2F;successful-rust-business-adoption-checklist&#x2F;#emphasize-code-reviews-and-pair-programming&quot;&gt;Emphasize Code Reviews and Pair Programming&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a href=&quot;https:&#x2F;&#x2F;corrode.dev&#x2F;blog&#x2F;successful-rust-business-adoption-checklist&#x2F;#encourage-refactoring&quot;&gt;Encourage Refactoring&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a href=&quot;https:&#x2F;&#x2F;corrode.dev&#x2F;blog&#x2F;successful-rust-business-adoption-checklist&#x2F;#regularly-review-progress-and-adjust-strategies&quot;&gt;Regularly Review Progress and Adjust Strategies&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a href=&quot;https:&#x2F;&#x2F;corrode.dev&#x2F;blog&#x2F;successful-rust-business-adoption-checklist&#x2F;#next-steps&quot;&gt;Next Steps&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;details&gt;
&lt;h2 id=&quot;know-why-you-are-considering-rust&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#know-why-you-are-considering-rust&quot; aria-label=&quot;Anchor link for: know-why-you-are-considering-rust&quot;&gt;Know Why You Are Considering Rust&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;p&gt;Understanding &lt;em&gt;why&lt;&#x2F;em&gt; you are considering adopting Rust is crucial.&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;Define clear goals and expectations for the project — this is a good idea, no matter if you decide on Rust or another language in the end.&lt;&#x2F;li&gt;
&lt;li&gt;Set out to &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.youtube.com&#x2F;watch?v=DnT-LUQgc7s&quot;&gt;compare all the available options by fairly evaluating the pros and cons of each language&lt;&#x2F;a&gt; in a table or a document. Share this document with your team and stakeholders to fill in the gaps and ensure transparency.&lt;&#x2F;li&gt;
&lt;li&gt;Focus on business value and long-term benefits, not personal preferences.&lt;&#x2F;li&gt;
&lt;li&gt;Rust needs a catalyst for success, i.e., a clear benefit, which will be the driving force behind the adoption. Good catalysts are higher service stability, reduced operational costs, and better security. Don’t focus on performance alone.&lt;&#x2F;li&gt;
&lt;li&gt;Write down your success criteria, such as improved robustness (lower number of bugs), developer productivity, and better scalability.&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h2 id=&quot;get-the-buy-in-from-stakeholders&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#get-the-buy-in-from-stakeholders&quot; aria-label=&quot;Anchor link for: get-the-buy-in-from-stakeholders&quot;&gt;Get The Buy-In From Stakeholders&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;h3 id=&quot;your-team-must-be-on-board&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#your-team-must-be-on-board&quot; aria-label=&quot;Anchor link for: your-team-must-be-on-board&quot;&gt;Your Team Must Be On Board&lt;&#x2F;a&gt;&lt;&#x2F;h3&gt;
&lt;p&gt;Introducing Rust will be a disruptive change, and it’s vital to have the backing from both the team and leadership. One side is not enough. Make sure everyone understands the &lt;a href=&quot;&#x2F;blog&#x2F;why-rust&quot;&gt;benefits and challenges of using Rust&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;Rust is an organization-wide commitment, and it’s vital to have a long-term mindset. If you need to get something done quickly and can afford tech debt, consider using another language. However, for long-term projects, Rust’s benefits will offset the initial learning curve.&lt;&#x2F;p&gt;
&lt;p&gt;Management should understand the benefits of Rust and be willing to invest in training, hiring, and tooling. They should also be aware of the potential challenges (e.g., delayed project timelines, increased costs, etc.) and have a clear understanding of the trade-offs involved.&lt;&#x2F;p&gt;
&lt;p&gt;The magnitude of this decision should not be underestimated. Therefore, at the beginning of your adoption journey, consider bringing in a consultancy (&lt;a href=&quot;&#x2F;&quot;&gt;like corrode&lt;&#x2F;a&gt;) to help decision-makers fully understand the costs and benefits of Rust. This can be crucial for assessing risks and avoiding major surprises down the road. While this means a higher upfront cost, it ultimately provides clarity and allows your team to focus on the technical aspects, setting the project up for success.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;keep-an-eye-on-the-bus-factor&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#keep-an-eye-on-the-bus-factor&quot; aria-label=&quot;Anchor link for: keep-an-eye-on-the-bus-factor&quot;&gt;Keep an Eye on The Bus Factor&lt;&#x2F;a&gt;&lt;&#x2F;h3&gt;
&lt;p&gt;The &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Bus_factor&quot;&gt;bus factor&lt;&#x2F;a&gt; is the number of people on your team who need to be hit by a bus before your project is in trouble. Make sure this bus factor is bigger than 1.&lt;&#x2F;p&gt;
&lt;p&gt;Rust adoption should not be driven by ego or your CV but by business needs.
If you love Rust, but your organization is not ready for it, don’t force it on them — it will fall back on you. There should always be more than one person who knows the system well enough to maintain it.&lt;&#x2F;p&gt;
&lt;p&gt;Similarly, if you are the manager who has merely heard about the benefits of Rust, but your team is perfectly happy with the current technology stack, there might be no need to switch. Don’t choose Rust because of the hype; listen to your team.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;find-a-rust-champion&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#find-a-rust-champion&quot; aria-label=&quot;Anchor link for: find-a-rust-champion&quot;&gt;Find a Rust Champion&lt;&#x2F;a&gt;&lt;&#x2F;h3&gt;
&lt;p&gt;Find a Rust champion within your team who is passionate about Rust, good at teaching, and willing to lead the adoption effort. They will serve as the cornerstone for your Rust adoption process and can significantly ease the learning process for the rest of the team.&lt;&#x2F;p&gt;
&lt;p&gt;They don’t have to be a Rust expert, but ideally, a good champion already has some experience with Rust in production or has built a few larger side projects with it.&lt;&#x2F;p&gt;
&lt;p&gt;If there is nobody willing to take on that role, reconsider if Rust is the right choice; perhaps the team is not ready for the transition yet or is satisfied with the current technology stack. An external consultant cannot replace an internal champion (if anything, they work in tandem). The initial motivation has to come from within.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;run-a-survey-to-gauge-interest-and-concerns&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#run-a-survey-to-gauge-interest-and-concerns&quot; aria-label=&quot;Anchor link for: run-a-survey-to-gauge-interest-and-concerns&quot;&gt;Run a Survey to Gauge Interest and Concerns&lt;&#x2F;a&gt;&lt;&#x2F;h3&gt;
&lt;p&gt;Run a survey to gauge the team’s initial interest in Rust. Ask questions like:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;What is your current language of choice?&lt;&#x2F;li&gt;
&lt;li&gt;On a scale from 1 to 5, how interested are you in learning Rust?&lt;&#x2F;li&gt;
&lt;li&gt;What are your main concerns about adopting Rust?&lt;&#x2F;li&gt;
&lt;li&gt;Which other languages would you consider for the project?&lt;&#x2F;li&gt;
&lt;li&gt;What are the main benefits of choosing Rust for this project?&lt;&#x2F;li&gt;
&lt;li&gt;Would you be willing to take on a Rust project? If so, in what capacity?&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;If you need a comprehensive survey template to get started, feel free to &lt;a href=&quot;&#x2F;services&quot;&gt;reach out to me&lt;&#x2F;a&gt;. The template includes detailed questions that can help uncover your team’s readiness and potential challenges for adopting Rust.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;address-concerns-and-answer-questions-in-a-relaxed-setting&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#address-concerns-and-answer-questions-in-a-relaxed-setting&quot; aria-label=&quot;Anchor link for: address-concerns-and-answer-questions-in-a-relaxed-setting&quot;&gt;Address Concerns and Answer Questions in a Relaxed Setting&lt;&#x2F;a&gt;&lt;&#x2F;h3&gt;
&lt;p&gt;If you get mixed results, consider holding a Rust Q&amp;amp;A session with the team on a Friday afternoon. This way, you can address concerns and answer questions in a relaxed environment.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;project-planning&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#project-planning&quot; aria-label=&quot;Anchor link for: project-planning&quot;&gt;Project Planning&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;h3 id=&quot;finding-the-right-project&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#finding-the-right-project&quot; aria-label=&quot;Anchor link for: finding-the-right-project&quot;&gt;Finding The Right Project&lt;&#x2F;a&gt;&lt;&#x2F;h3&gt;
&lt;p&gt;My number one rule is: start small, but not too small.&lt;&#x2F;p&gt;
&lt;p&gt;Begin with a project that is close to your core business but not mission-critical. This approach allows your team to gain experience with Rust with less disruption to the business.&lt;&#x2F;p&gt;
&lt;p&gt;Choose a project in a domain you know very well. This way, you can focus on learning Rust and not on understanding the domain. On top of that, you can compare the performance of Rust with the existing system and see if it lives up to the expectations. It will be easier to onboard new team members if they are already familiar with the domain.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;choose-the-right-integration-method&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#choose-the-right-integration-method&quot; aria-label=&quot;Anchor link for: choose-the-right-integration-method&quot;&gt;Choose The Right Integration Method&lt;&#x2F;a&gt;&lt;&#x2F;h3&gt;
&lt;p&gt;There are various ways to integrate Rust into your existing infrastructure:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;CLI Tool&lt;&#x2F;strong&gt;: Develop a command-line tool in Rust.&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;FFI Layer&lt;&#x2F;strong&gt;: Call Rust code from another language using the Foreign Function Interface.&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Microservice &#x2F; Network Layer&lt;&#x2F;strong&gt;: Implement a microservice in Rust.&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;WebAssembly&lt;&#x2F;strong&gt;: Use Rust to compile to WebAssembly (e.g. for frontend).&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Embedded System&lt;&#x2F;strong&gt;: Develop an embedded system in Rust.&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;Pick the integration method which best aligns with your project’s requirements and team’s expertise. Choose a method that allows you to leverage Rust’s strengths while minimizing risks. Rust can be a great fit for performance-critical parts of your application, such as networking and data processing. Once the team sees the benefits of Rust, they will be more open to using it in other parts of the business. Pick a project with a huge upside and one that is easy to replace if things go wrong.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;strong&gt;A microservice&lt;&#x2F;strong&gt; is a good candidate for this. In the worst case, you can rewrite it in another language. You can gradually shift over traffic to the Rust service and see how it performs in production.&lt;&#x2F;p&gt;
&lt;p&gt;However, starting with a &lt;strong&gt;CLI tool&lt;&#x2F;strong&gt; might be easier for the team to manage and understand, even if it is not central to the core business. It can be a quick win and a manageable way to introduce Rust without significant risk, helping the team to see its potential.&lt;&#x2F;p&gt;
&lt;p&gt;Beginning with &lt;strong&gt;WebAssembly&lt;&#x2F;strong&gt; can be challenging due to its complexity. The team might get frustrated with the tooling and ecosystem, and there might not be any immediate benefits, such as faster performance. This could lead to a negative impression of Rust.&lt;&#x2F;p&gt;
&lt;p&gt;I saw some great results with Rust for &lt;strong&gt;embedded systems&lt;&#x2F;strong&gt;, where the tooling is excellent, and there is a clear project boundary. Tools like &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;probe.rs&#x2F;&quot;&gt;probe-rs&lt;&#x2F;a&gt; are often considered best-in-class.&lt;&#x2F;p&gt;
&lt;p&gt;The &lt;strong&gt;FFI layer&lt;&#x2F;strong&gt; is a good choice if you have a large codebase in another language and want to gradually replace parts of it with Rust. For example, some teams rewrite a performance-critical section of their Java monolith in Rust for 2-3x performance improvements. The &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;docs.rs&#x2F;jni&quot;&gt;jni crate&lt;&#x2F;a&gt; allows you to create a compatible library.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;check-the-ecosystem&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#check-the-ecosystem&quot; aria-label=&quot;Anchor link for: check-the-ecosystem&quot;&gt;Check the Ecosystem&lt;&#x2F;a&gt;&lt;&#x2F;h3&gt;
&lt;p&gt;Before starting a Rust project, check the ecosystem for libraries, tools, and resources you will need. Make sure that the libraries are available and well-maintained. Look at the issues and documentation of critical crates for your project. Get familiar with the maintainers. Join the Discord or Matrix channels of the main crates you plan to use. This will give you a good idea of the health of the ecosystem and the community.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;set-standards-for-crates&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#set-standards-for-crates&quot; aria-label=&quot;Anchor link for: set-standards-for-crates&quot;&gt;Set Standards for Crates&lt;&#x2F;a&gt;&lt;&#x2F;h3&gt;
&lt;p&gt;Some companies are fine with using any crate from crates.io, while others are more conservative and only use crates that have been around for a while and have a good reputation. I find &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;blessed.rs&#x2F;&quot;&gt;blessed.rs&lt;&#x2F;a&gt; to be a good resource for finding high-quality crates.&lt;&#x2F;p&gt;
&lt;p&gt;Choosing the right crates can have a big impact on the &lt;a href=&quot;&#x2F;blog&#x2F;long-term-rust-maintenance&#x2F;&quot;&gt;long-term maintainability&lt;&#x2F;a&gt; of your project.&lt;&#x2F;p&gt;
&lt;p&gt;Run &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;docs.rs&#x2F;cargo-audit&#x2F;latest&#x2F;cargo_audit&#x2F;&quot;&gt;cargo-audit&lt;&#x2F;a&gt; regularly to check for security vulnerabilities in your dependencies.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;establish-a-policy-on-async-rust&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#establish-a-policy-on-async-rust&quot; aria-label=&quot;Anchor link for: establish-a-policy-on-async-rust&quot;&gt;Establish a Policy on Async Rust&lt;&#x2F;a&gt;&lt;&#x2F;h3&gt;
&lt;p&gt;Async Rust requires proficiency in the language and can be challenging for beginners. &lt;a href=&quot;&#x2F;blog&#x2F;async&quot;&gt;Navigating the space is hard.&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;p&gt;Establish early on if you want to use async Rust in your project because it can have a big impact on your project. Some companies are fine with using async Rust everywhere, while others use it only when there is no other choice (e.g. the ecosystem does not provide a synchronous alternative).
I saw success in keeping the core of the application synchronous while using async for I&#x2F;O-bound tasks. For example, you could have a lib, which is synchronous and a wrapper around it that is async. This makes testing easier and allows you to use the synchronous lib in other projects.&lt;&#x2F;p&gt;
&lt;p&gt;Either way, establish a policy early on and make sure everyone is on the same page.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;have-a-migration-strategy&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#have-a-migration-strategy&quot; aria-label=&quot;Anchor link for: have-a-migration-strategy&quot;&gt;Have a Migration Strategy&lt;&#x2F;a&gt;&lt;&#x2F;h3&gt;
&lt;p&gt;Answer the following questions before starting the migration:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;What are the milestones for the migration?&lt;&#x2F;li&gt;
&lt;li&gt;How will you handle the transition period? E.g., will you run both systems in parallel?&lt;&#x2F;li&gt;
&lt;li&gt;How will you ensure that the team is productive during the migration?&lt;&#x2F;li&gt;
&lt;li&gt;What is your fallback plan if the migration fails? Can you roll back to the old system?&lt;&#x2F;li&gt;
&lt;li&gt;How will you measure the success of the migration? What are the key metrics?&lt;&#x2F;li&gt;
&lt;li&gt;How will you ensure that the team is productive with the new technology?&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;Document your position on these questions for future reference and to ensure that everyone is on the same page.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;become-an-active-member-of-the-community&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#become-an-active-member-of-the-community&quot; aria-label=&quot;Anchor link for: become-an-active-member-of-the-community&quot;&gt;Become An Active Member Of The Community&lt;&#x2F;a&gt;&lt;&#x2F;h3&gt;
&lt;p&gt;If you’re starting to get serious about Rust, don’t stand on the sidelines! Engage with the Rust community through &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;users.rust-lang.org&#x2F;&quot;&gt;forums&lt;&#x2F;a&gt;, and share your insights on your developer blog. Subscribe to &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;this-week-in-rust.org&#x2F;&quot;&gt;This Week in Rust&lt;&#x2F;a&gt; to stay up-to-date on the latest news and developments in the Rust ecosystem. Keep an eye on the announcements on the &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;blog.rust-lang.org&#x2F;&quot;&gt;Rust blog&lt;&#x2F;a&gt; as well as the &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;foundation.rust-lang.org&#x2F;&quot;&gt;Rust Foundation&lt;&#x2F;a&gt;. Being an active community member can provide valuable support and keep you updated on best practices.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;project-setup&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#project-setup&quot; aria-label=&quot;Anchor link for: project-setup&quot;&gt;Project Setup&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;h3 id=&quot;fully-embrace-rust-tooling&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#fully-embrace-rust-tooling&quot; aria-label=&quot;Anchor link for: fully-embrace-rust-tooling&quot;&gt;Fully Embrace Rust Tooling&lt;&#x2F;a&gt;&lt;&#x2F;h3&gt;
&lt;p&gt;Rust has some of the best tooling in the industry. Make good use of it! Use &lt;code&gt;cargo fmt&lt;&#x2F;code&gt; to format your code, &lt;code&gt;cargo clippy&lt;&#x2F;code&gt; to catch common mistakes, and &lt;code&gt;cargo test&lt;&#x2F;code&gt; or &lt;code&gt;cargo nextest&lt;&#x2F;code&gt; to test your project.&lt;&#x2F;p&gt;
&lt;p&gt;Use &lt;code&gt;rust-analyzer&lt;&#x2F;code&gt; for code completion and &lt;code&gt;rustup&lt;&#x2F;code&gt; to manage your Rust toolchain. There are also many other tools available, such as &lt;code&gt;cargo-watch&lt;&#x2F;code&gt; for automatically recompiling your code when it changes.&lt;&#x2F;p&gt;
&lt;p&gt;For CI&#x2F;CD, consider using GitHub Actions, GitLab CI, or Azure Pipelines. They all have good support for Rust. For GitHub Actions in particular, take a look at &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;dtolnay&#x2F;rust-toolchain&quot;&gt;dtolnay&#x2F;rust-toolchain&lt;&#x2F;a&gt;.
Enforce &lt;code&gt;cargo fmt --check&lt;&#x2F;code&gt; and &lt;code&gt;cargo clippy&lt;&#x2F;code&gt; in your CI pipeline.&lt;&#x2F;p&gt;
&lt;p&gt;Have these tools in place from the start and encourage all team members to
routinely use them while developing. There should be no exceptions.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;consider-an-internal-styleguide&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#consider-an-internal-styleguide&quot; aria-label=&quot;Anchor link for: consider-an-internal-styleguide&quot;&gt;Consider An Internal Styleguide&lt;&#x2F;a&gt;&lt;&#x2F;h3&gt;
&lt;p&gt;You can get pretty far with the above-mentioned tools.
However, one often overlooked aspect is the social side of Rust.
In languages like Python or Go, there typically is one idiomatic way to do things. That makes it easier to work in a group as the code looks coherent between authors and style discussions are reduced to a minimum.&lt;&#x2F;p&gt;
&lt;p&gt;In Rust, that is not the case as there tend to be multiple ways to
solve a problem, which all end up being valid. This can lead to
style discussions and code reviews that are more about personal preference than actual issues. Ultimately, these discussions end up not creating business value
and can be a source of frustration for the team.&lt;&#x2F;p&gt;
&lt;p&gt;Typical areas of churn are:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;Zero-cost abstractions vs. explicitness: are &lt;code&gt;.clone()&lt;&#x2F;code&gt;s okay or should you introduce lifetimes instead?&lt;&#x2F;li&gt;
&lt;li&gt;Generics: when does it make sense to introduce them? How many type parameters are too many?&lt;&#x2F;li&gt;
&lt;li&gt;Static vs dynamic dispatch: is it okay to use &lt;code&gt;Box&amp;lt;dyn Trait&amp;gt;&lt;&#x2F;code&gt; or should you always use &lt;code&gt;impl Trait&lt;&#x2F;code&gt;?&lt;&#x2F;li&gt;
&lt;li&gt;Macros: when are they okay and when should you avoid them? How complex can they get?&lt;&#x2F;li&gt;
&lt;li&gt;Functional vs. imperative style: e.g. when is it okay to use &lt;code&gt;for&lt;&#x2F;code&gt; loops and when should you use iterators?&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;It’s better to be upfront about these decisions and make them explicit.&lt;&#x2F;p&gt;
&lt;p&gt;As the project evolves, try to document your standpoints
on these topics in an internal style guide. This can be as simple as a markdown file in your repository. It will help new team members to get up to speed faster and reduce the amount of churn in code reviews.&lt;&#x2F;p&gt;
&lt;p&gt;Here is my take on the above topics:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;Prefer explicitness over zero-cost abstractions. Only introduce lifetimes when necessary. &lt;code&gt;.clone()&lt;&#x2F;code&gt; is okay most of the time. If not, consider &lt;code&gt;Rc&lt;&#x2F;code&gt; or &lt;code&gt;Arc&lt;&#x2F;code&gt;. Always measure the performance impact before introducing lifetimes.
In general, beginners &lt;a href=&quot;&#x2F;blog&#x2F;lifetimes&#x2F;&quot;&gt;worry about lifetimes too much&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;Generics are okay, but don’t overdo it. If you have more than 3 type parameters, consider if you can reduce them. If not, it might be a sign that your function is doing too much.&lt;&#x2F;li&gt;
&lt;li&gt;Prefer &lt;code&gt;impl Trait&lt;&#x2F;code&gt; over &lt;code&gt;Box&amp;lt;dyn Trait&amp;gt;&lt;&#x2F;code&gt;, but don’t be religious about it.
If a trait object reduces complexity, it’s okay to use it.&lt;&#x2F;li&gt;
&lt;li&gt;Macros are okay for repetitive tasks (such as writing out an &lt;code&gt;impl&lt;&#x2F;code&gt; block for
a long list of types), but avoid them for complex logic. Macros are hard to debug and can lead to cryptic error messages. They are almost like a language within a language.&lt;&#x2F;li&gt;
&lt;li&gt;Use OOP&#x2F;iterative style for global control flow and functional style for local transformations. Get acquainted with iterator patterns, but don’t overdo it. Sometimes a simple &lt;code&gt;for&lt;&#x2F;code&gt; loop is more readable than a chain of iterators.
Read my post on &lt;a href=&quot;&#x2F;blog&#x2F;iterators&quot;&gt;thinking in iterators&lt;&#x2F;a&gt; to learn more.&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;In general, resist the urge to be clever.
Don’t expect everyone on the team to know every Rust feature like higher-level trait bounds or non-trivial lifetimes.
Stuff like &lt;code&gt;impl &amp;lt;T, U, V&amp;gt; SomeTrait for YourType&amp;lt;T, U, V&amp;gt; where T: ....&lt;&#x2F;code&gt;
is challenging to read and understand for most people.&lt;&#x2F;p&gt;
&lt;p&gt;If you have to use advanced features, try to hide them behind a simple interface for the rest of the team.&lt;&#x2F;p&gt;
&lt;p&gt;Don’t underestimate documentation. Perhaps you have a rule that you should always document public structs and functions and you enforce this in your CI pipeline. You can do so by adding &lt;code&gt;#![deny(missing_docs)]&lt;&#x2F;code&gt; at the top of your &lt;code&gt;lib.rs&lt;&#x2F;code&gt; or &lt;code&gt;main.rs&lt;&#x2F;code&gt; and the compiler will refuse to compile code if there is any public item without documentation.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;team-building&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#team-building&quot; aria-label=&quot;Anchor link for: team-building&quot;&gt;Team Building&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;h3 id=&quot;start-with-a-small-team&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#start-with-a-small-team&quot; aria-label=&quot;Anchor link for: start-with-a-small-team&quot;&gt;Start With a Small Team&lt;&#x2F;a&gt;&lt;&#x2F;h3&gt;
&lt;p&gt;Start with a small team of 2-3 developers who are excited about Rust. They will be the pioneers and can help spread the word about Rust within the organization. Once the team has gained experience and confidence and has delivered a minimum viable product (MVP), you can expand the Rust team.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;start-a-team-channel&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#start-a-team-channel&quot; aria-label=&quot;Anchor link for: start-a-team-channel&quot;&gt;Start a Team Channel&lt;&#x2F;a&gt;&lt;&#x2F;h3&gt;
&lt;p&gt;Create a dedicated channel for the Rust team on your company’s communication platform (e.g., Slack, Discord, or Microsoft Teams). This channel can be used to share resources, ask questions, and discuss Rust-related topics. It’s a great way to build a sense of community and encourage knowledge sharing among team members.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;consider-expert-mentorship&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#consider-expert-mentorship&quot; aria-label=&quot;Anchor link for: consider-expert-mentorship&quot;&gt;Consider Expert Mentorship&lt;&#x2F;a&gt;&lt;&#x2F;h3&gt;
&lt;p&gt;Many companies wait too long to get professional help for their Rust projects. Some may have been burned in the past by hiring consultants who didn’t deliver what they promised. Other organizations think they can do it all by themselves, but this often leads to a hard-to-maintain codebase, poor developer experience, frustration, and in the worst case, the discontinuation of the project.&lt;&#x2F;p&gt;
&lt;p&gt;On the other hand, a good instructor can be an accelerator. They can help avoid costly mistakes, ask the hard questions around Rust adoption, and set the team up for success. Hiring consultants can accelerate the exploration process and mitigate risks. Experts can scaffold the project architecture, implement best practices like testing and CI&#x2F;CD, and train the team, ensuring a smooth transition for everyone involved.&lt;&#x2F;p&gt;
&lt;p&gt;Most importantly, bringing in a consultant early in the project can eliminate the “unknown unknowns” for your team and back up your decisions with expert advice.&lt;&#x2F;p&gt;
&lt;p&gt;Many companies fear the cost of hiring consultants. However, clarifying things early on and avoiding costly mistakes can be more economical in the long run. The team will benefit the most early on, starting with a solid foundation.&lt;&#x2F;p&gt;
&lt;p&gt;Even if it turns out that Rust is not the right choice for your project, it’s better to know that sooner rather than later. You can document the reasons which led to this decision and share them with the team for transparency. When the question comes up again in the future, you can refer back to this document and save time.&lt;&#x2F;p&gt;
&lt;div style=&quot;display: flex; justify-content: space-evenly; align-items: stretch; gap: 20px;&quot;&gt;
  &lt;p style=&quot;flex: 1; margin: 0; display: flex; align-items: center;&quot;&gt;
    Think of it like this: if you were to go rock climbing for the first time, would
    you rather have a seasoned climbing partner or go it alone? The guide can
    help you avoid dangerous routes, give you some tips, and make the experience much more
    pleasant for everyone involved.
  &lt;&#x2F;p&gt;
  &lt;img src=&quot;climb.svg&quot; alt=&quot;A good consultant is like a climbing partner or belayer&quot; width=&quot;100&quot; height=&quot;153&quot;&gt;
&lt;&#x2F;div&gt;
&lt;h3 id=&quot;allocate-time-for-learning&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#allocate-time-for-learning&quot; aria-label=&quot;Anchor link for: allocate-time-for-learning&quot;&gt;Allocate Time for Learning&lt;&#x2F;a&gt;&lt;&#x2F;h3&gt;
&lt;p&gt;Once an initial prototype is in place, it’s time to bring on the rest of the team.&lt;&#x2F;p&gt;
&lt;p&gt;The biggest concern about Rust that I hear from engineers is that they are worried they won’t have enough time to properly learn Rust. Set aside dedicated learning time for your team to get up to speed with Rust. Encourage your team to work on small Rust projects or contribute to open-source projects to gain practical experience. It takes around &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;opensource.googleblog.com&#x2F;2023&#x2F;06&#x2F;rust-fact-vs-fiction-5-insights-from-googles-rust-journey-2022.html&quot;&gt;4 months to get comfortable with Rust&lt;&#x2F;a&gt;, so plan accordingly.&lt;&#x2F;p&gt;
&lt;p&gt;This might be a good time to compare Rust workshops and training programs. Some consultancies (like &lt;a href=&quot;&#x2F;&quot;&gt;corrode&lt;&#x2F;a&gt;) offer dedicated Rust training for teams and provide discounts for larger groups. An on-site training can be a great way to kick off your Rust project and get everyone excited about the opportunity to work on the project. Remember to plan some time to schedule the training and to get the budget approved, so reach out to the training provider early.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;learning-resources&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#learning-resources&quot; aria-label=&quot;Anchor link for: learning-resources&quot;&gt;Learning Resources&lt;&#x2F;a&gt;&lt;&#x2F;h3&gt;
&lt;p&gt;No matter how you plan to integrate Rust into your project, make sure to read up on the language and its ecosystem. Here are the best resources I know of right now:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;doc.rust-lang.org&#x2F;book&#x2F;&quot;&gt;The Rust Book&lt;&#x2F;a&gt;: A must-read for every developer on the team. Make sure that everyone on the team gets a copy or reads it online.&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;rust-lang&#x2F;rustlings&quot;&gt;Rustlings&lt;&#x2F;a&gt;: Fun, short exercises to get started with Rust.&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;Which resources I would recommend after that depends on the team’s background and the project’s requirements.
Take a look at this &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;sger&#x2F;RustBooks&quot;&gt;Rust books list&lt;&#x2F;a&gt;, our &lt;a href=&quot;&#x2F;blog&#x2F;rust-learning-resources-2026&#x2F;&quot;&gt;curated Rust learning resources&lt;&#x2F;a&gt;, and resources for &lt;a href=&quot;&#x2F;blog&#x2F;idiomatic-rust-resources&#x2F;&quot;&gt;idiomatic Rust&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;budgeting&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#budgeting&quot; aria-label=&quot;Anchor link for: budgeting&quot;&gt;Budgeting&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;p&gt;To avoid any surprises, it’s essential to plan your budget carefully.
Be aware of the (hidden) costs associated with adopting Rust. And there’s quite a few of them.&lt;&#x2F;p&gt;
&lt;details&gt;
&lt;summary&gt;Click here to expand the list.&lt;&#x2F;summary&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Initial Setup and Planning&lt;&#x2F;strong&gt;&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;Rust exploration and evaluation (conducting surveys, research)&lt;&#x2F;li&gt;
&lt;li&gt;Alignment between stakeholders (meetings, design documents)&lt;&#x2F;li&gt;
&lt;li&gt;Planning and architecture&lt;&#x2F;li&gt;
&lt;li&gt;Feasibility study (proof of concept for your domain)&lt;&#x2F;li&gt;
&lt;li&gt;Transition management (project management resources)&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Opportunity costs&lt;&#x2F;strong&gt;&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;Costs of delaying other projects and features: time spent on Rust could
be devoted to other projects.&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Training and Team Preparation&lt;&#x2F;strong&gt;&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;Training (4 months of dedicated time)&lt;&#x2F;li&gt;
&lt;li&gt;Rust training and resources (books, online courses, conferences)&lt;&#x2F;li&gt;
&lt;li&gt;Mentorship and coaching&lt;&#x2F;li&gt;
&lt;li&gt;Team building activities (team lunches, offsites)&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Hiring and Team Expansion&lt;&#x2F;strong&gt;&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;Staffing costs for Rust developers (recruiting, job postings, onboarding)&lt;&#x2F;li&gt;
&lt;li&gt;Hiring people in infrastructure roles (SREs, DevOps)&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Setup Costs&lt;&#x2F;strong&gt;&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;Project structure&lt;&#x2F;li&gt;
&lt;li&gt;Workflows and tools (IDEs, linters, formatters)&lt;&#x2F;li&gt;
&lt;li&gt;Tooling setup (initial configuration of development environments)&lt;&#x2F;li&gt;
&lt;li&gt;CI&#x2F;CD pipelines&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Development and Implementation&lt;&#x2F;strong&gt;&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;Costs of fast development machines (&lt;a href=&quot;&#x2F;blog&#x2F;tips-for-faster-rust-compile-times&#x2F;&quot;&gt;Rust builds are hardware-intensive&lt;&#x2F;a&gt;)&lt;&#x2F;li&gt;
&lt;li&gt;Development costs (coding, testing, debugging)&lt;&#x2F;li&gt;
&lt;li&gt;Documentation&lt;&#x2F;li&gt;
&lt;li&gt;Writing guidelines and best practices&lt;&#x2F;li&gt;
&lt;li&gt;Code reviews and pair programming (to ensure code quality and knowledge sharing)&lt;&#x2F;li&gt;
&lt;li&gt;Performance tuning (if needed)&lt;&#x2F;li&gt;
&lt;li&gt;Security audits&lt;&#x2F;li&gt;
&lt;li&gt;Compliance and legal reviews (regulations and standards, e.g. GDPR or software licenses)&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Infrastructure and Tooling&lt;&#x2F;strong&gt;&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;Licensing for proprietary tools (rarely needed, but consider it)&lt;&#x2F;li&gt;
&lt;li&gt;Additional hardware during migration (a separate set of infrastructure
for the new system)&lt;&#x2F;li&gt;
&lt;li&gt;Monitoring and alerting tools (tools for monitoring performance
and reliability)&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Ongoing Maintenance and Support&lt;&#x2F;strong&gt;&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;Cloud costs (compute, storage, networking)&lt;&#x2F;li&gt;
&lt;li&gt;Ongoing maintenance costs (monitoring, logging, on-call, CI&#x2F;CD pipelines)&lt;&#x2F;li&gt;
&lt;li&gt;Refactoring and cleaning up technical debt&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Communication and Marketing&lt;&#x2F;strong&gt;&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;Internal communication (presentations)&lt;&#x2F;li&gt;
&lt;li&gt;External communication (blog posts, conference talks)&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Risk Management&lt;&#x2F;strong&gt;&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;Account for the cost of failure&lt;&#x2F;li&gt;
&lt;li&gt;Consider costs of rollback mechanisms&lt;&#x2F;li&gt;
&lt;li&gt;Costs of rollback if the migration fails&lt;&#x2F;li&gt;
&lt;li&gt;Contingency funds (allocating a budget for unforeseen expenses)&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;&#x2F;details&gt;
&lt;div class=&quot;info&quot;&gt;
  
  &lt;div class=&quot;info-header&quot;&gt;
    
      &lt;span class=&quot;icon icon-crab&quot;&gt;&lt;&#x2F;span&gt;
    
    &lt;h4&gt;&lt;p&gt;How Much Will Your Rust Project Cost?&lt;&#x2F;p&gt;
&lt;&#x2F;h4&gt;
  &lt;&#x2F;div&gt;
  
  &lt;p&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;corrode.notion.site&#x2F;862b591975e64a72aba3f8c66e01a3f1&quot;&gt;Here’s my detailed checklist for budgeting Rust projects.&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;p&gt;I use this list to help my clients plan their Rust projects and avoid any surprises. By going through this checklist, you can make sure that you have considered all major costs associated with adopting Rust and have a clear plan for your project.&lt;&#x2F;p&gt;
&lt;p&gt;Feel free to make a copy and adapt it to suit your project’s needs.&lt;&#x2F;p&gt;

&lt;&#x2F;div&gt;
&lt;h2 id=&quot;on-hiring-talent&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#on-hiring-talent&quot; aria-label=&quot;Anchor link for: on-hiring-talent&quot;&gt;On Hiring Talent&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;p&gt;Hiring Rust talent takes time and effort.
This section provides insights into hiring strategies and what to look for in candidates for Rust projects specifically.&lt;&#x2F;p&gt;
&lt;p&gt;For a comprehensive guide on hiring Rust developers, see our dedicated article on &lt;a href=&quot;&#x2F;blog&#x2F;hiring-rust-engineers&#x2F;&quot;&gt;How to Hire Rust Engineers&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;people-with-production-experience-are-hard-to-find-and-expensive&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#people-with-production-experience-are-hard-to-find-and-expensive&quot; aria-label=&quot;Anchor link for: people-with-production-experience-are-hard-to-find-and-expensive&quot;&gt;People with Production Experience Are Hard to Find and Expensive&lt;&#x2F;a&gt;&lt;&#x2F;h3&gt;
&lt;p&gt;It’s challenging to find developers with Rust &lt;em&gt;production&lt;&#x2F;em&gt; experience. Competing with the crypto industry, which heavily uses Rust, makes it even harder. Salaries for Rust developers in crypto can be 2-3 times higher than in other industries, and the pool of talent is small.&lt;&#x2F;p&gt;
&lt;p&gt;Unless you are a hot new startup or have a big budget, finding people with Rust production experience can be challenging and costly. Consider training your own team instead.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;source-talent-from-your-existing-teams-instead&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#source-talent-from-your-existing-teams-instead&quot; aria-label=&quot;Anchor link for: source-talent-from-your-existing-teams-instead&quot;&gt;Source Talent From Your Existing Teams Instead&lt;&#x2F;a&gt;&lt;&#x2F;h3&gt;
&lt;p&gt;Instead of focusing solely on experience, consider finding junior- to mid-level developers who are smart, curious, and eager to learn. From my experience, good candidates often have experience in related areas (like Kotlin or TypeScript) and are known for being quick learners. Place them near your Rust champion or an expert mentor to help them get up to speed quickly.&lt;&#x2F;p&gt;
&lt;p&gt;People in infrastructure roles are also a great fit. Those who tend to have an interest in scalability, performance, and networking can also be great additions to your team. Look for those with previous admin roles, who have worked close to the metal and have a good understanding of how things work under the hood.
These people are often excited to pick up Rust as their background aligns well with the language’s strengths.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;scaling-the-team&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#scaling-the-team&quot; aria-label=&quot;Anchor link for: scaling-the-team&quot;&gt;Scaling The Team&lt;&#x2F;a&gt;&lt;&#x2F;h3&gt;
&lt;p&gt;Once your project reaches a certain level of maturity, you can start hiring Rust developers to scale your team and maintain the project.&lt;&#x2F;p&gt;
&lt;p&gt;Using Rust can be a competitive advantage for smaller companies, as it attracts developers who are excited about the language’s potential. Companies like InfluxData have seen a notable increase in interest from developers after announcing projects involving Rust:&lt;&#x2F;p&gt;
&lt;blockquote&gt;
&lt;p&gt;I announced that we’re working on this new core of the database in November of
2020 in a talk I did. And I said we were hiring and we got a bunch
of inbound interest because of the fact that it was written in Rust.
— Paul Dix, InfluxData&lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
&lt;p&gt;If you’re interested in learning more about hiring Rust developers, don’t miss the season finale of ‘Rust in Production.’ Paul Dix from InfluxData and Micah Wylde from Arroyo share insights on why smaller companies find hiring Rust talent a competitive advantage while larger companies face unique challenges.&lt;&#x2F;p&gt;
&lt;p&gt;Find the section from the episode about hiring Rust engineers &lt;a href=&quot;&#x2F;podcast&#x2F;s01e07-season-finale&#x2F;?t=23%3A06&quot;&gt;here&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;ongoing-maintenance&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#ongoing-maintenance&quot; aria-label=&quot;Anchor link for: ongoing-maintenance&quot;&gt;Ongoing Maintenance&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;p&gt;I wrote a separate &lt;a href=&quot;&#x2F;blog&#x2F;long-term-rust-maintenance&#x2F;&quot;&gt;blog post on long-term Rust maintenance&lt;&#x2F;a&gt;, which might be helpful for you, but here are some specific tips for your first Rust project:&lt;&#x2F;p&gt;
&lt;h3 id=&quot;emphasize-code-reviews-and-pair-programming&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#emphasize-code-reviews-and-pair-programming&quot; aria-label=&quot;Anchor link for: emphasize-code-reviews-and-pair-programming&quot;&gt;Emphasize Code Reviews and Pair Programming&lt;&#x2F;a&gt;&lt;&#x2F;h3&gt;
&lt;p&gt;Code reviews and pair programming are a great way to share knowledge and best practices among team members. Make sure that code reviews are a regular part of your development process and that everyone on the team understands the importance of them.&lt;&#x2F;p&gt;
&lt;p&gt;Consider strategies like &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Mob_programming&quot;&gt;mob programming&lt;&#x2F;a&gt; to get the team up to speed quickly. This can be especially helpful for new team members who are still learning Rust and might be too shy to ask questions in a code review or on a team channel.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;encourage-refactoring&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#encourage-refactoring&quot; aria-label=&quot;Anchor link for: encourage-refactoring&quot;&gt;Encourage Refactoring&lt;&#x2F;a&gt;&lt;&#x2F;h3&gt;
&lt;p&gt;Encourage your team to refactor code regularly to keep it clean and maintainable. Make sure it is a regular part of your development process and that everyone on the team can change the codebase without fear. Unless you work in a safety-critical environment, everyone should be able to make changes to the codebase without asking for permission.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;regularly-review-progress-and-adjust-strategies&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#regularly-review-progress-and-adjust-strategies&quot; aria-label=&quot;Anchor link for: regularly-review-progress-and-adjust-strategies&quot;&gt;Regularly Review Progress and Adjust Strategies&lt;&#x2F;a&gt;&lt;&#x2F;h3&gt;
&lt;p&gt;As you go, adjust your strategies as needed. Make sure that you are hitting your milestones and that the team feels productive.&lt;&#x2F;p&gt;
&lt;p&gt;Some projects have the tendency to become overly complex, so regularly ask newcomers to review the codebase and give feedback on what they find confusing.
Keep the code straightforward and fight abstractions. Focus on being readable, not clever.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;next-steps&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#next-steps&quot; aria-label=&quot;Anchor link for: next-steps&quot;&gt;Next Steps&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;p&gt;By acknowledging the challenges and following these strategies, you can ensure a successful Rust adoption for your first production project. With careful planning and a dedicated team, Rust can drive significant improvements in your organization.&lt;&#x2F;p&gt;
&lt;p&gt;Check out our &lt;a href=&quot;&#x2F;podcast&#x2F;&quot;&gt;‘Rust in Production’ podcast&lt;&#x2F;a&gt; for insights from industry experts on how their teams successfully adopted Rust in production.&lt;&#x2F;p&gt;
&lt;div class=&quot;info&quot;&gt;
  
  &lt;div class=&quot;info-header&quot;&gt;
    
      &lt;span class=&quot;icon icon-info&quot;&gt;&lt;&#x2F;span&gt;
    
    &lt;h4&gt;&lt;p&gt;Need Help with Your Rust Project?&lt;&#x2F;p&gt;
&lt;&#x2F;h4&gt;
  &lt;&#x2F;div&gt;
  
  &lt;p&gt;If you’re considering adopting Rust for your next project, I can help you get started.
&lt;a href=&quot;&#x2F;#contact&quot;&gt;Reach out for a free consultation&lt;&#x2F;a&gt; if you need help with your Rust project. I’m happy to help you get the most out of Rust and guide you through the process.&lt;&#x2F;p&gt;

&lt;&#x2F;div&gt;
</description>
      </item>
      <item>
          <title>Matic</title>
          <pubDate>Thu, 13 Jun 2024 00:00:00 +0000</pubDate>
          <author>Matthias Endler</author>
          <link>https://corrode.dev/podcast/s02e04-matic/</link>
          <guid>https://corrode.dev/podcast/s02e04-matic/</guid>
          <description xml:base="https://corrode.dev/podcast/s02e04-matic/">&lt;div&gt;&lt;script id=&quot;letscast-player-4581d80f&quot; src=&quot;https:&#x2F;&#x2F;letscast.fm&#x2F;podcasts&#x2F;rust-in-production-82281512&#x2F;episodes&#x2F;rust-in-production-ep-11-matic-s-eric-seppanen-d520caf8-fa28-43d4-863e-a3360e1b53d3&#x2F;player.js?size=s&quot;&gt;&lt;&#x2F;script&gt;&lt;&#x2F;div&gt;
&lt;p&gt;The idea of smart robots automating away boring household chores
sounds enticing, yet these devices rarely work as advertised:
they get stuck, they break down, or are security nightmares.
And so it’s refreshing to see a company like Matic taking a
different approach by attempting to build truly smart, reliable,
and privacy-respecting robots. They use Rust for 95% of their codebase,
and use camera vision to navigate, vacuum, and mop floors.&lt;&#x2F;p&gt;
&lt;p&gt;I sit down with Eric Seppanen, Software Engineer at Matic, to learn
about vertical integration in robotics, on-device sensor processing,
large Rust codebases, and why Rust is a great language for the problem space.&lt;&#x2F;p&gt;</description>
      </item>
      <item>
          <title>Thunderbird</title>
          <pubDate>Thu, 30 May 2024 00:00:00 +0000</pubDate>
          <author>Matthias Endler</author>
          <link>https://corrode.dev/podcast/s02e03-thunderbird/</link>
          <guid>https://corrode.dev/podcast/s02e03-thunderbird/</guid>
          <description xml:base="https://corrode.dev/podcast/s02e03-thunderbird/">&lt;div&gt;&lt;script id=&quot;letscast-player-d02c0302&quot; src=&quot;https:&#x2F;&#x2F;letscast.fm&#x2F;podcasts&#x2F;rust-in-production-82281512&#x2F;episodes&#x2F;rust-in-production-ep-10-thunderbird-s-brendan-abolivier&#x2F;player.js?size=s&quot;&gt;&lt;&#x2F;script&gt;&lt;&#x2F;div&gt;
&lt;p&gt;There are probably only a handful of open-source projects that had a bigger
impact on the world than Mozilla Thunderbird. The email client has been around
for over two decades and has been a staple for many users (me included).&lt;&#x2F;p&gt;
&lt;p&gt;Dealing with a legacy codebase that serves millions of users is no easy feat.
The team at MZLA, a subsidiary of Mozilla, has been working hard to modernize
the core of Thunderbird by writing new parts in Rust.&lt;&#x2F;p&gt;
&lt;p&gt;In this episode, I talk to Brendan Abolivier, a software engineer at MZLA, about
the challenges of working on a legacy codebase, the new Rust-based Exchange protocol support, which is the first new protocol in Thunderbird in over a decade, and the future of Thunderbird.&lt;&#x2F;p&gt;</description>
      </item>
      <item>
          <title>Don&#x27;t Worry About Lifetimes</title>
          <pubDate>Wed, 29 May 2024 00:00:00 +0000</pubDate>
          <author>Matthias Endler</author>
          <link>https://corrode.dev/blog/lifetimes/</link>
          <guid>https://corrode.dev/blog/lifetimes/</guid>
          <description xml:base="https://corrode.dev/blog/lifetimes/">&lt;p&gt;When people say that learning Rust is hard, they often mention lifetimes. However, even after seven years of writing Rust, 95% of my code, probably more, doesn’t have any lifetime annotations! It is one of the areas of the language that I definitely worried way too much about when learning Rust, and I see many beginners do the same.&lt;&#x2F;p&gt;
&lt;div class=&quot;info&quot;&gt;
  
  &lt;div class=&quot;info-header&quot;&gt;
    
      &lt;span class=&quot;icon icon-info&quot;&gt;&lt;&#x2F;span&gt;
    
    &lt;h4&gt;&lt;p&gt;Disclaimer: When Lifetimes Really Matter&lt;&#x2F;p&gt;
&lt;&#x2F;h4&gt;
  &lt;&#x2F;div&gt;
  
  &lt;p&gt;The advice in this article is focused on common scenarios. There are cases where you &lt;em&gt;do&lt;&#x2F;em&gt; have to worry about lifetimes.&lt;&#x2F;p&gt;
&lt;p&gt;If you’re working in areas like embedded systems, real-time applications, or other performance-critical environments, you might encounter scenarios where dealing with lifetimes is essential. In such cases, please consult the &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;doc.rust-lang.org&#x2F;nomicon&#x2F;lifetime-elision.html&quot;&gt;section on lifetime elision in the Rustonomicon&lt;&#x2F;a&gt; for more detailed information.&lt;&#x2F;p&gt;

&lt;&#x2F;div&gt;
&lt;h2 id=&quot;what-are-lifetimes&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#what-are-lifetimes&quot; aria-label=&quot;Anchor link for: what-are-lifetimes&quot;&gt;What are lifetimes?&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;p&gt;Lifetimes tell the compiler how long a reference is valid.&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;fn&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; foo&lt;&#x2F;span&gt;&lt;span&gt;&amp;lt;&amp;#39;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;a&lt;&#x2F;span&gt;&lt;span&gt;&amp;gt;(bar&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;: &amp;amp;&lt;&#x2F;span&gt;&lt;span&gt;&amp;#39;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;a str&lt;&#x2F;span&gt;&lt;span&gt;) {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;    &#x2F;&#x2F; ...&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Here, I’m telling the compiler: “this reference &lt;code&gt;bar&lt;&#x2F;code&gt; is valid for the lifetime &lt;code&gt;&#x27;a&lt;&#x2F;code&gt;.” The compiler will then check that the reference is indeed not used after the lifetime &lt;code&gt;&#x27;a&lt;&#x2F;code&gt; ends. If this still sounds like gibberish to you, please continue reading.&lt;&#x2F;p&gt;
&lt;p&gt;Rust has a concept of lifetime &lt;em&gt;elision&lt;&#x2F;em&gt;, which means that you don’t have to write lifetime annotations in most cases; the compiler will infer them for you.&lt;&#x2F;p&gt;
&lt;div class=&quot;info&quot;&gt;
  
  &lt;div class=&quot;info-header&quot;&gt;
    
      &lt;span class=&quot;icon icon-info&quot;&gt;&lt;&#x2F;span&gt;
    
    &lt;h4&gt;&lt;p&gt;Lifetime Elision Recap&lt;&#x2F;p&gt;
&lt;&#x2F;h4&gt;
  &lt;&#x2F;div&gt;
  
  &lt;p&gt;The rules are simple:&lt;&#x2F;p&gt;
&lt;ol&gt;
&lt;li&gt;Every input reference to a function gets a distinct lifetime.&lt;&#x2F;li&gt;
&lt;li&gt;If there’s exactly one input lifetime, it gets applied to all output references.&lt;&#x2F;li&gt;
&lt;li&gt;If there are &lt;em&gt;multiple&lt;&#x2F;em&gt; input lifetimes but one of them is &lt;code&gt;&amp;amp;self&lt;&#x2F;code&gt; or &lt;code&gt;&amp;amp;mut self&lt;&#x2F;code&gt;, then the lifetime of &lt;code&gt;self&lt;&#x2F;code&gt; is applied to all output references.&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;p&gt;That means you only have to write out the lifetimes yourself if you have more than one input lifetime and none of them are &lt;code&gt;&amp;amp;self&lt;&#x2F;code&gt; or &lt;code&gt;&amp;amp;mut self&lt;&#x2F;code&gt;.&lt;&#x2F;p&gt;

&lt;&#x2F;div&gt;
&lt;p&gt;In the example above, we have one input lifetime, so we don’t have to write it out. This is equivalent (and easier on the eyes):&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;fn&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; foo&lt;&#x2F;span&gt;&lt;span&gt;(bar&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;: &amp;amp;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;str&lt;&#x2F;span&gt;&lt;span&gt;) {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;    &#x2F;&#x2F; ...&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;It turns out, lifetimes are &lt;em&gt;everywhere&lt;&#x2F;em&gt; in Rust, but they are just &lt;em&gt;implicit&lt;&#x2F;em&gt; most of the time. That’s a good thing.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;lifetimes-are-contagious&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#lifetimes-are-contagious&quot; aria-label=&quot;Anchor link for: lifetimes-are-contagious&quot;&gt;Lifetimes are contagious!&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;p&gt;The problem with lifetimes is that they spread in your codebase like a virus. Once you add a lifetime annotation, you have to add it to all the functions that call it, and all the functions that call those functions, and so on.&lt;&#x2F;p&gt;
&lt;p&gt;For example, let’s say you have a struct that contains a &lt;code&gt;String&lt;&#x2F;code&gt;:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;struct&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Foo&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    bar&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; String&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;And you want to optimize it by using a &lt;code&gt;&amp;amp;str&lt;&#x2F;code&gt; instead to avoid allocations:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;struct&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Foo&lt;&#x2F;span&gt;&lt;span&gt;&amp;lt;&amp;#39;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;a&lt;&#x2F;span&gt;&lt;span&gt;&amp;gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    bar&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;: &amp;amp;&lt;&#x2F;span&gt;&lt;span&gt;&amp;#39;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;a str&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Now you have to add the lifetime annotation to all the functions that use &lt;code&gt;Foo&lt;&#x2F;code&gt;:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;fn&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; foo&lt;&#x2F;span&gt;&lt;span&gt;&amp;lt;&amp;#39;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;a&lt;&#x2F;span&gt;&lt;span&gt;&amp;gt;(foo&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;: &amp;amp;&lt;&#x2F;span&gt;&lt;span&gt;&amp;#39;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;a Foo&lt;&#x2F;span&gt;&lt;span&gt;) {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;    &#x2F;&#x2F; ...&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;This can get out of hand very quickly. The function signature is now more complex, and it is harder to understand what the function does. Refactoring gets harder because you have to carry over the lifetime annotations. Lifetimes are not free! It’s easy to back yourself into a corner where making fundamental changes to your code becomes difficult. As such, explicit lifetimes should be treated as a last resort because they increase tech debt and alienate beginners.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;reasons-for-lifetimes&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#reasons-for-lifetimes&quot; aria-label=&quot;Anchor link for: reasons-for-lifetimes&quot;&gt;Reasons for lifetimes&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;p&gt;Nowadays, I consider it an anti-pattern to prematurely add lifetime annotations to a piece of code without a good reason. There’s really only two situations where you should add lifetime annotations:&lt;&#x2F;p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;There is a performance bottleneck&lt;&#x2F;strong&gt;: You found a slow piece of code in your hot path, and you have profiled it and determined that the bottleneck is indeed because of allocations. In this case, it could make sense to use lifetimes to avoid allocations. (The alternative is to refactor your code to use a better algorithm to avoid the hot path in the first place.)&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Code that you depend on requires lifetime annotations:&lt;&#x2F;strong&gt; There’s little you can do about this, other than to look for alternatives that don’t require lifetimes.&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;h2 id=&quot;don-t-be-afraid-of-lifetimes-either&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#don-t-be-afraid-of-lifetimes-either&quot; aria-label=&quot;Anchor link for: don-t-be-afraid-of-lifetimes-either&quot;&gt;Don’t Be Afraid Of Lifetimes Either&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;p&gt;What if you depend on a library that requires lifetime annotations?&lt;&#x2F;p&gt;
&lt;p&gt;One example is Servo’s &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;servo&#x2F;html5ever&#x2F;&quot;&gt;&lt;code&gt;html5ever&lt;&#x2F;code&gt;&lt;&#x2F;a&gt;, a high-performance HTML parser written in Rust. It uses lifetimes extensively to ensure memory safety and performance. When using such a library, you have to deal with lifetimes, whether you like it or not. However, understanding the basics of lifetimes can help you navigate these situations more effectively. Remember that lifetimes are there to help you write safe and efficient code. They are not something to be afraid of but rather a powerful tool in your Rust toolbelt.&lt;&#x2F;p&gt;
&lt;p&gt;It’s wise to get comfortable with lifetimes even if you don’t use them often.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;a-practical-example&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#a-practical-example&quot; aria-label=&quot;Anchor link for: a-practical-example&quot;&gt;A Practical Example&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;p&gt;Let’s look at a practical example where lifetimes need to be explicitly added. Consider a function that returns the longest of two string slices.&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;fn&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; longest&lt;&#x2F;span&gt;&lt;span&gt;(x&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;: &amp;amp;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;str&lt;&#x2F;span&gt;&lt;span&gt;, y&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;: &amp;amp;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;str&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; -&amp;gt; &amp;amp;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;str&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    if&lt;&#x2F;span&gt;&lt;span&gt; x&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;len&lt;&#x2F;span&gt;&lt;span&gt;() &amp;gt; y&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;len&lt;&#x2F;span&gt;&lt;span&gt;() {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        x&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    }&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; else&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        y&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;If we tried to compile that, we’d get an error:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;plain&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;error[E0106]: missing lifetime specifier&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt; --&amp;gt; src&#x2F;lib.rs:1:33&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  |&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;1 | fn longest(x: &amp;amp;str, y: &amp;amp;str) -&amp;gt; &amp;amp;str {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  |               ----     ----     ^ expected named lifetime parameter&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  |&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  = help: this function&amp;#39;s return type contains a borrowed value, but the signature does not say whether it is borrowed from `x` or `y`&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;help: consider introducing a named lifetime parameter&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  |&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;1 | fn longest&amp;lt;&amp;#39;a&amp;gt;(x: &amp;amp;&amp;#39;a str, y: &amp;amp;&amp;#39;a str) -&amp;gt; &amp;amp;&amp;#39;a str {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  |           ++++     ++          ++          ++&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;What went wrong?&lt;&#x2F;p&gt;
&lt;h2 id=&quot;put-yourself-into-the-shoes-of-the-compiler&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#put-yourself-into-the-shoes-of-the-compiler&quot; aria-label=&quot;Anchor link for: put-yourself-into-the-shoes-of-the-compiler&quot;&gt;Put Yourself Into the Shoes of the Compiler&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;p&gt;To understand the error, imagine you are the Rust compiler. Your job is to ensure that references are always valid and that no reference outlives the data it points to. In this example, the function &lt;code&gt;longest&lt;&#x2F;code&gt; takes two string slices and returns one of them.&lt;&#x2F;p&gt;
&lt;p&gt;As the compiler, you see that the function signature promises to return a reference (&lt;code&gt;&amp;amp;str&lt;&#x2F;code&gt;), but it doesn’t specify which input reference (&lt;code&gt;x&lt;&#x2F;code&gt; or &lt;code&gt;y&lt;&#x2F;code&gt;) it corresponds to.
We face a dilemma:
Will the returned string live as long as &lt;code&gt;x&lt;&#x2F;code&gt; or &lt;code&gt;y&lt;&#x2F;code&gt;?&lt;&#x2F;p&gt;
&lt;img src=&quot;ferris.svg&quot; alt=&quot;Ferris the crab, the Rust mascot, pondering a dilemma about the function&#x27;s lifetimes&quot; class=&quot;noinvert&quot;&gt;
&lt;p&gt;It depends on which of the two strings is longer and this can only be determined at runtime.&lt;&#x2F;p&gt;
&lt;p&gt;Without this knowledge, you can’t confirm that the returned reference will be valid: You need to specify the &lt;em&gt;relationship&lt;&#x2F;em&gt; between the input and the output to make this guarantee. If you pick the wrong one, you might end up with a dangling reference. The ambiguity makes it impossible for the compiler to guarantee the safety of the returned reference.
You need to provide more information to the compiler to resolve this ambiguity.&lt;&#x2F;p&gt;
&lt;p&gt;To fix this, we need to add a lifetime parameter to the function signature:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;fn&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; longest&lt;&#x2F;span&gt;&lt;span&gt;&amp;lt;&amp;#39;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;a&lt;&#x2F;span&gt;&lt;span&gt;&amp;gt;(x&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;: &amp;amp;&lt;&#x2F;span&gt;&lt;span&gt;&amp;#39;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;a str&lt;&#x2F;span&gt;&lt;span&gt;, y&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;: &amp;amp;&lt;&#x2F;span&gt;&lt;span&gt;&amp;#39;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;a str&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; -&amp;gt; &amp;amp;&lt;&#x2F;span&gt;&lt;span&gt;&amp;#39;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;a str&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    if&lt;&#x2F;span&gt;&lt;span&gt; x&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;len&lt;&#x2F;span&gt;&lt;span&gt;() &amp;gt; y&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;len&lt;&#x2F;span&gt;&lt;span&gt;() {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        x&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    }&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; else&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        y&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;By adding &lt;code&gt;&#x27;a&lt;&#x2F;code&gt;, we specify that both input references &lt;code&gt;x&lt;&#x2F;code&gt; and &lt;code&gt;y&lt;&#x2F;code&gt; have the same lifetime &lt;code&gt;&#x27;a&lt;&#x2F;code&gt;, and the returned reference will also have this lifetime. This makes it clear to the compiler that the returned reference is guaranteed to be valid as long as &lt;em&gt;both&lt;&#x2F;em&gt; input references are valid. Now, the compiler can safely check and ensure that the references are used correctly throughout the code.&lt;&#x2F;p&gt;
&lt;div class=&quot;info&quot;&gt;
  
  &lt;div class=&quot;info-header&quot;&gt;
    
      &lt;span class=&quot;icon icon-info&quot;&gt;&lt;&#x2F;span&gt;
    
    &lt;h4&gt;&lt;p&gt;Side Note: Other Programming Languages&lt;&#x2F;p&gt;
&lt;&#x2F;h4&gt;
  &lt;&#x2F;div&gt;
  
  &lt;p&gt;“Hold on,” you might say, “other programming languages don’t require me to think about lifetimes. Why does Rust make it so complicated?”&lt;&#x2F;p&gt;
&lt;p&gt;The C programming language will happily let you access memory that has been freed, leading to undefined behavior. It will watch in silence as you walk off the edge of a cliff.&lt;&#x2F;p&gt;
&lt;p&gt;Dangling pointers are a common source of bugs, and this is what lifetimes in Rust aim to prevent. The Rust compiler makes you stop and think about the ambiguity in your code and forces you to make relationships between data explicit.&lt;&#x2F;p&gt;
&lt;p&gt;“But what about Python, PHP, or Java? We don’t have to worry about lifetimes there, right?”&lt;&#x2F;p&gt;
&lt;p&gt;Yes, these languages have systems like reference counting or garbage collectors in place, which automatically manage memory for you. There is an overhead to these mechanisms, though. In some restricted environments, like embedded systems or real-time applications, automatic memory management is not even an option because it can introduce unpredictable garbage collector pauses or the environment doesn’t provide a runtime.&lt;&#x2F;p&gt;
&lt;p&gt;Rust’s lifetimes are a way to ensure memory safety without overhead at the small cost of being explicit about lifetimes in the face of ambiguity.&lt;&#x2F;p&gt;

&lt;&#x2F;div&gt;
&lt;h2 id=&quot;lifetimes-as-a-way-to-convey-intent&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#lifetimes-as-a-way-to-convey-intent&quot; aria-label=&quot;Anchor link for: lifetimes-as-a-way-to-convey-intent&quot;&gt;Lifetimes As A Way To Convey Intent&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;p&gt;Part of why lifetimes can look scary is that they are often named &lt;code&gt;&#x27;a&lt;&#x2F;code&gt;, &lt;code&gt;&#x27;b&lt;&#x2F;code&gt;, or &lt;code&gt;&#x27;c&lt;&#x2F;code&gt;. This makes them look like some kind of academic, mathematical notation. That’s just a convention to make them quicker to write, though, and coming up with better names is hard!&lt;&#x2F;p&gt;
&lt;p&gt;It can be helpful to think of lifetimes as “labels” — &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.possiblerust.com&#x2F;pattern&#x2F;naming-your-lifetimes&quot;&gt;you can name them however you want&lt;&#x2F;a&gt; to make your code more understandable. For instance:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;&#x2F;&#x2F; Now it is clear that the processed data is tied to the input data&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;fn&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; process_input&lt;&#x2F;span&gt;&lt;span&gt;&amp;lt;&amp;#39;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;input&lt;&#x2F;span&gt;&lt;span&gt;&amp;gt;(data&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;: &amp;amp;&lt;&#x2F;span&gt;&lt;span&gt;&amp;#39;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;input str&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; -&amp;gt; &amp;amp;&lt;&#x2F;span&gt;&lt;span&gt;&amp;#39;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;input str&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;    &#x2F;&#x2F; ...&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Naming lifetimes can be quite helpful if you need to juggle multiple borrow sources
or when you want to express the origin of a reference more clearly. Serde uses this technique to great effect in its &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;docs.rs&#x2F;serde&#x2F;latest&#x2F;serde&#x2F;trait.Deserialize.html&quot;&gt;&lt;code&gt;Deserialize&lt;&#x2F;code&gt;&lt;&#x2F;a&gt; trait:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;fn&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; deserialize&lt;&#x2F;span&gt;&lt;span&gt;&amp;lt;&amp;#39;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;de&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; D&lt;&#x2F;span&gt;&lt;span&gt;&amp;gt;(deserializer&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; D&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; -&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Result&lt;&#x2F;span&gt;&lt;span&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;font-style: italic;&quot;&gt;Self&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; D&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;Error&lt;&#x2F;span&gt;&lt;span&gt;&amp;gt;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;where&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;    D&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Deserializer&lt;&#x2F;span&gt;&lt;span&gt;&amp;lt;&amp;#39;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;de&lt;&#x2F;span&gt;&lt;span&gt;&amp;gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;{&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;    &#x2F;&#x2F; ...&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Here, &lt;code&gt;&#x27;de&lt;&#x2F;code&gt; means “this lifetime is tied to the deserializer”
or “this thing lives as long as the deserializer does.”
Suddenly, that syntax makes a lot more sense!&lt;&#x2F;p&gt;
&lt;p&gt;If you’re curious, see &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;serde.rs&#x2F;lifetimes.html&quot;&gt;serde’s detailed explanation of deserializer lifetimes &lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;Think of lifetimes as type signatures: most of the time, they can be inferred,
but at times it’s clearer to spell them out to avoid mistakes. Plus, these
explicit annotations double as useful documentation.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;avoiding-lifetimes-with-smart-pointers&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#avoiding-lifetimes-with-smart-pointers&quot; aria-label=&quot;Anchor link for: avoiding-lifetimes-with-smart-pointers&quot;&gt;Avoiding Lifetimes With Smart Pointers&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;p&gt;You might think that you have to introduce a lifetime if you want to avoid
unnecessary copies; for example, when handling a big chunk of data.&lt;&#x2F;p&gt;
&lt;p&gt;However, you can also use smart pointers like &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;doc.rust-lang.org&#x2F;std&#x2F;rc&#x2F;struct.Rc.html&quot;&gt;&lt;code&gt;Rc&lt;&#x2F;code&gt;&lt;&#x2F;a&gt; (reference-counted) or &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;doc.rust-lang.org&#x2F;std&#x2F;sync&#x2F;struct.Arc.html&quot;&gt;&lt;code&gt;Arc&lt;&#x2F;code&gt;&lt;&#x2F;a&gt; (atomic reference-counted) to share ownership of the data. This way, you don’t need to worry about explicit lifetimes while keeping the cost of cloning the data close to zero. It’s a good trade-off in many situations.&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;&#x2F;&#x2F; We only pay for the allocation once&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;let&lt;&#x2F;span&gt;&lt;span&gt; hello&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Rc&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;new&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt;&amp;quot;Hello&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;to_string&lt;&#x2F;span&gt;&lt;span&gt;());&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;&#x2F;&#x2F; This is a cheap operation&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;let&lt;&#x2F;span&gt;&lt;span&gt; hello2&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; hello&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;clone&lt;&#x2F;span&gt;&lt;span&gt;();&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Here’s how you could use &lt;code&gt;Rc&lt;&#x2F;code&gt; to avoid lifetimes in the &lt;code&gt;longest&lt;&#x2F;code&gt; function:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;use&lt;&#x2F;span&gt;&lt;span&gt; std&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span&gt;rc&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;Rc&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;fn&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; longest&lt;&#x2F;span&gt;&lt;span&gt;(x&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Rc&lt;&#x2F;span&gt;&lt;span&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;String&lt;&#x2F;span&gt;&lt;span&gt;&amp;gt;, y&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Rc&lt;&#x2F;span&gt;&lt;span&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;String&lt;&#x2F;span&gt;&lt;span&gt;&amp;gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; -&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Rc&lt;&#x2F;span&gt;&lt;span&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;String&lt;&#x2F;span&gt;&lt;span&gt;&amp;gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    if&lt;&#x2F;span&gt;&lt;span&gt; x&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;len&lt;&#x2F;span&gt;&lt;span&gt;() &amp;gt; y&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;len&lt;&#x2F;span&gt;&lt;span&gt;() {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        x&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    }&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; else&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        y&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;That’s just a silly example (and you’d probably use &lt;code&gt;String&lt;&#x2F;code&gt; anyway in that case), but it shows how you can sidestep lifetimes by using reference-counted pointers.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;when-not-to-use-lifetimes&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#when-not-to-use-lifetimes&quot; aria-label=&quot;Anchor link for: when-not-to-use-lifetimes&quot;&gt;When (Not) To Use Lifetimes&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;p&gt;Sometimes, the compiler is a bit too eager in suggesting lifetimes.
More often than not, the better alternative is to refactor your code.
It might not always be clear how to do this, so here’s a flowchart to help you decide when
lifetime annotations are truly necessary or which refactoring strategies are available.&lt;&#x2F;p&gt;
&lt;img src=&quot;decision-tree.svg&quot; alt=&quot;Flow chart on how to decide on using lifetimes or not&quot;&gt;
&lt;h2 id=&quot;conclusion&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#conclusion&quot; aria-label=&quot;Anchor link for: conclusion&quot;&gt;Conclusion&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;p&gt;All references (borrows) in Rust have lifetimes. The compiler tracks them,
whether they’re explicit or not.&lt;&#x2F;p&gt;
&lt;p&gt;At the start of my Rust journey, I worried way too much about lifetimes. I
thought they were the key to understanding Rust and that I need to master them
to write idiomatic code. But it turns out you don’t need to worry about
lifetimes all that much.&lt;&#x2F;p&gt;
&lt;p&gt;Nowadays, most of my code is free of explicit lifetimes.
I only have to add lifetimes in two kinds of situations: returning references from a function and storing a reference in a struct.&lt;&#x2F;p&gt;
&lt;p&gt;In all other cases, the compiler does a great job of inferring lifetimes
for you, and you should only add them when you have a good reason to do so, i.e.  when the compiler tells you to, when optimizing for performance, or
when you want to explicitly describe the relationships in your code to humans.&lt;&#x2F;p&gt;
</description>
      </item>
      <item>
          <title>AMP</title>
          <pubDate>Thu, 16 May 2024 00:00:00 +0000</pubDate>
          <author>Matthias Endler</author>
          <link>https://corrode.dev/podcast/s02e02-amp/</link>
          <guid>https://corrode.dev/podcast/s02e02-amp/</guid>
          <description xml:base="https://corrode.dev/podcast/s02e02-amp/">&lt;div&gt;&lt;script id=&quot;letscast-player-8087b1dc&quot; src=&quot;https:&#x2F;&#x2F;letscast.fm&#x2F;podcasts&#x2F;rust-in-production-82281512&#x2F;episodes&#x2F;rust-in-production-ep-9-amp-s-carter-schultz&#x2F;player.js?size=s&quot;&gt;&lt;&#x2F;script&gt;&lt;&#x2F;div&gt;
&lt;p&gt;Imagine you’re faced with the challenge to build a system that can handle billions of recyclable items per year
with the goal of being better than a human at identifying what can be recycled.
Material classification is a complex problem that requires a lot of data and a lot of processing power
and it is a cutting-edge field of research.&lt;&#x2F;p&gt;
&lt;p&gt;Carters Schultz and his colleagues at AMP chose Rust to build the core of this system — and it worked “shockingly well”.
In this interview, Carter, charismatic and witty, shares his experience of getting your hands dirty with Rust,
and building a cutting-edge production-ready system, which can be now replicated across the world.&lt;&#x2F;p&gt;</description>
      </item>
      <item>
          <title>Thinking in Iterators</title>
          <pubDate>Wed, 15 May 2024 00:00:00 +0000</pubDate>
          <author>Matthias Endler</author>
          <link>https://corrode.dev/blog/iterators/</link>
          <guid>https://corrode.dev/blog/iterators/</guid>
          <description xml:base="https://corrode.dev/blog/iterators/">&lt;p&gt;Python has this really neat feature called &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;docs.python.org&#x2F;3&#x2F;tutorial&#x2F;datastructures.html#list-comprehensions&quot;&gt;list
comprehensions&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;python&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;# A list of bands&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;bands&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; [&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #E9F284;&quot;&gt;    &amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt;Metallica&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E9F284;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #E9F284;&quot;&gt;    &amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt;Iron Maiden&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E9F284;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #E9F284;&quot;&gt;    &amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt;AC&#x2F;DC&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E9F284;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #E9F284;&quot;&gt;    &amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt;Judas Priest&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E9F284;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #E9F284;&quot;&gt;    &amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt;Megadeth&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E9F284;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;# A list comprehension to filter for bands that start with &amp;quot;M&amp;quot;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;m_bands&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; [band&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; for&lt;&#x2F;span&gt;&lt;span&gt; band&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; in&lt;&#x2F;span&gt;&lt;span&gt; bands&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; if&lt;&#x2F;span&gt;&lt;span&gt; band.startswith(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E9F284;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt;M&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E9F284;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;)]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;# A list comprehension to uppercase the bands&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;uppercased&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; [band.upper()&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; for&lt;&#x2F;span&gt;&lt;span&gt; band&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; in&lt;&#x2F;span&gt;&lt;span&gt; m_bands]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;# We get [&amp;quot;METALLICA&amp;quot;, &amp;quot;MEGADETH&amp;quot;] &lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;List comprehensions are a concise way to create lists from other lists,
but they work with any iterable, like dicts!&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;python&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;books&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #E9F284;&quot;&gt;    &amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt;The Lord of the Rings&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E9F284;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E9F284;&quot;&gt; &amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt;J. R. R. Tolkien&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E9F284;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #E9F284;&quot;&gt;    &amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt;The Hobbit&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E9F284;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E9F284;&quot;&gt; &amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt;J. R. R. Tolkien&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E9F284;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #E9F284;&quot;&gt;    &amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt;Harry Potter&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E9F284;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E9F284;&quot;&gt; &amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt;J. K. Rowling&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E9F284;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;tolkien_books&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; [&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    book&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; for&lt;&#x2F;span&gt;&lt;span&gt; book, author&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; in&lt;&#x2F;span&gt;&lt;span&gt; books.items()&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    if&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E9F284;&quot;&gt; &amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt;Tolkien&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E9F284;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; in&lt;&#x2F;span&gt;&lt;span&gt; author&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;# tolkien_books = [&amp;quot;The Lord of the Rings&amp;quot;, &amp;quot;The Hobbit&amp;quot;]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;As a Pythonista, list comprehensions became second nature to me.
Their elegance is hard to beat. For a long time, I wished Rust had something
similar. It was one of the few things I &lt;em&gt;profoundly&lt;&#x2F;em&gt; missed from Python —
until I learned more about the philosophy behind Rust’s iterator patterns.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;enter-rust-s-iterators&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#enter-rust-s-iterators&quot; aria-label=&quot;Anchor link for: enter-rust-s-iterators&quot;&gt;Enter Rust’s Iterators&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;p&gt;Rust has a notion of &lt;em&gt;chainable operations&lt;&#x2F;em&gt; on iterators, forming a pipeline where
each operation is applied to every element in sequence. Two of the most common
operations are &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;doc.rust-lang.org&#x2F;std&#x2F;iter&#x2F;trait.Iterator.html#method.map&quot;&gt;&lt;code&gt;map&lt;&#x2F;code&gt;&lt;&#x2F;a&gt;, which applies a function to each item, and &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;doc.rust-lang.org&#x2F;std&#x2F;iter&#x2F;trait.Iterator.html#method.filter&quot;&gt;&lt;code&gt;filter&lt;&#x2F;code&gt;&lt;&#x2F;a&gt;, which
selectively includes items that meet a certain condition.&lt;&#x2F;p&gt;
&lt;p&gt;Here’s the equivalent Rust code for the first Python example above:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;let&lt;&#x2F;span&gt;&lt;span&gt; bands&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; vec!&lt;&#x2F;span&gt;&lt;span&gt;[&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt;    &amp;quot;Metallica&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt;    &amp;quot;Iron Maiden&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt;    &amp;quot;AC&#x2F;DC&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt;    &amp;quot;Judas Priest&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt;    &amp;quot;Megadeth&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;];&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;let&lt;&#x2F;span&gt;&lt;span&gt; uppercased&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Vec&lt;&#x2F;span&gt;&lt;span&gt;&amp;lt;_&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; bands&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;iter&lt;&#x2F;span&gt;&lt;span&gt;()&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;                    .&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;filter&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;|&lt;&#x2F;span&gt;&lt;span&gt;band&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;|&lt;&#x2F;span&gt;&lt;span&gt; band&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;starts_with&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt;&amp;quot;M&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;))&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;                    .&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;map&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;|&lt;&#x2F;span&gt;&lt;span&gt;band&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;|&lt;&#x2F;span&gt;&lt;span&gt; band&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;to_uppercase&lt;&#x2F;span&gt;&lt;span&gt;())&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;                    .&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;collect&lt;&#x2F;span&gt;&lt;span&gt;();&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;&#x2F;&#x2F; uppercased = vec![&amp;quot;METALLICA&amp;quot;, &amp;quot;MEGADETH&amp;quot;]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Sure, it’s a tad more verbose than Python’s list comprehensions, but oh, the
versatility!&lt;&#x2F;p&gt;
&lt;p&gt;For example, debugging an iterator chain is as simple as inserting an &lt;code&gt;inspect&lt;&#x2F;code&gt;
wherever you want to peek at the elements:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;let&lt;&#x2F;span&gt;&lt;span&gt; uppercased&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Vec&lt;&#x2F;span&gt;&lt;span&gt;&amp;lt;_&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; bands&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    .&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;iter&lt;&#x2F;span&gt;&lt;span&gt;()&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    .&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;filter&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;|&lt;&#x2F;span&gt;&lt;span&gt;band&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;|&lt;&#x2F;span&gt;&lt;span&gt; band&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;starts_with&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt;&amp;quot;M&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;))&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    .&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;inspect&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;|&lt;&#x2F;span&gt;&lt;span&gt;band&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;|&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; println!&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt;&amp;quot;Found band that starts with M: {band}&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;))&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    .&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;map&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;|&lt;&#x2F;span&gt;&lt;span&gt;band&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;|&lt;&#x2F;span&gt;&lt;span&gt; band&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;to_uppercase&lt;&#x2F;span&gt;&lt;span&gt;())&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    .&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;collect&lt;&#x2F;span&gt;&lt;span&gt;();&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Achieving the same effect with list comprehensions in Python is quite tricky.&lt;&#x2F;p&gt;
&lt;p&gt;I often find myself chaining iterator operations in Rust. And honestly? It’s
pretty intuitive. Over time, I’ve even grown fond of its explicitness. (Or, you know,
maybe it’s just some form of &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Stockholm_syndrome&quot;&gt;Stockholm syndrome&lt;&#x2F;a&gt;.)&lt;&#x2F;p&gt;
&lt;p&gt;What I like the most is the flexibility of this pattern. Let me demonstrate!&lt;&#x2F;p&gt;
&lt;h2 id=&quot;collecting-into-different-types&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#collecting-into-different-types&quot; aria-label=&quot;Anchor link for: collecting-into-different-types&quot;&gt;Collecting into different types&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;p&gt;In Python, you can collect into different types like a &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;docs.python.org&#x2F;3&#x2F;tutorial&#x2F;datastructures.html#sets&quot;&gt;&lt;code&gt;set&lt;&#x2F;code&gt;&lt;&#x2F;a&gt;:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;python&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;tolkien_books&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    book&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; for&lt;&#x2F;span&gt;&lt;span&gt; book, author&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; in&lt;&#x2F;span&gt;&lt;span&gt; books.items()&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    if&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E9F284;&quot;&gt; &amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt;Tolkien&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E9F284;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; in&lt;&#x2F;span&gt;&lt;span&gt; author&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;# It&amp;#39;s a set!&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;# tolkien_books = {&amp;quot;The Lord of the Rings&amp;quot;, &amp;quot;The Hobbit&amp;quot;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Note that the notation is irritatingly different from a list comprehension. Instead of square
brackets, we suddenly use curly braces now.&lt;&#x2F;p&gt;
&lt;p&gt;In contrast, to collect into different types in Rust, just specify the &lt;em&gt;type&lt;&#x2F;em&gt; you want to collect into; easy as cake!&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;let&lt;&#x2F;span&gt;&lt;span&gt; books&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; HashMap&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;from_iter&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;vec!&lt;&#x2F;span&gt;&lt;span&gt;[&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    (&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt;&amp;quot;The Lord of the Rings&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt; &amp;quot;J. R. R. Tolkien&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;),&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    (&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt;&amp;quot;The Hobbit&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt; &amp;quot;J. R. R. Tolkien&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;),&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    (&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt;&amp;quot;Harry Potter&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt; &amp;quot;J. K. Rowling&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;),&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;]);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;&#x2F;&#x2F; Collect into a vector&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;let&lt;&#x2F;span&gt;&lt;span&gt; tolkien_books&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Vec&lt;&#x2F;span&gt;&lt;span&gt;&amp;lt;_&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; books&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    .&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;iter&lt;&#x2F;span&gt;&lt;span&gt;()&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;    &#x2F;&#x2F; Look at the second element of the tuple, which is the author&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    .&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;filter&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;|&lt;&#x2F;span&gt;&lt;span&gt;(_, author)&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;|&lt;&#x2F;span&gt;&lt;span&gt; author&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;contains&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt;&amp;quot;Tolkien&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;))&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;    &#x2F;&#x2F; Now only take the first element of the tuple, which is the book&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    .&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;map&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;|&lt;&#x2F;span&gt;&lt;span&gt;(book, _)&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;|&lt;&#x2F;span&gt;&lt;span&gt; book)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;    &#x2F;&#x2F; Collect into a vector&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    .&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;collect&lt;&#x2F;span&gt;&lt;span&gt;();&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;&#x2F;&#x2F; Alternatively, collect into a set.&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;&#x2F;&#x2F; This works because `collect` can collect into any type that implements&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;&#x2F;&#x2F; `FromIterator`, which `HashSet` does.&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;let&lt;&#x2F;span&gt;&lt;span&gt; tolkien_books&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; HashSet&lt;&#x2F;span&gt;&lt;span&gt;&amp;lt;_&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; books&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    .&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;iter&lt;&#x2F;span&gt;&lt;span&gt;()&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    .&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;filter&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;|&lt;&#x2F;span&gt;&lt;span&gt;(_, author)&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;|&lt;&#x2F;span&gt;&lt;span&gt; author&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;contains&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt;&amp;quot;Tolkien&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;))&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    .&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;map&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;|&lt;&#x2F;span&gt;&lt;span&gt;(book, _)&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;|&lt;&#x2F;span&gt;&lt;span&gt; book)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    .&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;collect&lt;&#x2F;span&gt;&lt;span&gt;();&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;What if we wanted to count the number of bands that start with the same letter?&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;let&lt;&#x2F;span&gt;&lt;span&gt; first_letters&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; HashMap&lt;&#x2F;span&gt;&lt;span&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;char&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; usize&lt;&#x2F;span&gt;&lt;span&gt;&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; bands&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    .&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;iter&lt;&#x2F;span&gt;&lt;span&gt;()&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;    &#x2F;&#x2F; Filter out bands that don&amp;#39;t have a first letter.&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;    &#x2F;&#x2F; (Yes, that&amp;#39;s possible because we accept any string as input.)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;    &#x2F;&#x2F; `filter_map` is like `map` but it filters out `None` values.&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;    &#x2F;&#x2F; If the band is empty, `chars().next()` will return `None`.&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    .&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;filter_map&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;|&lt;&#x2F;span&gt;&lt;span&gt;name&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;|&lt;&#x2F;span&gt;&lt;span&gt; name&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;chars&lt;&#x2F;span&gt;&lt;span&gt;()&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;next&lt;&#x2F;span&gt;&lt;span&gt;())&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;    &#x2F;&#x2F; Start counting the occurrences of each letter&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    .&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;fold&lt;&#x2F;span&gt;&lt;span&gt;(HashMap&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;new&lt;&#x2F;span&gt;&lt;span&gt;(),&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; |mut&lt;&#x2F;span&gt;&lt;span&gt; acc, c&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;|&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;        &#x2F;&#x2F; Use the entry API to insert a new key or increment the value&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;        &#x2F;&#x2F; https:&#x2F;&#x2F;doc.rust-lang.org&#x2F;std&#x2F;collections&#x2F;hash_map&#x2F;enum.Entry.html&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;        &#x2F;&#x2F; Gets the entry for the character `c` and inserts 0 if it&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;        &#x2F;&#x2F; doesn&amp;#39;t exist&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;        *&lt;&#x2F;span&gt;&lt;span&gt;acc&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;entry&lt;&#x2F;span&gt;&lt;span&gt;(c)&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;or_insert&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt;0&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; +=&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt; 1&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        acc&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    });&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;&#x2F;&#x2F; Printing the result&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;for&lt;&#x2F;span&gt;&lt;span&gt; (letter, count)&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; in &amp;amp;&lt;&#x2F;span&gt;&lt;span&gt;first_letters {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;    println!&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt;&amp;quot;{}: {}&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;, letter, count);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Which gives us:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;plain&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;M: 2&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;I: 1&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;A: 1&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;J: 1&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Neat!&lt;&#x2F;p&gt;
&lt;p&gt;In Python, you would probably stop using list comprehensions altogether and
use the builtin &lt;code&gt;Counter&lt;&#x2F;code&gt; for this:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;python&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;from&lt;&#x2F;span&gt;&lt;span&gt; collections&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; import&lt;&#x2F;span&gt;&lt;span&gt; Counter&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;# Note that we handle the case where a band &lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;# is an empty string with the `if len(band)` condition&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;first_letters&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; Counter([band[&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt;0&lt;&#x2F;span&gt;&lt;span&gt;]&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; for&lt;&#x2F;span&gt;&lt;span&gt; band&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; in&lt;&#x2F;span&gt;&lt;span&gt; bands&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; if&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;&quot;&gt; len&lt;&#x2F;span&gt;&lt;span&gt;(band)])&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;That’s another API to learn and remember.&lt;&#x2F;p&gt;
&lt;p&gt;Rust also has a &lt;code&gt;Counter&lt;&#x2F;code&gt; implementation, but it lives outside the standard
library in the &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;crates.io&#x2F;crates&#x2F;counter&quot;&gt;counter&lt;&#x2F;a&gt; crate.
Nevertheless, it fits right in – like a natural extension of the standard library.&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;use&lt;&#x2F;span&gt;&lt;span&gt; counter&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;Counter&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;let&lt;&#x2F;span&gt;&lt;span&gt; first_letters&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Counter&lt;&#x2F;span&gt;&lt;span&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;char&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; usize&lt;&#x2F;span&gt;&lt;span&gt;&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; bands&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    .&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;iter&lt;&#x2F;span&gt;&lt;span&gt;()&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    .&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;filter_map&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;|&lt;&#x2F;span&gt;&lt;span&gt;name&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;|&lt;&#x2F;span&gt;&lt;span&gt; name&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;chars&lt;&#x2F;span&gt;&lt;span&gt;()&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;next&lt;&#x2F;span&gt;&lt;span&gt;())&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    .&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;collect&lt;&#x2F;span&gt;&lt;span&gt;();&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;We still use the same patterns that we used before and we didn’t have
to refactor our code. It was all very seamless.
Again, we just changed the type we collect into!&lt;&#x2F;p&gt;
&lt;p&gt;Such a deep integration into the the iterator API would be much harder,
impossible even, in Python.&lt;&#x2F;p&gt;
&lt;p&gt;In Rust you get the best of both worlds: the flexibility of the ecosystem
and the native feel of the standard library.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;behind-the-scenes-of-collect&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#behind-the-scenes-of-collect&quot; aria-label=&quot;Anchor link for: behind-the-scenes-of-collect&quot;&gt;Behind the Scenes of &lt;code&gt;collect&lt;&#x2F;code&gt;&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;p&gt;The convenience of collecting into a &lt;code&gt;Counter&lt;&#x2F;code&gt; is made possible by the fact that
&lt;code&gt;Counter&lt;&#x2F;code&gt; implements &lt;code&gt;FromIterator&lt;&#x2F;code&gt;.
That’s all the compiler needs to know to be able to use &lt;code&gt;collect&lt;&#x2F;code&gt; with &lt;code&gt;Counter&lt;&#x2F;code&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;Let’s peek behind the curtain and see how it works.&lt;&#x2F;p&gt;
&lt;p&gt;Here is a code snippet from the &lt;code&gt;counter&lt;&#x2F;code&gt; crate:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;impl&lt;&#x2F;span&gt;&lt;span&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;T&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; N&lt;&#x2F;span&gt;&lt;span&gt;&amp;gt; iter&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;FromIterator&lt;&#x2F;span&gt;&lt;span&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;T&lt;&#x2F;span&gt;&lt;span&gt;&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; for&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Counter&lt;&#x2F;span&gt;&lt;span&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;T&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; N&lt;&#x2F;span&gt;&lt;span&gt;&amp;gt;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;where&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;    T&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Hash&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; +&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Eq&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;    N&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; AddAssign&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; +&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Zero&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; +&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; One&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;{&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;    &#x2F;&#x2F;&#x2F; Produce a `Counter` from an iterator of items. This is called automatically&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;    &#x2F;&#x2F;&#x2F; by [`Iterator::collect()`].&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;    &#x2F;&#x2F;&#x2F;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;    &#x2F;&#x2F;&#x2F; [`Iterator::collect()`]:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;    &#x2F;&#x2F;&#x2F; https:&#x2F;&#x2F;doc.rust-lang.org&#x2F;stable&#x2F;std&#x2F;iter&#x2F;trait.Iterator.html#method.collect&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;    &#x2F;&#x2F;&#x2F;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;    &#x2F;&#x2F;&#x2F; ```rust&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;    &#x2F;&#x2F;&#x2F; # use counter::Counter;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;    &#x2F;&#x2F;&#x2F; # use std::collections::HashMap;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;    &#x2F;&#x2F;&#x2F; let counter = &amp;quot;abbccc&amp;quot;.chars().collect::&amp;lt;Counter&amp;lt;_&amp;gt;&amp;gt;();&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;    &#x2F;&#x2F;&#x2F; let expect = [(&amp;#39;a&amp;#39;, 1), (&amp;#39;b&amp;#39;, 2), (&amp;#39;c&amp;#39;, 3)].iter().cloned().collect::&amp;lt;HashMap&amp;lt;_, _&amp;gt;&amp;gt;();&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;    &#x2F;&#x2F;&#x2F; assert_eq!(counter.into_map(), expect);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;    &#x2F;&#x2F;&#x2F; ```&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;    &#x2F;&#x2F;&#x2F;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    fn&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; from_iter&lt;&#x2F;span&gt;&lt;span&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;I&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; IntoIterator&lt;&#x2F;span&gt;&lt;span&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;Item&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; T&lt;&#x2F;span&gt;&lt;span&gt;&amp;gt;&amp;gt;(iter&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; I&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; -&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;font-style: italic;&quot;&gt; Self&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;        Counter&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;T&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; N&lt;&#x2F;span&gt;&lt;span&gt;&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;init&lt;&#x2F;span&gt;&lt;span&gt;(iter)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;You can see that it just calls &lt;code&gt;Counter::init&lt;&#x2F;code&gt; where &lt;code&gt;init&lt;&#x2F;code&gt; is defined as:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;impl&lt;&#x2F;span&gt;&lt;span&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;T&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; N&lt;&#x2F;span&gt;&lt;span&gt;&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Counter&lt;&#x2F;span&gt;&lt;span&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;T&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; N&lt;&#x2F;span&gt;&lt;span&gt;&amp;gt;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;where&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;    T&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Hash&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; +&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Eq&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;    N&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; AddAssign&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; +&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Zero&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; +&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; One&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;{&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;    &#x2F;&#x2F;&#x2F; Create a new `Counter` initialized with the given iterable.&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    pub fn&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; init&lt;&#x2F;span&gt;&lt;span&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;I&lt;&#x2F;span&gt;&lt;span&gt;&amp;gt;(iterable&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; I&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; -&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Counter&lt;&#x2F;span&gt;&lt;span&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;T&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; N&lt;&#x2F;span&gt;&lt;span&gt;&amp;gt;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    where&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;        I&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; IntoIterator&lt;&#x2F;span&gt;&lt;span&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;Item&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; T&lt;&#x2F;span&gt;&lt;span&gt;&amp;gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;        let mut&lt;&#x2F;span&gt;&lt;span&gt; counter&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Counter&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;new&lt;&#x2F;span&gt;&lt;span&gt;();&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        counter&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;update&lt;&#x2F;span&gt;&lt;span&gt;(iterable);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        counter&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;    &#x2F;&#x2F;&#x2F; Add the counts of the elements from the given iterable to this counter.&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    pub fn&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; update&lt;&#x2F;span&gt;&lt;span&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;I&lt;&#x2F;span&gt;&lt;span&gt;&amp;gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;&amp;amp;mut&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;font-style: italic;&quot;&gt; self&lt;&#x2F;span&gt;&lt;span&gt;, iterable&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; I&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    where&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;        I&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; IntoIterator&lt;&#x2F;span&gt;&lt;span&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;Item&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; T&lt;&#x2F;span&gt;&lt;span&gt;&amp;gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;        for&lt;&#x2F;span&gt;&lt;span&gt; item&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; in&lt;&#x2F;span&gt;&lt;span&gt; iterable {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;            let&lt;&#x2F;span&gt;&lt;span&gt; entry&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;font-style: italic;&quot;&gt; self&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span&gt;map&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;entry&lt;&#x2F;span&gt;&lt;span&gt;(item)&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;or_insert_with&lt;&#x2F;span&gt;&lt;span&gt;(N&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span&gt;zero);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;            *&lt;&#x2F;span&gt;&lt;span&gt;entry&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; +=&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; N&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;one&lt;&#x2F;span&gt;&lt;span&gt;();&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;That might look a little intimidating at first, but if you squint, you’ll see that &lt;code&gt;Counter&lt;&#x2F;code&gt; uses a &lt;code&gt;for&lt;&#x2F;code&gt; loop to iterate over the elements of the iterator and also uses the &lt;code&gt;entry&lt;&#x2F;code&gt; API to insert a new key or increment the value; just like we did manually before.&lt;&#x2F;p&gt;
&lt;p&gt;The final, missing piece can be found in the Rust standard library
in the &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;doc.rust-lang.org&#x2F;std&#x2F;iter&#x2F;trait.Iterator.html&quot;&gt;&lt;code&gt;Iterator&lt;&#x2F;code&gt; trait&lt;&#x2F;a&gt;:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;fn&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; collect&lt;&#x2F;span&gt;&lt;span&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;B&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; FromIterator&lt;&#x2F;span&gt;&lt;span&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;font-style: italic;&quot;&gt;Self&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;Item&lt;&#x2F;span&gt;&lt;span&gt;&amp;gt;&amp;gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;font-style: italic;&quot;&gt;self&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; -&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; B&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;where&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #BD93F9;font-style: italic;&quot;&gt;    Self&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Sized&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;{&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;    FromIterator&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;from_iter&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;font-style: italic;&quot;&gt;self&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;As you can see, the &lt;code&gt;collect&lt;&#x2F;code&gt; method is implemented for all types that implement
&lt;code&gt;FromIterator&lt;&#x2F;code&gt; and it’s just a thin wrapper around &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;doc.rust-lang.org&#x2F;std&#x2F;iter&#x2F;trait.FromIterator.html&quot;&gt;&lt;code&gt;FromIterator::from_iter&lt;&#x2F;code&gt;&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;The &lt;code&gt;Counter&lt;&#x2F;code&gt; crate implements &lt;code&gt;FromIterator&lt;&#x2F;code&gt; and therefore we can use
it in combination with &lt;code&gt;collect&lt;&#x2F;code&gt;.
It’s simple and effective — and without knowing all the details, it can
feel like magic.
In reality though, the flexibility is made possible by the trait system and the
iterator API.&lt;&#x2F;p&gt;
&lt;p&gt;If you want to learn more, the &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;coriolinus&#x2F;counter-rs&#x2F;blob&#x2F;master&#x2F;src&#x2F;lib.rs&quot;&gt;&lt;code&gt;counter&lt;&#x2F;code&gt; source
code&lt;&#x2F;a&gt; makes for
an interesting read.&lt;&#x2F;p&gt;
&lt;p&gt;What’s important is that this integration needs to be done only once and then it
can be used by everyone. So as a mere user, you don’t need to know how &lt;code&gt;collect&lt;&#x2F;code&gt;
works, just that it does.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;conclusion&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#conclusion&quot; aria-label=&quot;Anchor link for: conclusion&quot;&gt;Conclusion&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;p&gt;It may be just a personal anecdote, but I feel like more experienced Rust
developers tend to prefer iterators over other methods of iteration like
&lt;code&gt;for&lt;&#x2F;code&gt; loops.&lt;&#x2F;p&gt;
&lt;p&gt;One reason might be that iterators are more versatile because they can be
chained and collected into custom types as we have seen
and they scale well with the complexity of the problem:
at no point are you forced to use a different API or pattern.&lt;&#x2F;p&gt;
&lt;p&gt;Another reason why I like iterator chains is that naming things is hard.
With iterators, you don’t need to come up with a name for the intermediate
steps.&lt;&#x2F;p&gt;
&lt;p&gt;Just do me a favor and don’t create pipelines which are super hard to read.
If the iterator chain is too long, or a step in the chain is longer than a few lines, there’s no shame in breaking
it up into multiple steps.&lt;&#x2F;p&gt;
&lt;p&gt;My hope is that I was able to show you how powerful iterator patterns in Rust
are and they are a powerful stand-in for those list comprehensions you might
know and love from Python.&lt;&#x2F;p&gt;
&lt;p&gt;I encourage you to explore the iterator API in Rust and see how you can use it
to make your code more expressive and concise.&lt;&#x2F;p&gt;
</description>
      </item>
      <item>
          <title>Long-term Rust Project Maintenance</title>
          <pubDate>Mon, 13 May 2024 00:00:00 +0000</pubDate>
          <author>Matthias Endler</author>
          <link>https://corrode.dev/blog/long-term-rust-maintenance/</link>
          <guid>https://corrode.dev/blog/long-term-rust-maintenance/</guid>
          <description xml:base="https://corrode.dev/blog/long-term-rust-maintenance/">&lt;p&gt;Rust has reached a level of maturity where it is being used for critical
infrastructure, replacing legacy systems written in C or C++.
This means, &lt;strong&gt;some Rust projects need to be maintained for years or even decades to come&lt;&#x2F;strong&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;By some estimates, the cost of maintaining a product is more than &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.ncbi.nlm.nih.gov&#x2F;pmc&#x2F;articles&#x2F;PMC3610582&#x2F;&quot;&gt;90% of the
software’s total cost&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;Critical software demands minimal downtime and high reliability, so it is
reassuring that the Rust core team highlights its commitment to these values in
their post &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;blog.rust-lang.org&#x2F;2014&#x2F;10&#x2F;30&#x2F;Stability.html&quot;&gt;“Stability as a
Deliverable.”&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;p&gt;The following is a collection of best practices and advice for maintaining Rust
projects over a very long timeframe. It covers topics like team dynamics, managing dependencies, software architecture, and tooling.&lt;&#x2F;p&gt;
&lt;p&gt;This guide is based on my experience assisting clients with medium to large Rust
projects. While much of the advice may be applicable to other languages, I will emphasize aspects specific to Rust.&lt;&#x2F;p&gt;
&lt;h2&gt;Table of Contents&lt;&#x2F;h2&gt;
&lt;details class=&quot;toc&quot;&gt;
&lt;summary&gt;
Click here to expand the table of contents.
&lt;&#x2F;summary&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;https:&#x2F;&#x2F;corrode.dev&#x2F;blog&#x2F;long-term-rust-maintenance&#x2F;#your-team-needs-to-be-on-board&quot;&gt;Your Team Needs to be On Board&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a href=&quot;https:&#x2F;&#x2F;corrode.dev&#x2F;blog&#x2F;long-term-rust-maintenance&#x2F;#building-for-rust-stability-and-longevity&quot;&gt;Building for Rust Stability and Longevity&lt;&#x2F;a&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;https:&#x2F;&#x2F;corrode.dev&#x2F;blog&#x2F;long-term-rust-maintenance&#x2F;#prefer-stable-rust-over-nightly&quot;&gt;Prefer Stable Rust Over Nightly&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a href=&quot;https:&#x2F;&#x2F;corrode.dev&#x2F;blog&#x2F;long-term-rust-maintenance&#x2F;#regularly-update-your-compiler&quot;&gt;Regularly Update Your Compiler&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a href=&quot;https:&#x2F;&#x2F;corrode.dev&#x2F;blog&#x2F;long-term-rust-maintenance&#x2F;#editions&quot;&gt;Editions&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a href=&quot;https:&#x2F;&#x2F;corrode.dev&#x2F;blog&#x2F;long-term-rust-maintenance&#x2F;#use-rust-language-features-conservatively&quot;&gt;Use Rust Language Features Conservatively&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a href=&quot;https:&#x2F;&#x2F;corrode.dev&#x2F;blog&#x2F;long-term-rust-maintenance&#x2F;#be-conservative-about-async-rust&quot;&gt;Be Conservative About Async Rust&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a href=&quot;https:&#x2F;&#x2F;corrode.dev&#x2F;blog&#x2F;long-term-rust-maintenance&#x2F;#managing-dependencies&quot;&gt;Managing Dependencies&lt;&#x2F;a&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;https:&#x2F;&#x2F;corrode.dev&#x2F;blog&#x2F;long-term-rust-maintenance&#x2F;#dependencies-are-a-liability&quot;&gt;Dependencies are a Liability&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a href=&quot;https:&#x2F;&#x2F;corrode.dev&#x2F;blog&#x2F;long-term-rust-maintenance&#x2F;#limit-the-number-of-dependencies&quot;&gt;Limit The Number Of Dependencies&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a href=&quot;https:&#x2F;&#x2F;corrode.dev&#x2F;blog&#x2F;long-term-rust-maintenance&#x2F;#how-to-choose-dependencies&quot;&gt;How To Choose Dependencies&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a href=&quot;https:&#x2F;&#x2F;corrode.dev&#x2F;blog&#x2F;long-term-rust-maintenance&#x2F;#do-not-pin-dependencies&quot;&gt;Do Not Pin Dependencies&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a href=&quot;https:&#x2F;&#x2F;corrode.dev&#x2F;blog&#x2F;long-term-rust-maintenance&#x2F;#stick-to-std-where-possible&quot;&gt;Stick to &lt;code&gt;std&lt;&#x2F;code&gt; Where Possible&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a href=&quot;https:&#x2F;&#x2F;corrode.dev&#x2F;blog&#x2F;long-term-rust-maintenance&#x2F;#use-stable-dependencies&quot;&gt;Use Stable Dependencies&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a href=&quot;https:&#x2F;&#x2F;corrode.dev&#x2F;blog&#x2F;long-term-rust-maintenance&#x2F;#disable-unnecessary-features&quot;&gt;Disable Unnecessary Features&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a href=&quot;https:&#x2F;&#x2F;corrode.dev&#x2F;blog&#x2F;long-term-rust-maintenance&#x2F;#building-on-solid-foundations&quot;&gt;Building On Solid Foundations&lt;&#x2F;a&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;https:&#x2F;&#x2F;corrode.dev&#x2F;blog&#x2F;long-term-rust-maintenance&#x2F;#software-architecture&quot;&gt;Software Architecture&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a href=&quot;https:&#x2F;&#x2F;corrode.dev&#x2F;blog&#x2F;long-term-rust-maintenance&#x2F;#api-design&quot;&gt;API design&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a href=&quot;https:&#x2F;&#x2F;corrode.dev&#x2F;blog&#x2F;long-term-rust-maintenance&#x2F;#testing&quot;&gt;Testing&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a href=&quot;https:&#x2F;&#x2F;corrode.dev&#x2F;blog&#x2F;long-term-rust-maintenance&#x2F;#documentation&quot;&gt;Documentation&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a href=&quot;https:&#x2F;&#x2F;corrode.dev&#x2F;blog&#x2F;long-term-rust-maintenance&#x2F;#about-unsafe-code&quot;&gt;About Unsafe Code&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a href=&quot;https:&#x2F;&#x2F;corrode.dev&#x2F;blog&#x2F;long-term-rust-maintenance&#x2F;#tooling-and-infrastructure&quot;&gt;Tooling and Infrastructure&lt;&#x2F;a&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;https:&#x2F;&#x2F;corrode.dev&#x2F;blog&#x2F;long-term-rust-maintenance&#x2F;#use-boring-technology&quot;&gt;Use Boring Technology&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a href=&quot;https:&#x2F;&#x2F;corrode.dev&#x2F;blog&#x2F;long-term-rust-maintenance&#x2F;#use-linters-and-formatters&quot;&gt;Use Linters and Formatters&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a href=&quot;https:&#x2F;&#x2F;corrode.dev&#x2F;blog&#x2F;long-term-rust-maintenance&#x2F;#make-releases-boring&quot;&gt;Make Releases Boring&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a href=&quot;https:&#x2F;&#x2F;corrode.dev&#x2F;blog&#x2F;long-term-rust-maintenance&#x2F;#invest-in-the-rust-ecosystem&quot;&gt;Invest in the Rust Ecosystem&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a href=&quot;https:&#x2F;&#x2F;corrode.dev&#x2F;blog&#x2F;long-term-rust-maintenance&#x2F;#stick-to-a-regular-maintenance-schedule&quot;&gt;Stick To A Regular Maintenance Schedule&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a href=&quot;https:&#x2F;&#x2F;corrode.dev&#x2F;blog&#x2F;long-term-rust-maintenance&#x2F;#conclusion&quot;&gt;Conclusion&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;details&gt;
&lt;h2 id=&quot;your-team-needs-to-be-on-board&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#your-team-needs-to-be-on-board&quot; aria-label=&quot;Anchor link for: your-team-needs-to-be-on-board&quot;&gt;Your Team Needs to be On Board&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;p&gt;First, make sure that your team buys into the &lt;a href=&quot;&#x2F;blog&#x2F;why-rust&quot;&gt;decision to use
Rust&lt;&#x2F;a&gt; and that they have the necessary skills to work with the
language.&lt;&#x2F;p&gt;
&lt;p&gt;Introducing Rust is often a disruptive change
and requires a long-term mindset. &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;mainmatter.com&#x2F;blog&#x2F;2023&#x2F;12&#x2F;13&#x2F;rust-adoption-playbook-for-ctos-and-engineering-managers&#x2F;&quot;&gt;It is important to have the backing of both the
team and leadership to make this transition successful.&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;p&gt;On top of that, every language comes with its own set of tools,
libraries, and idioms. It takes time for a team to become proficient in
a new environment, and Rust is well-known for its steep learning curve.&lt;&#x2F;p&gt;
&lt;p&gt;Investing in Rust training and team-augmentation is a good way to accelerate
this process. While it means higher upfront costs, it will pay off in the long run, because the team will feel confident in their ability to maintain the codebase.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;img src=&quot;https:&#x2F;&#x2F;corrode.dev&#x2F;blog&#x2F;long-term-rust-maintenance&#x2F;scale.svg&quot; alt=&quot;Rust Maintenance&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;h2 id=&quot;building-for-rust-stability-and-longevity&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#building-for-rust-stability-and-longevity&quot; aria-label=&quot;Anchor link for: building-for-rust-stability-and-longevity&quot;&gt;Building for Rust Stability and Longevity&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;h3 id=&quot;prefer-stable-rust-over-nightly&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#prefer-stable-rust-over-nightly&quot; aria-label=&quot;Anchor link for: prefer-stable-rust-over-nightly&quot;&gt;Prefer Stable Rust Over Nightly&lt;&#x2F;a&gt;&lt;&#x2F;h3&gt;
&lt;p&gt;Rust has a stable release every six weeks, which brings new features and bug
fixes to the language.&lt;&#x2F;p&gt;
&lt;p&gt;The stable release is the most reliable and well-tested version of Rust.
In contrast, the nightly release is a daily snapshot of the Rust compiler
and is more likely to break your code.&lt;&#x2F;p&gt;
&lt;p&gt;For long-term maintenance, it’s important to stick to the stable release
of Rust if at all possible. This ensures that your code will continue to compile and run without modification, even as the language evolves.&lt;&#x2F;p&gt;
&lt;p&gt;There are only very few cases where nightly Rust is still necessary
and you should carefully evaluate if the benefits outweigh the risks.&lt;&#x2F;p&gt;
&lt;blockquote&gt;
&lt;p&gt;If you are writing code that should live for a while, or a library that is
aimed to be widely used, avoiding nightly features is likely your best bet.
— Andre Bogus in &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;web.archive.org&#x2F;web&#x2F;2022*&#x2F;https:&#x2F;&#x2F;www.getsynth.com&#x2F;docs&#x2F;blog&#x2F;2021&#x2F;10&#x2F;11&#x2F;nightly&quot;&gt;The nightly elephant in the room&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
&lt;h3 id=&quot;regularly-update-your-compiler&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#regularly-update-your-compiler&quot; aria-label=&quot;Anchor link for: regularly-update-your-compiler&quot;&gt;Regularly Update Your Compiler&lt;&#x2F;a&gt;&lt;&#x2F;h3&gt;
&lt;p&gt;Dependencies can specify a minimum version of the Rust compiler they require. Keeping your compiler up-to-date ensures you can use the latest versions of your dependencies.&lt;&#x2F;p&gt;
&lt;p&gt;Additionally, continuous integration tools, like the &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;dtolnay&#x2F;rust-toolchain&quot;&gt;&lt;code&gt;dtolnay&#x2F;rust-toolchain&lt;&#x2F;code&gt;&lt;&#x2F;a&gt; GitHub Action, default to the latest stable Rust version. Therefore, it’s adivsable to keep your compiler current.&lt;&#x2F;p&gt;
&lt;p&gt;Updating your compiler toolchain is simple. Do it regularly:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;shellscript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;rustup&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt; update&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;&lt;h3 id=&quot;editions&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#editions&quot; aria-label=&quot;Anchor link for: editions&quot;&gt;Editions&lt;&#x2F;a&gt;&lt;&#x2F;h3&gt;
&lt;p&gt;An often underrated feature which is not found in other languages is Rust’s &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;doc.rust-lang.org&#x2F;edition-guide&#x2F;editions&#x2F;&quot;&gt;edition
system&lt;&#x2F;a&gt;. It ensures
&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;blog.rust-lang.org&#x2F;2014&#x2F;10&#x2F;30&#x2F;Stability.html#the-plan&quot;&gt;stability without
stagnation&lt;&#x2F;a&gt;:
every three years, a new edition is released, which allows the language to
evolve without breaking existing code. For example, the 2018 edition introduced
the &lt;code&gt;async&lt;&#x2F;code&gt; and &lt;code&gt;await&lt;&#x2F;code&gt; keywords, which are now widely used in Rust codebases;
but code written in the 2015 edition still compiles and runs without
modification. Mixing crates from different editions is
possible as well.&lt;&#x2F;p&gt;
&lt;p&gt;As a result, organizations have time to migrate their codebase to the new
edition at their own pace.&lt;&#x2F;p&gt;
&lt;p&gt;That said, try to keep your codebase up-to-date with the latest edition, as it
will make it easier to benefit from new features and improvements in the
language.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;use-rust-language-features-conservatively&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#use-rust-language-features-conservatively&quot; aria-label=&quot;Anchor link for: use-rust-language-features-conservatively&quot;&gt;Use Rust Language Features Conservatively&lt;&#x2F;a&gt;&lt;&#x2F;h3&gt;
&lt;p&gt;Rust comes with a wealth of powerful features, such as macros, traits,
generics, and lifetimes. While these features can make code more expressive and
efficient, they can also make code harder to read and maintain.&lt;&#x2F;p&gt;
&lt;p&gt;For long-term maintenance, it’s important to be conservative about using
advanced language features. At times, this might come at the cost of
performance or verbosity, but the benefit is code that is easier to understand
by a larger part of the team.&lt;&#x2F;p&gt;
&lt;p&gt;Here are a few examples of conservative use of Rust language features:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Use macros only for boilerplate code&lt;&#x2F;strong&gt;: Macros can be powerful tools for
code generation, but can be hard to read and debug and take a toll on
compile times. Use them sparingly and only for code that is repetitive.
&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;earthly.dev&#x2F;blog&#x2F;rust-macros&#x2F;&quot;&gt;Know When to Use Macros vs. Functions&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Avoid complex trait bounds&lt;&#x2F;strong&gt;: Traits are a common way to abstract over types
in Rust, but complex &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;doc.rust-lang.org&#x2F;rust-by-example&#x2F;generics&#x2F;bounds.html&quot;&gt;trait bounds&lt;&#x2F;a&gt;
can lead to hard-to-understand error messages and obfuscate business logic.
Some code duplication is often preferable to complex trait bounds.&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;clone&lt;&#x2F;code&gt; is fine&lt;&#x2F;strong&gt;: While &lt;code&gt;clone&lt;&#x2F;code&gt; can be a performance bottleneck, it is
often the simplest way to avoid lifetimes and keep code readable.
In many cases, the performance overhead is negligible.
If you are considering to introduce lifetimes to avoid &lt;code&gt;clone&lt;&#x2F;code&gt;, ask yourself
if the added complexity is worth the performance gain.&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;I discussed these and other antipatterns in my talk &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;fosdem.org&#x2F;2024&#x2F;schedule&#x2F;event&#x2F;fosdem-2024-2434-the-four-horsemen-of-bad-rust-code&#x2F;&quot;&gt;The Four Horsemen of Bad
Rust
Code&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;be-conservative-about-async-rust&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#be-conservative-about-async-rust&quot; aria-label=&quot;Anchor link for: be-conservative-about-async-rust&quot;&gt;Be Conservative About Async Rust&lt;&#x2F;a&gt;&lt;&#x2F;h3&gt;
&lt;p&gt;There is one point in particular that is worth calling out in the context of
long-term maintenance in Rust: &lt;strong&gt;keep your core business logic synchronous&lt;&#x2F;strong&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;This ensures that you don’t have to clutter your types with trait bounds like
&lt;code&gt;Send&lt;&#x2F;code&gt; and &lt;code&gt;Sync&lt;&#x2F;code&gt;, and that you can easily test your code without having to
deal with asynchronous runtimes.&lt;&#x2F;p&gt;
&lt;p&gt;Especially in core libraries, it’s important to be conservative about exposing async functions in the public API. This ensures that your library can be used in both synchronous and asynchronous contexts and does not impose a specific runtime on the user.&lt;&#x2F;p&gt;
&lt;p&gt;To learn more about the tradeoffs of the async Rust ecosystem, I recommend reading
&lt;a href=&quot;&#x2F;blog&#x2F;async&#x2F;&quot;&gt;The State of Async Rust&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;managing-dependencies&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#managing-dependencies&quot; aria-label=&quot;Anchor link for: managing-dependencies&quot;&gt;Managing Dependencies&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;h3 id=&quot;dependencies-are-a-liability&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#dependencies-are-a-liability&quot; aria-label=&quot;Anchor link for: dependencies-are-a-liability&quot;&gt;Dependencies are a Liability&lt;&#x2F;a&gt;&lt;&#x2F;h3&gt;
&lt;p&gt;One of the most important aspects of long-term Rust maintenance is being
conservative about dependencies.&lt;&#x2F;p&gt;
&lt;p&gt;Rust has a very active ecosystem, with thousands of crates available on
&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;crates.io&#x2F;&quot;&gt;crates.io&lt;&#x2F;a&gt;, but there is no guarantee that a crate will be
maintained in the long term; and even if it is, you need to &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;tweedegolf.nl&#x2F;en&#x2F;blog&#x2F;104&#x2F;dealing-with-dependencies-in-rust&quot;&gt;trust the team
behind it&lt;&#x2F;a&gt;.
Security fixes in dependencies could take a long time to be released, and &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;marshallpierce&#x2F;rust-base64&#x2F;issues&#x2F;213&quot;&gt;the API of a dependency could change in undesirable ways&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;As a consequence, every dependency should be seen as a liability.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;limit-the-number-of-dependencies&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#limit-the-number-of-dependencies&quot; aria-label=&quot;Anchor link for: limit-the-number-of-dependencies&quot;&gt;Limit The Number Of Dependencies&lt;&#x2F;a&gt;&lt;&#x2F;h3&gt;
&lt;p&gt;Rust’s standard library is intentionally small to avoid issues like those in
Python’s extensive standard library, where certain parts are discouraged from
use:&lt;&#x2F;p&gt;
&lt;blockquote&gt;
&lt;p&gt;Python’s standard library is piling up with cruft, unnecessary duplication of
functionality, and dispensable features. — &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;peps.python.org&#x2F;pep-0594&#x2F;&quot;&gt;PEP 594&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
&lt;p&gt;Rust encourages using small, focused packages called crates, promoting modular development and simplifying the core library’s
maintenance. However, over-reliance on many third-party packages can create
maintenance challenges. &lt;strong&gt;Keep the number of dependencies low&lt;&#x2F;strong&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;Each dependency increases:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;Compile times&lt;&#x2F;li&gt;
&lt;li&gt;Complexity in build scripts and CI&lt;&#x2F;li&gt;
&lt;li&gt;Documentation to read&lt;&#x2F;li&gt;
&lt;li&gt;Attack surface&lt;&#x2F;li&gt;
&lt;li&gt;Etc.&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h3 id=&quot;how-to-choose-dependencies&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#how-to-choose-dependencies&quot; aria-label=&quot;Anchor link for: how-to-choose-dependencies&quot;&gt;How To Choose Dependencies&lt;&#x2F;a&gt;&lt;&#x2F;h3&gt;
&lt;p&gt;Now that we’ve established the importance of limiting dependencies, how do you
choose the right ones? Here are some factors to consider when choosing a crate:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Popularity&lt;&#x2F;strong&gt;: The more popular a crate is, the more likely it is to be
maintained. Check the number of downloads, the number of open
issues, and the last commit date. Here is a list of &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;lib.rs&#x2F;std&quot;&gt;popular Rust
crates&lt;&#x2F;a&gt;.&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;License&lt;&#x2F;strong&gt;: Make sure the crate’s license is compatible with your project’s
license. The most common licenses in the Rust ecosystem are MIT and Apache 2.0, which are both permissive licenses.
However, some crates come with more restrictive licenses, such as GPL or AGPL. These licenses can pose challenges for closed source software projects, as they require you to release your source code if you distribute the software. For open source projects, these licenses can be a viable option, but it’s important to understand the implications for your specific use case.&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Maintenance&lt;&#x2F;strong&gt;: Check the crate’s GitHub repository for signs of active maintenance. Are issues being addressed? Are pull requests being merged? Is the crate following best practices? While it’s important to see activity, keep in mind that a repository with a last commit from a few months ago isn’t necessarily unmaintained, especially for small and stable crates. Prefer crates from well-known community members or companies who have gained trust over time.&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Security&lt;&#x2F;strong&gt;: Make sure the crate has a good security track record and that&lt;br &#x2F;&gt;
the maintainers are responsive to security issues.
Check &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;rustsec.org&#x2F;&quot;&gt;RustSec&lt;&#x2F;a&gt; for known vulnerabilities in Rust crates
before adding them to your project.
Run &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;crates.io&#x2F;crates&#x2F;cargo-audit&quot;&gt;cargo-audit&lt;&#x2F;a&gt; for known vulnerabilities in your dependencies.&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;Take a look at &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;blessed.rs&#x2F;&quot;&gt;blessed.rs&lt;&#x2F;a&gt; for a list of recommended
crates in the Rust ecosystem. Use tools like
&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;doc.rust-lang.org&#x2F;cargo&#x2F;commands&#x2F;cargo-tree.html&quot;&gt;cargo-tree&lt;&#x2F;a&gt; and
&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;est31&#x2F;cargo-udeps&quot;&gt;cargo udeps&lt;&#x2F;a&gt; to find duplicate, outdated,
or unused dependencies.&lt;&#x2F;p&gt;
&lt;p&gt;For a case study on how to reduce the number of dependencies in a real-world
Rust project, read &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.memorysafety.org&#x2F;blog&#x2F;reducing-dependencies-in-sudo&#x2F;&quot;&gt;Sudo-rs dependencies: when less is
better&lt;&#x2F;a&gt; by
Ruben Nijveld from Prossimo.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;do-not-pin-dependencies&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#do-not-pin-dependencies&quot; aria-label=&quot;Anchor link for: do-not-pin-dependencies&quot;&gt;Do Not Pin Dependencies&lt;&#x2F;a&gt;&lt;&#x2F;h3&gt;
&lt;p&gt;A common reaction to hedge the risks of exposing your project to breaking
changes is to pin dependencies to a specific version. While this sounds like a
good idea, it can in fact result in the opposite: a project with outdated
dependencies that are no longer maintained and have known security
vulnerabilities. This is a big maintenance burden.&lt;&#x2F;p&gt;
&lt;p&gt;Instead, it is better to be proactive about keeping dependencies up-to-date:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Use &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;kbknapp&#x2F;cargo-outdated&quot;&gt;&lt;code&gt;cargo outdated&lt;&#x2F;code&gt;&lt;&#x2F;a&gt;&lt;&#x2F;strong&gt;: This command shows you which
dependencies are out of date. Run it regularly to keep track of new versions.&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Automate dependency updates&lt;&#x2F;strong&gt;: Use tools like &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;dependabot.com&#x2F;&quot;&gt;Dependabot&lt;&#x2F;a&gt;
or &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.mend.io&#x2F;renovate&#x2F;&quot;&gt;Renovate&lt;&#x2F;a&gt; to receive automated pull
requests for dependency updates.&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Regularly run &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;doc.rust-lang.org&#x2F;cargo&#x2F;commands&#x2F;cargo-update.html&quot;&gt;&lt;code&gt;cargo update&lt;&#x2F;code&gt;&lt;&#x2F;a&gt;&lt;&#x2F;strong&gt;: It updates your dependencies
to the latest version that matches the version constraints in your &lt;code&gt;Cargo.toml&lt;&#x2F;code&gt;.&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Use &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;doc.rust-lang.org&#x2F;cargo&#x2F;commands&#x2F;cargo-tree.html&quot;&gt;&lt;code&gt;cargo tree&lt;&#x2F;code&gt;&lt;&#x2F;a&gt;&lt;&#x2F;strong&gt;: This shows you a tree of your
dependencies, to help you find duplicate- or outdated dependencies
— including transitive dependencies.&lt;&#x2F;li&gt;
&lt;li&gt;Try not to skip any major versions of your dependencies, as this can make it
harder to upgrade in the future.&lt;&#x2F;li&gt;
&lt;li&gt;Be proactive about replacing deprecated or unmaintained dependencies with a
more recent alternative.&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;For major dependencies (like the web framework or your async runtime) it’s a good idea to follow the release notes or blog posts to stay up-to-date with
upcoming changes. For example, you &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;docs.github.com&#x2F;en&#x2F;account-and-profile&#x2F;managing-subscriptions-and-notifications-on-github&#x2F;managing-subscriptions-for-activity-on-github&#x2F;viewing-your-subscriptions&quot;&gt;can watch for new releases (including the changelog) on GitHub&lt;&#x2F;a&gt; or subscribe to the project’s newsletter.&lt;&#x2F;p&gt;
&lt;p&gt;Keep in mind that it takes time for the broader ecosystem to catch up with new
releases of these major dependencies, so it can take a while before you can
safely upgrade. In such a case, it’s a good idea to add regular reminders to
your calendar to handle the upgrade.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;stick-to-std-where-possible&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#stick-to-std-where-possible&quot; aria-label=&quot;Anchor link for: stick-to-std-where-possible&quot;&gt;Stick to &lt;code&gt;std&lt;&#x2F;code&gt; Where Possible&lt;&#x2F;a&gt;&lt;&#x2F;h3&gt;
&lt;p&gt;The Rust standard library is well-maintained and has a strong focus on backwards
compatibility. It is a good idea to stick to &lt;code&gt;std&lt;&#x2F;code&gt; where possible.&lt;&#x2F;p&gt;
&lt;p&gt;For example, the &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;doc.rust-lang.org&#x2F;std&#x2F;collections&#x2F;&quot;&gt;&lt;code&gt;std::collections&lt;&#x2F;code&gt;&lt;&#x2F;a&gt; module provides a good selection of data
structures, such as &lt;code&gt;HashMap&lt;&#x2F;code&gt;, &lt;code&gt;Vec&lt;&#x2F;code&gt;, and &lt;code&gt;HashSet&lt;&#x2F;code&gt;, which are well-tested.
While there are great third-party crates that provide similar data structures,
which might be faster or have additional features, it is often better to stick
to the standard library, as it is used by a wide range of projects and
guaranteed to be maintained in the long term.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;use-stable-dependencies&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#use-stable-dependencies&quot; aria-label=&quot;Anchor link for: use-stable-dependencies&quot;&gt;Use Stable Dependencies&lt;&#x2F;a&gt;&lt;&#x2F;h3&gt;
&lt;p&gt;Crates which &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;doc.rust-lang.org&#x2F;cargo&#x2F;reference&#x2F;semver.html&quot;&gt;follow
semver&lt;&#x2F;a&gt; and reach version
1.0 are considered stable and should be preferred over non-stable crates. This
is because crates below version 1.0 are allowed to make breaking changes in
minor versions, which can lead to unexpected breakage in your project.&lt;&#x2F;p&gt;
&lt;p&gt;Since the Rust ecosystem is still relatively young, many crates have not reached
a stable 1.0 version release yet. Nonetheless, it is a good idea to prefer
stable crates over unstable ones where possible.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;disable-unnecessary-features&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#disable-unnecessary-features&quot; aria-label=&quot;Anchor link for: disable-unnecessary-features&quot;&gt;Disable Unnecessary Features&lt;&#x2F;a&gt;&lt;&#x2F;h3&gt;
&lt;p&gt;Many crates offer optional features that can be enabled or disabled. These
features can add additional functionality to the crate, but they can also
increase compile times and the complexity of the crate. If you don’t need a
feature, it’s a good idea to disable it.
You can find the available features in the crate’s &lt;code&gt;Cargo.toml&lt;&#x2F;code&gt; file or on the
crate’s documentation page.
For example, &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;docs.rs&#x2F;crate&#x2F;tokio&#x2F;latest&#x2F;features&quot;&gt;here are the &lt;code&gt;tokio&lt;&#x2F;code&gt; features&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;div class=&quot;info&quot;&gt;
  
  &lt;div class=&quot;info-header&quot;&gt;
    
      &lt;span class=&quot;icon icon-info&quot;&gt;&lt;&#x2F;span&gt;
    
    &lt;h4&gt;&lt;p&gt;Pro Tip: Quickly Discovering Unnecessary Features&lt;&#x2F;p&gt;
&lt;&#x2F;h4&gt;
  &lt;&#x2F;div&gt;
  
  &lt;p&gt;A nice trick is to use the &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;doc.rust-lang.org&#x2F;cargo&#x2F;reference&#x2F;features.html#the-default-feature&quot;&gt;&lt;code&gt;default-features = false&lt;&#x2F;code&gt;&lt;&#x2F;a&gt; option for each dependency in your
&lt;code&gt;Cargo.toml&lt;&#x2F;code&gt;, which disables all features, which are enabled by default.&lt;&#x2F;p&gt;
&lt;p&gt;This way you can inspect which features are crucial for your project and
carefully add them back one by one. It’s a good way to avoid unnecessary
bloat.&lt;&#x2F;p&gt;
&lt;p&gt;For example:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;toml&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;[&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;&quot;&gt;dependencies&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #8BE9FD;&quot;&gt;flate2&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;&quot;&gt; version&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E9F284;&quot;&gt; &amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt;1.0.30&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E9F284;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;&quot;&gt; default-features&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt; false&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;&quot;&gt; features&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; [&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E9F284;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt;zlib&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E9F284;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;] }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;&#x2F;div&gt;
&lt;h2 id=&quot;building-on-solid-foundations&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#building-on-solid-foundations&quot; aria-label=&quot;Anchor link for: building-on-solid-foundations&quot;&gt;Building On Solid Foundations&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;h3 id=&quot;software-architecture&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#software-architecture&quot; aria-label=&quot;Anchor link for: software-architecture&quot;&gt;Software Architecture&lt;&#x2F;a&gt;&lt;&#x2F;h3&gt;
&lt;p&gt;Conversely, maintaining a codebase for a long time &lt;em&gt;doesn’t&lt;&#x2F;em&gt; mean you should leave
it untouched; quite the opposite: it requires constant effort and work.&lt;&#x2F;p&gt;
&lt;p&gt;Some of the most robust codebases in the world are continuously updated.
Projects like the Linux kernel, which has been in development for over 30 years,
or Mozilla Firefox, are constantly being improved and refactored.&lt;&#x2F;p&gt;
&lt;p&gt;Here are some principles for durable software design:&lt;&#x2F;p&gt;
&lt;ol&gt;
&lt;li&gt;Learn about &lt;a href=&quot;&#x2F;blog&#x2F;idiomatic-rust-resources&quot;&gt;idiomatic Rust&lt;&#x2F;a&gt; and follow the best practices of the Rust community.&lt;&#x2F;li&gt;
&lt;li&gt;Heavily lean into the type system: prefer a type-first design, where you use the &lt;a href=&quot;&#x2F;blog&#x2F;compile-time-invariants&quot;&gt;type system to enforce invariants&lt;&#x2F;a&gt; and prevent bugs. For example, here is how to &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;cliffle.com&#x2F;blog&#x2F;rust-typestate&#x2F;&quot;&gt;use the typestate pattern to guarantee object behavior at compile-time&lt;&#x2F;a&gt;.&lt;&#x2F;li&gt;
&lt;li&gt;Don’t be afraid to take ownership: refactor and rewrite where necessary. Rust makes it &lt;em&gt;easy&lt;&#x2F;em&gt; to refactor and you should take advantage of that.&lt;&#x2F;li&gt;
&lt;li&gt;Strive for &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;highassurance.rs&#x2F;chp16_appendix&#x2F;components.html&quot;&gt;low coupling and high cohesion&lt;&#x2F;a&gt; between your modules and crates.
&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Coupling_(computer_programming)&quot;&gt;&lt;img src=&quot;https:&#x2F;&#x2F;corrode.dev&#x2F;blog&#x2F;long-term-rust-maintenance&#x2F;CouplingVsCohesion.svg&quot; alt=&quot;Low coupling and high cohesion&quot; &#x2F;&gt;&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;Learn about &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;rust-unofficial.github.io&#x2F;patterns&#x2F;additional_resources&#x2F;design-principles.html&quot;&gt;design principles such as SOLID&lt;&#x2F;a&gt;.&lt;&#x2F;li&gt;
&lt;li&gt;Avoid premature optimization and over-engineering.&lt;&#x2F;li&gt;
&lt;li&gt;Consider &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;doc.rust-cqrs.org&#x2F;theory_ddd.html&quot;&gt;Domain-driven design&lt;&#x2F;a&gt;. It is a way to express your business logic in a common business language that everyone on the team understands.&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;alexis-lozano.com&#x2F;hexagonal-architecture-in-rust-1&#x2F;&quot;&gt;Study hexagonal architecture&lt;&#x2F;a&gt; (a.k.a onion Architecture or ‘Ports and Adapters’). This architecture separates the core business logic from the infrastructure, making it easier to test and maintain.&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;p&gt;The Rust ecosystem continues to develop, with new frameworks frequently being introduced. To avoid chasing a moving target, it’s a good idea to keep the core of your application framework-agnostic. This way, you can replace your web framework or UI layer without having to rewrite the entire application.
The above mentioned design principles can help you with that.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;api-design&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#api-design&quot; aria-label=&quot;Anchor link for: api-design&quot;&gt;API design&lt;&#x2F;a&gt;&lt;&#x2F;h3&gt;
&lt;p&gt;API design is part of software architecture, but it deserves its own section.&lt;&#x2F;p&gt;
&lt;p&gt;Software that gets maintained for a long time is often critical and heavily used
by other software. Changing an API can break downstream users and cause churn.
Defensive API design minimizes the risk of these breaking changes.&lt;&#x2F;p&gt;
&lt;p&gt;Here are some tips for designing APIs that stand the test of time:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Minimize the public API surface&lt;&#x2F;strong&gt;:
It’s very hard to remove features once they are public. Only expose what is
absolutely necessary for users to interact with your system. While this sounds
obvious, it’s easy to expose too much in a public API. Keeping functions and
structs private prevents implementation details from leaking out of modules,
making future refactoring easier since you can change the internals without
affecting the public API.&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Consider making enums non-exhaustive&lt;&#x2F;strong&gt;: For enums that may introduce new variants in the future, use the &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;doc.rust-lang.org&#x2F;reference&#x2F;attributes&#x2F;type_system.html&quot;&gt;&lt;code&gt;#[non_exhaustive]&lt;&#x2F;code&gt;&lt;&#x2F;a&gt; attribute. This allows adding new variants without breaking existing code. However, this approach encourages catch-all patterns, which can be problematic if new variants require specific handling. Use &lt;code&gt;non_exhaustive&lt;&#x2F;code&gt; only if a catch-all pattern is acceptable. If your enum represents a fixed set of options with no foreseeable additions, it’s better to keep it exhaustive. Breaking changes in such cases ensure the code is updated to handle new cases explicitly, maintaining correctness and clarity. (See this &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;hyperium&#x2F;http&#x2F;issues&#x2F;188&quot;&gt;discussion in the hyperium&#x2F;http crate&lt;&#x2F;a&gt;.)&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Hide implementation details behind own types&lt;&#x2F;strong&gt;: Use the &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;rust-unofficial.github.io&#x2F;patterns&#x2F;patterns&#x2F;behavioural&#x2F;newtype.html#motivation&quot;&gt;newtype
pattern&lt;&#x2F;a&gt;
to hide implementation details and prevent users from relying on them. For
example, instead of exposing that you depend on a specific crate, wrap it in a
newtype, so use &lt;code&gt;pub Request(reqwest::Request)&lt;&#x2F;code&gt; instead of exposing the
dependency directly.
Don’t be afraid to introduce your own types around basic types. E.g. &lt;code&gt;Miles(u64)&lt;&#x2F;code&gt; and &lt;code&gt;Kilometers(u64)&lt;&#x2F;code&gt; are both &lt;code&gt;u64&lt;&#x2F;code&gt; under the hood, but
their explicit types make it harder to mix them up.&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Use semver&lt;&#x2F;strong&gt;: Follow the &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;semver.org&#x2F;&quot;&gt;Semantic Versioning&lt;&#x2F;a&gt; guidelines to communicate changes to your users. This will help them understand the impact of a new release and make it easier to upgrade. Consider using &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;obi1kenobi&#x2F;cargo-semver-checks&quot;&gt;cargo-semver-checks&lt;&#x2F;a&gt; to detect breaking changes in your code.&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;For more information, the Rust team has published a &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;rust-lang.github.io&#x2F;api-guidelines&#x2F;checklist.html&quot;&gt;Rust API Guidelines
Checklist&lt;&#x2F;a&gt;, which is
well worth a read.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;testing&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#testing&quot; aria-label=&quot;Anchor link for: testing&quot;&gt;Testing&lt;&#x2F;a&gt;&lt;&#x2F;h3&gt;
&lt;p&gt;Tests are a form of documentation that gets verified automatically.
If you have a hard time writing tests, it’s a sign that your code is too
complex and needs refactoring. If you can’t explain what a struct or function
does, it might do too much. Split it up into smaller parts and test those parts
individually.&lt;&#x2F;p&gt;
&lt;p&gt;In Rust, unit tests reside alongside the code within the same module, which is
where the majority of testing should happen.&lt;&#x2F;p&gt;
&lt;p&gt;Make sure that the tests are easy to run without any manual setup (ideally, just
a &lt;code&gt;cargo test&lt;&#x2F;code&gt; should be enough), and that they run quickly (think seconds, not minutes)
and mostly without external dependencies. If tests are slow, they won’t be run
as often, and you’ll lose the benefits of having them. Integrate your tests into
a continuous integration pipeline on GitHub Actions or GitLab CI to ensure that
they run automatically on every commit.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;documentation&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#documentation&quot; aria-label=&quot;Anchor link for: documentation&quot;&gt;Documentation&lt;&#x2F;a&gt;&lt;&#x2F;h3&gt;
&lt;p&gt;Rust has great support for documentation.
You can write documentation as Markdown comments right next to your code, and
it gets rendered into a nice HTML page with &lt;code&gt;cargo doc&lt;&#x2F;code&gt;.
Make extensive use of this!&lt;&#x2F;p&gt;
&lt;p&gt;Here are some tips for writing good documentation:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;Don’t expect to be around to explain your code. Even if you are, you might not
remember why you wrote something a certain way.&lt;&#x2F;li&gt;
&lt;li&gt;It’s easiest to write documentation as soon as you start writing code. Update it as
your mental model of the code evolves.&lt;&#x2F;li&gt;
&lt;li&gt;Take the time to document, why certain optimizations were &lt;em&gt;not&lt;&#x2F;em&gt; done and the
trade-offs of your design decisions.&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;Some tooling can help you with this:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;Enforce documentation for public functions and types with clippy’s &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;doc.rust-lang.org&#x2F;rustdoc&#x2F;write-documentation&#x2F;what-to-include.html&quot;&gt;&lt;code&gt;#![deny(missing_docs)]&lt;&#x2F;code&gt;&lt;&#x2F;a&gt; lint.&lt;&#x2F;li&gt;
&lt;li&gt;Run &lt;code&gt;cargo doc --open&lt;&#x2F;code&gt; from time to time to see how your documentation looks like
and fill in the gaps.&lt;&#x2F;li&gt;
&lt;li&gt;Add doctests to your documentation. This way, you can ensure that the examples
in your documentation are correct and up-to-date.&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;frehberg.com&#x2F;2022&#x2F;12&#x2F;docs-as-code-mermaid-inline-diagrams&#x2F;&quot;&gt;Add mermaid diagrams to your documentation&lt;&#x2F;a&gt; to visualize complex concepts.&lt;&#x2F;li&gt;
&lt;li&gt;Use &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;GuillaumeGomez&#x2F;doc-comment&quot;&gt;doc-comment&lt;&#x2F;a&gt; to ensure that your examples in the &lt;code&gt;README.md&lt;&#x2F;code&gt; are up-to-date.&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;As an example, here is the documentation for the &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;docs.rs&#x2F;axum&#x2F;latest&#x2F;axum&quot;&gt;Axum web framework&lt;&#x2F;a&gt;, which is generated from comments in the code:&lt;&#x2F;p&gt;
&lt;p&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;docs.rs&#x2F;axum&#x2F;latest&#x2F;axum&#x2F;&quot;&gt;&lt;img src=&quot;https:&#x2F;&#x2F;corrode.dev&#x2F;blog&#x2F;long-term-rust-maintenance&#x2F;axum-docs.png&quot; alt=&quot;Axum Documentation&quot; &#x2F;&gt;&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;p&gt;Here are the things I like about this introduction:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;input disabled=&quot;&quot; type=&quot;checkbox&quot; checked=&quot;&quot;&#x2F;&gt;
It’s approachable and easy to read.&lt;&#x2F;li&gt;
&lt;li&gt;&lt;input disabled=&quot;&quot; type=&quot;checkbox&quot; checked=&quot;&quot;&#x2F;&gt;
It immediately shows how to use the library for simple, real-world scenarios.&lt;&#x2F;li&gt;
&lt;li&gt;&lt;input disabled=&quot;&quot; type=&quot;checkbox&quot; checked=&quot;&quot;&#x2F;&gt;
It explains core concepts and how they relate to each other.&lt;&#x2F;li&gt;
&lt;li&gt;&lt;input disabled=&quot;&quot; type=&quot;checkbox&quot; checked=&quot;&quot;&#x2F;&gt;
It provides links to more detailed information.&lt;&#x2F;li&gt;
&lt;li&gt;&lt;input disabled=&quot;&quot; type=&quot;checkbox&quot; checked=&quot;&quot;&#x2F;&gt;
It includes a table of contents for easy navigation.&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;If you feel intrigued, &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;blog.guillaume-gomez.fr&#x2F;articles&#x2F;2020-03-12+Guide+on+how+to+write+documentation+for+a+Rust+crate&quot;&gt;here is a great guide on how to write documentation in Rust&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;about-unsafe-code&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#about-unsafe-code&quot; aria-label=&quot;Anchor link for: about-unsafe-code&quot;&gt;About Unsafe Code&lt;&#x2F;a&gt;&lt;&#x2F;h3&gt;
&lt;p&gt;Unsafe code relies on the author to ensure its correctness and adherence to
current and future rules. Due to the inherent complexity, errors in unsafe
code are typically difficult to detect and debug.&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;Minimize the use of unsafe code and encapsulate it in a safe API. This way,
the unsafe code can at least be isolated and its behavior can be more easily
understood and tested.&lt;&#x2F;li&gt;
&lt;li&gt;If you find yourself using unsafe code to improve performance, consider using
better algorithms or data structures instead. Rust’s performance is often
competitive with C and C++ without resorting to unsafe code.
See &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.youtube.com&#x2F;watch?v=uUu9eFNNbjg&quot;&gt;this video on datastructures in the Zed Text Editor, which shows how
&lt;code&gt;Rope&lt;&#x2F;code&gt;s and &lt;code&gt;SumTree&lt;&#x2F;code&gt;s get used for performant and safe code&lt;&#x2F;a&gt;.&lt;&#x2F;li&gt;
&lt;li&gt;Use &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;geiger-rs&#x2F;cargo-geiger&quot;&gt;cargo-geiger&lt;&#x2F;a&gt; to check for
unsafe code.&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;&lt;img src=&quot;https:&#x2F;&#x2F;corrode.dev&#x2F;blog&#x2F;long-term-rust-maintenance&#x2F;cargo-geiger.png&quot; alt=&quot;cargo-geiger&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;h2 id=&quot;tooling-and-infrastructure&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#tooling-and-infrastructure&quot; aria-label=&quot;Anchor link for: tooling-and-infrastructure&quot;&gt;Tooling and Infrastructure&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;h3 id=&quot;use-boring-technology&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#use-boring-technology&quot; aria-label=&quot;Anchor link for: use-boring-technology&quot;&gt;Use Boring Technology&lt;&#x2F;a&gt;&lt;&#x2F;h3&gt;
&lt;p&gt;Based on personal experience, the latest technology can be tempting, but for long-term codebase maintenance in a production environment, it’s wise to use reliable, well-established tools like JSON and SQL. These tools offer abundant documentation and support, making it easier to find help when needed.&lt;&#x2F;p&gt;
&lt;p&gt;The same principle applies when choosing Virtual Machines or Containers over newer options like WebAssembly or Edge Computing, as the former have more providers and established ecosystems.&lt;&#x2F;p&gt;
&lt;p&gt;Overall, proven technologies change less frequently, allowing you to focus on your business rather than constantly chasing the latest trends.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;use-linters-and-formatters&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#use-linters-and-formatters&quot; aria-label=&quot;Anchor link for: use-linters-and-formatters&quot;&gt;Use Linters and Formatters&lt;&#x2F;a&gt;&lt;&#x2F;h3&gt;
&lt;p&gt;There are a number of well-established tools that can help you maintain a
consistent code style and catch common errors:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;rust-lang&#x2F;rustfmt&quot;&gt;rustfmt&lt;&#x2F;a&gt; formats your code according to
the Rust style guidelines.&lt;&#x2F;p&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;
&lt;p&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;doc.rust-lang.org&#x2F;clippy&#x2F;&quot;&gt;clippy&lt;&#x2F;a&gt; is a collection of lints to catch
common mistakes and improve your code.&lt;&#x2F;p&gt;
&lt;p&gt;I use the most pedantic clippy settings in my projects.
To enable them, add the following lines to the top of your &lt;code&gt;main.rs&lt;&#x2F;code&gt; or &lt;code&gt;lib.rs&lt;&#x2F;code&gt;:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;#![deny(clippy&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span&gt;all)]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;#![warn(clippy&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span&gt;pedantic)]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;#![warn(clippy&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span&gt;restriction)]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;#![warn(clippy&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span&gt;nursery)]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;#![warn(clippy&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span&gt;cargo)]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;This will enable all lints, including the pedantic ones, which are not enabled by default.
Chances are, you will get a lot of warnings when you first enable them.
But fixing them will make your code more idiomatic and less error-prone.
You can disable specific lints if you find them too noisy.&lt;&#x2F;p&gt;
&lt;p&gt;More detailed information on pedantic clippy settings can be found &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;zhauniarovich.com&#x2F;post&#x2F;2021&#x2F;2021-09-pedantic-clippy&#x2F;&quot;&gt;here&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;
&lt;p&gt;Also check this &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;analysis-tools.dev&#x2F;tag&#x2F;rust&quot;&gt;list of Rust static analysis tools&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h3 id=&quot;make-releases-boring&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#make-releases-boring&quot; aria-label=&quot;Anchor link for: make-releases-boring&quot;&gt;Make Releases Boring&lt;&#x2F;a&gt;&lt;&#x2F;h3&gt;
&lt;p&gt;Run your CI pipeline on a regular basis to ensure that your codebase is always
in a deployable state. The worst time to find out that something is broken is when
you’re trying to deploy a fix.&lt;&#x2F;p&gt;
&lt;p&gt;Look into &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;MarcoIeni&#x2F;release-plz&quot;&gt;release-plz&lt;&#x2F;a&gt; for release
automation. It can create pull requests for new releases, which you can review
and merge when you’re ready.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;img src=&quot;https:&#x2F;&#x2F;corrode.dev&#x2F;blog&#x2F;long-term-rust-maintenance&#x2F;release-plz.png&quot; alt=&quot;release-plz&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;p&gt;If you are afraid of triggering a release, it’s a sign that your release process
is too complex or too slow. Simplify it until you are confident that you can release at any
time and &lt;a href=&quot;&#x2F;blog&#x2F;tips-for-faster-ci-builds&#x2F;&quot;&gt;speed up your Rust CI builds&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;invest-in-the-rust-ecosystem&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#invest-in-the-rust-ecosystem&quot; aria-label=&quot;Anchor link for: invest-in-the-rust-ecosystem&quot;&gt;Invest in the Rust Ecosystem&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;p&gt;If you depend on the Rust ecosystem for your business, it is in your best
interest to invest in it. Being an active member of the Rust community will ensure that your voice gets heard, and you can influence the direction of the language and ecosystem.&lt;&#x2F;p&gt;
&lt;p&gt;This can be done in a number of ways:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;Report bugs and contribute code to the crates you use.&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;sponsors&#x2F;explore?account=mre&amp;amp;ecosystems=RUST&amp;amp;sort_by=MOST_USED&quot;&gt;Sponsor crates that you depend on&lt;&#x2F;a&gt;.&lt;&#x2F;li&gt;
&lt;li&gt;Give talks and write blog posts about your experiences with Rust.&lt;&#x2F;li&gt;
&lt;li&gt;Support the &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;foundation.rust-lang.org&#x2F;&quot;&gt;Rust Foundation&lt;&#x2F;a&gt; and core team members.&lt;&#x2F;li&gt;
&lt;li&gt;Encourage your team to contribute to the Rust ecosystem.&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h2 id=&quot;stick-to-a-regular-maintenance-schedule&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#stick-to-a-regular-maintenance-schedule&quot; aria-label=&quot;Anchor link for: stick-to-a-regular-maintenance-schedule&quot;&gt;Stick To A Regular Maintenance Schedule&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;p&gt;It’s quite easy to let things slip when you’re focused on new features and high-priority tasks.
That’s why it’s important to set aside regular time for maintenance.&lt;&#x2F;p&gt;
&lt;p&gt;For example, you could schedule a &lt;strong&gt;quarterly project review&lt;&#x2F;strong&gt; to check for
outdated dependencies, security vulnerabilities, and code smells.
Find a time that works for your team and stick to it.&lt;&#x2F;p&gt;
&lt;div class=&quot;info&quot;&gt;
  
  &lt;div class=&quot;info-header&quot;&gt;
    
      &lt;span class=&quot;icon icon-info&quot;&gt;&lt;&#x2F;span&gt;
    
    &lt;h4&gt;&lt;p&gt;Download My Free Maintenance Checklist&lt;&#x2F;p&gt;
&lt;&#x2F;h4&gt;
  &lt;&#x2F;div&gt;
  
  &lt;p&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;corrode.notion.site&#x2F;Rust-Maintenance-Checklist-3fa116db4c6149cbacbe3c16f81c6bb0&quot;&gt;Here is my own checklist for regular maintenance.&lt;&#x2F;a&gt;
Feel free to create a copy and adapt it to your needs. If you have any suggestions for improvements, please let me know and I’ll update the list.&lt;&#x2F;p&gt;

&lt;&#x2F;div&gt;
&lt;h2 id=&quot;conclusion&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#conclusion&quot; aria-label=&quot;Anchor link for: conclusion&quot;&gt;Conclusion&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;p&gt;&lt;img src=&quot;https:&#x2F;&#x2F;corrode.dev&#x2F;blog&#x2F;long-term-rust-maintenance&#x2F;conclusion.svg&quot; alt=&quot;Conclusion&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;p&gt;Maintaining a long-term codebase is challenging, regardless of the programming
language. However, Rust excels in this area due to its focus on safety, solid
tooling, and active community.&lt;&#x2F;p&gt;
&lt;p&gt;By following the principles outlined in this post, you can
ensure that your codebase remains robust and maintainable for years to come.&lt;&#x2F;p&gt;
&lt;div class=&quot;info&quot;&gt;
  
  &lt;div class=&quot;info-header&quot;&gt;
    
      &lt;span class=&quot;icon icon-radio&quot;&gt;&lt;&#x2F;span&gt;
    
    &lt;h4&gt;&lt;p&gt;Supercharge Your Rust Adoption&lt;&#x2F;p&gt;
&lt;&#x2F;h4&gt;
  &lt;&#x2F;div&gt;
  
  &lt;p&gt;If you want to learn from top companies that have successfully adopted Rust,
consider subscribing to the &lt;a href=&quot;&#x2F;podcast&quot;&gt;Rust In Production Podcast&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;In case your company is considering to adopt Rust for a new project, feel free to reach out for a &lt;a href=&quot;&#x2F;#contact&quot;&gt;consultation&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;

&lt;&#x2F;div&gt;
</description>
      </item>
      <item>
          <title>curl</title>
          <pubDate>Thu, 02 May 2024 00:00:00 +0000</pubDate>
          <author>Matthias Endler</author>
          <link>https://corrode.dev/podcast/s02e01-curl/</link>
          <guid>https://corrode.dev/podcast/s02e01-curl/</guid>
          <description xml:base="https://corrode.dev/podcast/s02e01-curl/">&lt;div&gt;&lt;script id=&quot;letscast-player-82930892&quot; src=&quot;https:&#x2F;&#x2F;letscast.fm&#x2F;podcasts&#x2F;rust-in-production-82281512&#x2F;episodes&#x2F;rust-in-production-ep-8-curl-s-daniel-stenberg&#x2F;player.js?size=s&quot;&gt;&lt;&#x2F;script&gt;&lt;&#x2F;div&gt;
&lt;p&gt;In the season premier we talk to none other than Daniel Stenberg! We focus on integrating Rust modules in curl, their benefits, ways in which Rust and Rust crates helped improve curl, but also how curl helped those crates, and where curl is used in the official Rust toolchain. Along the way we also learn about the early history of curl and Rust, which section of your car’s owner’s-manual you should “re”-read, some weird HTTP edge-cases, and Daniel’s experience in open-source maintainership.&lt;&#x2F;p&gt;</description>
      </item>
      <item>
          <title>Season 1 - Finale</title>
          <pubDate>Thu, 07 Mar 2024 00:00:00 +0000</pubDate>
          <author>Matthias Endler</author>
          <link>https://corrode.dev/podcast/s01e07-season-finale/</link>
          <guid>https://corrode.dev/podcast/s01e07-season-finale/</guid>
          <description xml:base="https://corrode.dev/podcast/s01e07-season-finale/">&lt;div&gt;&lt;script id=&quot;letscast-player-6c8ce152&quot; src=&quot;https:&#x2F;&#x2F;letscast.fm&#x2F;podcasts&#x2F;rust-in-production-82281512&#x2F;episodes&#x2F;rust-in-production-ep-7-season-finale&#x2F;player.js?size=s&quot;&gt;&lt;&#x2F;script&gt;&lt;&#x2F;div&gt;
&lt;p&gt;In the season finale of ‘Rust in Production’, we take a cold, hard look at our
goals and achievements during the first season.&lt;&#x2F;p&gt;
&lt;p&gt;Did we manage to answer the tough questions about Rust’s usage in the industry?
Were we able to provide a balanced view of the challenges and benefits of using
Rust? Or did we end up merely preaching to the choir?&lt;&#x2F;p&gt;
&lt;p&gt;As it turns out, the answers align nicely with the main themes from the Rust
2023 survey: the hiring market, the learning curve, the reasons for choosing
Rust, the costs of adoption, and the complexity of the language. Either way,
there were definitely some surprises and unexpected turns along the way!&lt;&#x2F;p&gt;</description>
      </item>
      <item>
          <title>Sentry</title>
          <pubDate>Thu, 22 Feb 2024 00:00:00 +0000</pubDate>
          <author>Matthias Endler</author>
          <link>https://corrode.dev/podcast/s01e06-sentry/</link>
          <guid>https://corrode.dev/podcast/s01e06-sentry/</guid>
          <description xml:base="https://corrode.dev/podcast/s01e06-sentry/">&lt;div&gt;&lt;script id=&quot;letscast-player-e098acdf&quot; src=&quot;https:&#x2F;&#x2F;letscast.fm&#x2F;podcasts&#x2F;rust-in-production-82281512&#x2F;episodes&#x2F;rust-in-production-ep-6-sentry-s-arpad-borsos&#x2F;player.js?size=s&quot;&gt;&lt;&#x2F;script&gt;&lt;&#x2F;div&gt;
&lt;p&gt;In this episode, we talk to Arpad Borsos, Systems Software Engineer at Sentry,
about how they use Rust to build a modern error monitoring platform for
developers.&lt;&#x2F;p&gt;</description>
      </item>
      <item>
          <title>The State of Async Rust: Runtimes</title>
          <pubDate>Wed, 21 Feb 2024 00:00:00 +0000</pubDate>
          <author>Matthias Endler</author>
          <link>https://corrode.dev/blog/async/</link>
          <guid>https://corrode.dev/blog/async/</guid>
          <description xml:base="https://corrode.dev/blog/async/">&lt;p&gt;Recently, I found myself returning to a compelling series of blog posts titled
&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;aturon.github.io&#x2F;blog&#x2F;2016&#x2F;08&#x2F;11&#x2F;futures&#x2F;&quot;&gt;Zero-cost futures in Rust&lt;&#x2F;a&gt;
by Aaron Turon about what would become the foundation of Rust’s async ecosystem
and the &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;tokio.rs&#x2F;&quot;&gt;Tokio&lt;&#x2F;a&gt; runtime.&lt;&#x2F;p&gt;
&lt;p&gt;This series stands as a cornerstone in writings about Rust. People like Aaron
are the reason why I wanted to be part of the Rust community in the first place.&lt;&#x2F;p&gt;
&lt;p&gt;While 2016 evokes nostalgic memories of excitement and fervor surrounding async
Rust, my sentiments regarding the current state of its ecosystem are now
somewhat ambivalent.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;why-bother&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#why-bother&quot; aria-label=&quot;Anchor link for: why-bother&quot;&gt;Why Bother?&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;p&gt;Through this series, I hope to address two different audiences:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;Newcomers to async Rust, seeking to get an overview of the current state of
the ecosystem.&lt;&#x2F;li&gt;
&lt;li&gt;Library maintainers and contributors to the async ecosystem, in the hope that
my perspective can be a basis for discussion about the future of async Rust.&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;In the first article, we will focus on the current state of async Rust runtimes,
their design choices, and their implications on the broader Rust async ecosystem.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;one-true-runtime&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#one-true-runtime&quot; aria-label=&quot;Anchor link for: one-true-runtime&quot;&gt;One True Runtime&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;p&gt;An inconvenient truth about async Rust is that &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;rust-lang&#x2F;areweasyncyet.rs&#x2F;issues&#x2F;34&quot;&gt;libraries still need to be
written against individual
runtimes&lt;&#x2F;a&gt;. Writing your
async code in a runtime-agnostic fashion requires &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;launchbadge&#x2F;sqlx&#x2F;blob&#x2F;d0fbe7feff4b3a200cf0453417d5e53bd011643a&#x2F;sqlx-core&#x2F;src&#x2F;rt&#x2F;mod.rs#L116-L136&quot;&gt;conditional
compilation&lt;&#x2F;a&gt;,
&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;docs.rs&#x2F;async-compat&#x2F;latest&#x2F;async_compat&quot;&gt;compatibility layers&lt;&#x2F;a&gt; and
&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;seanmonstar&#x2F;reqwest&#x2F;issues&#x2F;719#issuecomment-558758637&quot;&gt;handling
edge-cases&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;This is the rationale behind most libraries gravitating towards the
One True Runtime — &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;tokio.rs&#x2F;&quot;&gt;Tokio&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;Executor coupling is a big problem for async Rust as it breaks the ecosystem
into silos. &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.reddit.com&#x2F;r&#x2F;rust&#x2F;comments&#x2F;f10tcq&#x2F;confusion_with_rusts_async_architecture_and_how&#x2F;fh1oagw&#x2F;&quot;&gt;Documentation and examples for one runtime don’t work with the
other
runtimes&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;Moreover, much of the existing documentation on async Rust feels outdated or
incomplete. For example, the async book remains in draft, with concepts like
cancellation, timeouts, and &lt;code&gt;FuturesUnordered&lt;&#x2F;code&gt; yet to be covered. (There is an open &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;rust-lang&#x2F;async-book&#x2F;pull&#x2F;96&quot;&gt;pull
request&lt;&#x2F;a&gt;, though.)&lt;&#x2F;p&gt;
&lt;p&gt;That leaves us with a situation that is unsatisfactory for everyone involved:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;For new users, it is a big ask to &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;kevinhoffman.medium.com&#x2F;rust-async-and-the-terrible-horrible-no-good-very-bad-day-348ebc836274&quot;&gt;navigate this space&lt;&#x2F;a&gt; and make future-proof decisions.&lt;&#x2F;li&gt;
&lt;li&gt;For experienced users and library maintainers, &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;launchbadge&#x2F;sqlx&#x2F;issues&#x2F;1669#issuecomment-1032132220&quot;&gt;supporting multiple runtimes is an additional burden&lt;&#x2F;a&gt;. It’s no surprise that popular crates like &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;seanmonstar&#x2F;reqwest&quot;&gt;&lt;code&gt;reqwest&lt;&#x2F;code&gt;&lt;&#x2F;a&gt; &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;seanmonstar&#x2F;reqwest&#x2F;blob&#x2F;master&#x2F;Cargo.toml#L109&quot;&gt;simply insist on Tokio as a runtime&lt;&#x2F;a&gt;.&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;This close coupling, &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;rust-lang&#x2F;wg-async&#x2F;issues&#x2F;45&quot;&gt;recognized by the async working
group&lt;&#x2F;a&gt;, has me worried about
its potential long-term impact on the ecosystem.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;the-case-of-async-std&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#the-case-of-async-std&quot; aria-label=&quot;Anchor link for: the-case-of-async-std&quot;&gt;The case of &lt;code&gt;async-std&lt;&#x2F;code&gt;&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;p&gt;&lt;code&gt;async-std&lt;&#x2F;code&gt; was an attempt to create an alternative runtime that is closer to
the Rust standard library. Its promise was that you could almost use it as a
drop-in replacement.&lt;&#x2F;p&gt;
&lt;p&gt;Take, for instance, this straightforward synchronous file-reading code:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;use&lt;&#x2F;span&gt;&lt;span&gt; std&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span&gt;fs&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;File&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;use&lt;&#x2F;span&gt;&lt;span&gt; std&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span&gt;io&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;Read&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;fn&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; main&lt;&#x2F;span&gt;&lt;span&gt;()&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; -&amp;gt;&lt;&#x2F;span&gt;&lt;span&gt; std&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span&gt;io&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;Result&lt;&#x2F;span&gt;&lt;span&gt;&amp;lt;()&amp;gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    let mut&lt;&#x2F;span&gt;&lt;span&gt; file&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; File&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;open&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt;&amp;quot;foo.txt&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;?&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    let mut&lt;&#x2F;span&gt;&lt;span&gt; data&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; vec!&lt;&#x2F;span&gt;&lt;span&gt;[];&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    file&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;read_to_end&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;&amp;amp;mut&lt;&#x2F;span&gt;&lt;span&gt; data)&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;?&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;    Ok&lt;&#x2F;span&gt;&lt;span&gt;(())&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;In &lt;code&gt;async-std&lt;&#x2F;code&gt;, it is an &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;docs.rs&#x2F;async-std&#x2F;latest&#x2F;async_std&#x2F;fs&#x2F;struct.File.html#method.open&quot;&gt;async
operation&lt;&#x2F;a&gt;
instead:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;use&lt;&#x2F;span&gt;&lt;span&gt; async_std&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span&gt;prelude&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::*&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;use&lt;&#x2F;span&gt;&lt;span&gt; async_std&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span&gt;fs&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;File&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;use&lt;&#x2F;span&gt;&lt;span&gt; async_std&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span&gt;io;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;async fn&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; read_file&lt;&#x2F;span&gt;&lt;span&gt;(path&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;: &amp;amp;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;str&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; -&amp;gt;&lt;&#x2F;span&gt;&lt;span&gt; io&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;Result&lt;&#x2F;span&gt;&lt;span&gt;&amp;lt;()&amp;gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    let mut&lt;&#x2F;span&gt;&lt;span&gt; file&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; File&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;open&lt;&#x2F;span&gt;&lt;span&gt;(path)&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.await?&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    let mut&lt;&#x2F;span&gt;&lt;span&gt; data&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; vec!&lt;&#x2F;span&gt;&lt;span&gt;[];&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    file&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;read_to_end&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;&amp;amp;mut&lt;&#x2F;span&gt;&lt;span&gt; data)&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.await?&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;    Ok&lt;&#x2F;span&gt;&lt;span&gt;(())&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;The only difference is the &lt;code&gt;await&lt;&#x2F;code&gt; keyword.&lt;&#x2F;p&gt;
&lt;p&gt;While the name might suggest it, &lt;code&gt;async-std&lt;&#x2F;code&gt; is not a drop-in replacement
for the standard library as there are many &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;seanmonstar&#x2F;reqwest&#x2F;issues&#x2F;719#issuecomment-558758637&quot;&gt;subtle differences between the
two&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;Here are some examples of issues that are still open:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;async-rs&#x2F;async-std&#x2F;issues&#x2F;731&quot;&gt;New thread is spawned for every I&#x2F;O request&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;async-rs&#x2F;async-std&#x2F;issues&#x2F;914&quot;&gt;OpenOptionsExt missing for Windows?&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;async-rs&#x2F;async-std&#x2F;issues&#x2F;900&quot;&gt;Spawned task is stuck during flushing in
File.drop()&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;It is hard to create a runtime that is fully compatible with the standard
library. Even if it &lt;em&gt;were&lt;&#x2F;em&gt; a drop-in replacement, I’d still ponder its actual merit.&lt;&#x2F;p&gt;
&lt;p&gt;Rust is a language that values explicitness. This is especially true for
reasoning about runtime behavior, such as allocations and blocking operations.
The async-std’s teams proposal to &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.reddit.com&#x2F;r&#x2F;rust&#x2F;comments&#x2F;ebfj3x&#x2F;stop_worrying_about_blocking_the_new_asyncstd&#x2F;&quot;&gt;“Stop worrying about
blocking”&lt;&#x2F;a&gt;
was &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.reddit.com&#x2F;r&#x2F;rust&#x2F;comments&#x2F;ebpzqx&#x2F;do_not_stop_worrying_about_blocking_in_async&quot;&gt;met with noticeable community skepticism&lt;&#x2F;a&gt; and later retracted.&lt;&#x2F;p&gt;
&lt;p&gt;As of this writing, &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;lib.rs&#x2F;crates&#x2F;async-std&#x2F;rev&quot;&gt;1754 public crates have a dependency on
&lt;code&gt;async-std&lt;&#x2F;code&gt;&lt;&#x2F;a&gt; and there
are companies that &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;launchbadge&#x2F;sqlx&#x2F;issues&#x2F;1669#issuecomment-1028879475&quot;&gt;rely on it in
production&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;However, looking at the commits over time &lt;code&gt;async-std&lt;&#x2F;code&gt; is essentially abandoned
as there is &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;async-rs&#x2F;async-std&#x2F;graphs&#x2F;contributors&quot;&gt;no active development
anymore&lt;&#x2F;a&gt;:&lt;&#x2F;p&gt;
&lt;p&gt;&lt;img src=&quot;https:&#x2F;&#x2F;corrode.dev&#x2F;blog&#x2F;async&#x2F;async-std-github.svg&quot; alt=&quot;Fading async-std contribution graph on Github&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;p&gt;&lt;strong&gt;Update&lt;&#x2F;strong&gt;: as of March 1, 2025, &lt;code&gt;async-std&lt;&#x2F;code&gt; has &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;async-rs&#x2F;async-std&#x2F;commit&#x2F;fb56bffdbb4699e1add70a0f834dee6f57c398eb&quot;&gt;officially been discontinued&lt;&#x2F;a&gt;.
The suggested replacement is &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;smol-rs&#x2F;smol&#x2F;&quot;&gt;smol&lt;&#x2F;a&gt;, which is a&lt;br &#x2F;&gt;
lightweight, much more explicit runtime, that is different to &lt;code&gt;async-std&lt;&#x2F;code&gt; in
many ways.&lt;&#x2F;p&gt;
&lt;p&gt;This leaves those reliant on the &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;docs.rs&#x2F;async-std&#x2F;latest&#x2F;async_std&#x2F;&quot;&gt;&lt;code&gt;async-std&lt;&#x2F;code&gt;
API&lt;&#x2F;a&gt; – be it for concurrency
mechanisms, extension traits, or otherwise – in an unfortunate situation, as is
the case for libraries developed on top of &lt;code&gt;async-std&lt;&#x2F;code&gt;, such as
&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;http-rs&#x2F;surf&quot;&gt;&lt;code&gt;surf&lt;&#x2F;code&gt;&lt;&#x2F;a&gt;. The core of &lt;code&gt;async-std&lt;&#x2F;code&gt; has long been
powered by &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;smol-rs&#x2F;smol&quot;&gt;&lt;code&gt;smol&lt;&#x2F;code&gt;&lt;&#x2F;a&gt;, but it is probably best to
use it directly for new projects.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;can-t-we-just-embrace-tokio&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#can-t-we-just-embrace-tokio&quot; aria-label=&quot;Anchor link for: can-t-we-just-embrace-tokio&quot;&gt;Can’t we just embrace Tokio?&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;p&gt;Tokio stands as Rust’s canonical async runtime.
But to label Tokio merely as a runtime would be an understatement.
It has extra modules for
&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;docs.rs&#x2F;tokio&#x2F;latest&#x2F;tokio&#x2F;fs&#x2F;index.html&quot;&gt;fs&lt;&#x2F;a&gt;,
&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;docs.rs&#x2F;tokio&#x2F;latest&#x2F;tokio&#x2F;io&#x2F;index.html&quot;&gt;io&lt;&#x2F;a&gt;,
&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;docs.rs&#x2F;tokio&#x2F;latest&#x2F;tokio&#x2F;net&#x2F;index.html&quot;&gt;net&lt;&#x2F;a&gt;,
&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;docs.rs&#x2F;tokio&#x2F;latest&#x2F;tokio&#x2F;process&#x2F;index.html&quot;&gt;process-&lt;&#x2F;a&gt; and &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;docs.rs&#x2F;tokio&#x2F;latest&#x2F;tokio&#x2F;signal&#x2F;index.html&quot;&gt;signal
handling&lt;&#x2F;a&gt; and
&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;docs.rs&#x2F;tokio&#x2F;latest&#x2F;tokio&#x2F;#modules&quot;&gt;more&lt;&#x2F;a&gt;.
That makes it more of a framework for asynchronous programming than just a
runtime.&lt;&#x2F;p&gt;
&lt;p&gt;Partially, this is because Tokio had a pioneering role in async Rust. It
explored the design space as it went along. And while you could exclusively use
the runtime and ignore the rest, it is easier and more common to buy into the
entire ecosystem.&lt;&#x2F;p&gt;
&lt;p&gt;Yet, my main concern with Tokio is that it makes a lot of assumptions about how
async code should be written and where it runs.&lt;&#x2F;p&gt;
&lt;p&gt;For example, &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;docs.rs&#x2F;tokio&#x2F;latest&#x2F;tokio&#x2F;&quot;&gt;at the beginning of the Tokio
documentation&lt;&#x2F;a&gt;, they state:&lt;&#x2F;p&gt;
&lt;p&gt;“The easiest way to get started is to enable all features. Do this by enabling
the &lt;code&gt;full&lt;&#x2F;code&gt; feature flag”:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;tokio&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; { version&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt; &amp;quot;1&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;, features&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; [&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt;&amp;quot;full&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;] }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;By doing so, one would set up a
&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;rustmagazine.org&#x2F;issue-4&#x2F;how-tokio-schedule-tasks&#x2F;&quot;&gt;work-stealing&lt;&#x2F;a&gt;,
&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;docs.rs&#x2F;tokio&#x2F;latest&#x2F;tokio&#x2F;attr.main.html&quot;&gt;multi-threaded runtime&lt;&#x2F;a&gt;
which mandates that types are &lt;code&gt;Send&lt;&#x2F;code&gt; and &lt;code&gt;&#x27;static&lt;&#x2F;code&gt; and makes it necessary to use
synchronization primitives such as
&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;doc.rust-lang.org&#x2F;std&#x2F;sync&#x2F;struct.Arc.html&quot;&gt;&lt;code&gt;Arc&lt;&#x2F;code&gt;&lt;&#x2F;a&gt; and
&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;doc.rust-lang.org&#x2F;std&#x2F;sync&#x2F;struct.Mutex.html&quot;&gt;&lt;code&gt;Mutex&lt;&#x2F;code&gt;&lt;&#x2F;a&gt; for all but the
most trivial applications.&lt;&#x2F;p&gt;
&lt;div class=&quot;info&quot;&gt;
  
  &lt;div class=&quot;info-header&quot;&gt;
    
      &lt;span class=&quot;icon icon-info&quot;&gt;&lt;&#x2F;span&gt;
    
    &lt;h4&gt;&lt;p&gt;Understanding ’static Lifetimes in Async Rust&lt;&#x2F;p&gt;
&lt;&#x2F;h4&gt;
  &lt;&#x2F;div&gt;
  
  &lt;p&gt;A &lt;code&gt;&#x27;static&lt;&#x2F;code&gt; trait bound mandates that the type does not contain any non-static
references. This means the receiver can hold on to the type
&lt;em&gt;indefinitely&lt;&#x2F;em&gt; without it becoming invalid until they decide to drop it.&lt;&#x2F;p&gt;
&lt;p&gt;Here is an example of an async function that has a &lt;code&gt;&#x27;static&lt;&#x2F;code&gt; lifetime bound:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;async fn&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; process_data&lt;&#x2F;span&gt;&lt;span&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;T&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span&gt; &amp;#39;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;static&lt;&#x2F;span&gt;&lt;span&gt;&amp;gt;(data&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; T&lt;&#x2F;span&gt;&lt;span&gt;) {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;    &#x2F;&#x2F; ...&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Owned data passes a &lt;code&gt;&#x27;static&lt;&#x2F;code&gt; lifetime bound if it, and all of its contents, do
not contain any non-static references — but, crucially, a &lt;em&gt;reference&lt;&#x2F;em&gt; to
that owned data generally does not.&lt;&#x2F;p&gt;
&lt;p&gt;Since tasks in async runtimes may outlive the scope they were created in
(especially in multi-threaded contexts), ensuring that references remain valid
for the duration of the task’s execution is challenging. This is why async tasks
often require &lt;code&gt;&#x27;static&lt;&#x2F;code&gt; data, to guarantee that the data lives long enough or to
ensure ownership is transferred to the task.&lt;&#x2F;p&gt;
&lt;p&gt;This makes it hard to use references in async code, as borrowed data must live
as long as the task.&lt;&#x2F;p&gt;
&lt;p&gt;For most practical use-cases, this means that futures cannot borrow
data from the scope they are spawned from, unless the data lives long enough or
ownership is transferred.&lt;&#x2F;p&gt;
&lt;p&gt;This requirement marks a significant departure from
synchronous Rust, where borrowing data across function calls is commonplace.
It represents a fundamental shift in how we manage data lifetimes and ownership
in asynchronous compared to synchronous Rust.&lt;&#x2F;p&gt;

&lt;&#x2F;div&gt;
&lt;blockquote&gt;
&lt;p&gt;The Original Sin of Rust async programming is making it multi-threaded by
default. If premature optimization is the root of all evil, this is the mother
of all premature optimizations, and it curses all your code with the unholy
&lt;code&gt;Send + &#x27;static&lt;&#x2F;code&gt;, or worse yet &lt;code&gt;Send + Sync + &#x27;static&lt;&#x2F;code&gt;, which just kills all the
joy of actually writing Rust.&lt;&#x2F;p&gt;
&lt;p&gt;— &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;maciej.codes&#x2F;2022-06-09-local-async.html&quot;&gt;Maciej Hirsz&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
&lt;p&gt;Any time we reach for an &lt;code&gt;Arc&lt;&#x2F;code&gt; or a &lt;code&gt;Mutex&lt;&#x2F;code&gt; it’s good idea to stop for a moment
and think about the future implications of that decision.&lt;&#x2F;p&gt;
&lt;p&gt;The choice to use &lt;code&gt;Arc&lt;&#x2F;code&gt; or &lt;code&gt;Mutex&lt;&#x2F;code&gt; might be indicative of a design that
hasn’t fully embraced the ownership and borrowing principles that Rust
emphasizes. It’s worth reconsidering if the shared state is genuinely necessary
or if there’s a simpler design that could minimize or eliminate the need
for shared mutable state (for instance by using channels).&lt;&#x2F;p&gt;
&lt;p&gt;The problem, of course, is that Tokio imposes this design on you. It’s not your
choice to make.&lt;&#x2F;p&gt;
&lt;p&gt;Beyond the complexities of architecting async code atop these synchronization
mechanisms, they carry a performance cost: Locking means runtime overhead and
additional memory usage; in embedded environments, these mechanisms are often
not available at all.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;strong&gt;Multi-threaded-by-default runtimes cause accidental complexity completely
unrelated to the task of writing async code.&lt;&#x2F;strong&gt; This additional complexity can also impact build times, as discussed in our guide on &lt;a href=&quot;&#x2F;blog&#x2F;tips-for-faster-rust-compile-times&#x2F;&quot;&gt;Tips for Faster Compile Times&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;Futures should be designed for brief, scoped lifespans rather than the &lt;code&gt;&#x27;static&lt;&#x2F;code&gt; lifetime.
Ideally, we’d lean on an explicit &lt;code&gt;spawn::async&lt;&#x2F;code&gt; instead of &lt;code&gt;spawn::blocking&lt;&#x2F;code&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;Maciej suggested to use a &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;maciej.codes&#x2F;2022-06-09-local-async.html&quot;&gt;local async
runtime&lt;&#x2F;a&gt; which is
single-threaded by default and does &lt;strong&gt;not&lt;&#x2F;strong&gt; require types to be &lt;code&gt;Send&lt;&#x2F;code&gt; and
&lt;code&gt;&#x27;static&lt;&#x2F;code&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;I fully agree.&lt;&#x2F;p&gt;
&lt;p&gt;However, I have little hope that the Rust community will change course at this
point. Tokio’s roots run deep within the ecosystem and it feels like for better
or worse we’re stuck with it.&lt;&#x2F;p&gt;
&lt;p&gt;In the realms of networking and web operations, it’s likely that one of your
dependencies integrates Tokio, effectively nudging you towards its adoption. At
the time of writing, &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;lib.rs&#x2F;crates&#x2F;tokio&#x2F;rev&quot;&gt;Tokio is used at runtime in 20,768 crates (of which 5,245
depend on it optionally)&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;img src=&quot;https:&#x2F;&#x2F;corrode.dev&#x2F;blog&#x2F;async&#x2F;runtimes.svg&quot; alt=&quot;Runtime popularity bar chart between tokio, async-std, and smol with Tokio greatly dominating&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;p&gt;In spite of all this, we should not stop innovating in the async space!&lt;&#x2F;p&gt;
&lt;h2 id=&quot;other-runtimes&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#other-runtimes&quot; aria-label=&quot;Anchor link for: other-runtimes&quot;&gt;Other Runtimes&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;p&gt;Going beyond Tokio, several other runtimes deserve more attention:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;smol-rs&#x2F;smol&quot;&gt;smol&lt;&#x2F;a&gt;: A small async runtime,
which is easy to understand. The entire executor is around
&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;smol-rs&#x2F;async-executor&#x2F;blob&#x2F;master&#x2F;src&#x2F;lib.rs&quot;&gt;1000 lines of code&lt;&#x2F;a&gt;
with other parts of the ecosystem being similarly small.&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;embassy-rs&#x2F;embassy&quot;&gt;embassy&lt;&#x2F;a&gt;: An async runtime for
embedded systems.&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;DataDog&#x2F;glommio&quot;&gt;glommio&lt;&#x2F;a&gt;: An async runtime for I&#x2F;O-bound
workloads, built on top of &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;lwn.net&#x2F;Articles&#x2F;810414&#x2F;&quot;&gt;io_uring&lt;&#x2F;a&gt;
and using a thread-per-core model.&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;These runtimes are important, as they explore alternative paths or open up new
use cases for async Rust. Drawing a parallel with &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;mastodon.social&#x2F;@mre&#x2F;111019994687648975&quot;&gt;Rust’s error handling
story&lt;&#x2F;a&gt;, the hope is that
competing designs will lead to a more robust foundation overall.
Especially, iterating on smaller runtimes that are less invasive and
single-threaded by default can help improve Rust’s async story.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;async-vs-threads&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#async-vs-threads&quot; aria-label=&quot;Anchor link for: async-vs-threads&quot;&gt;Async vs Threads&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;blockquote&gt;
&lt;p&gt;If you don’t need async for performance reasons, threads can often be the
simpler alternative. — &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;rust-lang.github.io&#x2F;async-book&#x2F;01_getting_started&#x2F;02_why_async.html#async-vs-threads-in-rust&quot;&gt;the Async Book&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
&lt;p&gt;Modern operating systems come with highly optimized schedulers that are
excellent at multitasking and support async I&#x2F;O through
&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;lwn.net&#x2F;Articles&#x2F;776703&#x2F;&quot;&gt;io_uring&lt;&#x2F;a&gt; and
&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;mre&#x2F;fcat&quot;&gt;splice&lt;&#x2F;a&gt;. We should make better use of these
capabilities. At least we should fully lean into the capabilities of modern
operating systems.&lt;&#x2F;p&gt;
&lt;p&gt;Take our sync code to read a file from above for example.
We can call this function inside the new &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;doc.rust-lang.org&#x2F;std&#x2F;thread&#x2F;fn.scope.html&quot;&gt;scoped
threads&lt;&#x2F;a&gt;:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;use&lt;&#x2F;span&gt;&lt;span&gt; std&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span&gt;error&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;Error&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;use&lt;&#x2F;span&gt;&lt;span&gt; std&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span&gt;fs;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;use&lt;&#x2F;span&gt;&lt;span&gt; std&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span&gt;io&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;Read&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;use&lt;&#x2F;span&gt;&lt;span&gt; std&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span&gt;path&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;Path&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;use&lt;&#x2F;span&gt;&lt;span&gt; std&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span&gt;{thread, time};&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;fn&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; main&lt;&#x2F;span&gt;&lt;span&gt;() {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    thread&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;scope&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;|&lt;&#x2F;span&gt;&lt;span&gt;scope&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;|&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;        &#x2F;&#x2F; worker thread 1&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        scope&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;spawn&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;||&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;            let&lt;&#x2F;span&gt;&lt;span&gt; contents&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; fs&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;read_to_string&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt;&amp;quot;foo.txt&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;            &#x2F;&#x2F; do something with contents&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        });&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;        &#x2F;&#x2F; worker thread 2&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        scope&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;spawn&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;||&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;            let&lt;&#x2F;span&gt;&lt;span&gt; contents&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; fs&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;read_to_string&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt;&amp;quot;bar.txt&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;            &#x2F;&#x2F; ...&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        });&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;        &#x2F;&#x2F; worker thread 3&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        scope&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;spawn&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;||&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;            let&lt;&#x2F;span&gt;&lt;span&gt; contents&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; fs&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;read_to_string&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt;&amp;quot;baz.txt&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;            &#x2F;&#x2F; ...&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        });&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    });&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;    &#x2F;&#x2F; No join; threads get joined&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;    &#x2F;&#x2F; automatically once the scope ends&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;(&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;play.rust-lang.org&#x2F;?version=stable&amp;amp;mode=debug&amp;amp;edition=2021&amp;amp;gist=1bb9bbd9fdd4626bae93ac3d2cd81165&quot;&gt;Link to playground&lt;&#x2F;a&gt;)&lt;&#x2F;p&gt;
&lt;p&gt;Or, perhaps more aptly,&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;fn&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; main&lt;&#x2F;span&gt;&lt;span&gt;() {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    let&lt;&#x2F;span&gt;&lt;span&gt; files&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; [&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt;&amp;quot;foo.txt&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt; &amp;quot;bar.txt&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt; &amp;quot;baz.txt&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;];&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    thread&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;scope&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;|&lt;&#x2F;span&gt;&lt;span&gt;scope&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;|&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;        for&lt;&#x2F;span&gt;&lt;span&gt; file&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; in&lt;&#x2F;span&gt;&lt;span&gt; files {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            scope&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;spawn&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;move ||&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;                let&lt;&#x2F;span&gt;&lt;span&gt; contents&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; fs&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;read_to_string&lt;&#x2F;span&gt;&lt;span&gt;(file);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;                &#x2F;&#x2F; ...&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            });&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    });&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;If this code were placed into a function, it would serve both synchronous and
asynchronous callers, completely removing the need for an asynchronous runtime.
The scheduling burden would shift to the operating system.&lt;&#x2F;p&gt;
&lt;p&gt;Async Rust promises efficient resource handling, at the cost of complexity and
worse ergonomics. As an example, if the function were &lt;em&gt;async&lt;&#x2F;em&gt; and you called it
&lt;em&gt;outside&lt;&#x2F;em&gt; of a runtime, it would compile, but not run. Futures do nothing unless
being polled; a common footgun for newcomers.&lt;&#x2F;p&gt;
&lt;p&gt;For teams evaluating async Rust for production use, it’s worth understanding the full trade-offs. See &lt;a href=&quot;&#x2F;blog&#x2F;why-rust&#x2F;&quot;&gt;Why Rust in Production&lt;&#x2F;a&gt; for a broader perspective on when these complexities are justified.&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;use&lt;&#x2F;span&gt;&lt;span&gt; tokio&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span&gt;fs;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;#[tokio&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span&gt;main]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;async fn&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; main&lt;&#x2F;span&gt;&lt;span&gt;() {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;    &#x2F;&#x2F; This will print a warning, but compile&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;    &#x2F;&#x2F; and do nothing at runtime&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    fs&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;read_to_string&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt;&amp;quot;foo.txt&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;(&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;play.rust-lang.org&#x2F;?version=stable&amp;amp;mode=debug&amp;amp;edition=2021&amp;amp;gist=dac468c7e7ea0f224e91b56ccadc8e43&quot;&gt;Link to playground&lt;&#x2F;a&gt;)&lt;&#x2F;p&gt;
&lt;p&gt;If you find yourself needing to share state between threads, consider using a
channel:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;use&lt;&#x2F;span&gt;&lt;span&gt; std&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span&gt;error&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;Error&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;use&lt;&#x2F;span&gt;&lt;span&gt; std&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span&gt;fs;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;use&lt;&#x2F;span&gt;&lt;span&gt; std&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span&gt;io&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;Read&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;use&lt;&#x2F;span&gt;&lt;span&gt; std&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span&gt;path&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;Path&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;use&lt;&#x2F;span&gt;&lt;span&gt; std&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span&gt;{thread, time};&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;use&lt;&#x2F;span&gt;&lt;span&gt; std&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span&gt;sync&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span&gt;mpsc;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;fn&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; main&lt;&#x2F;span&gt;&lt;span&gt;() {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    let&lt;&#x2F;span&gt;&lt;span&gt; (tx, rx)&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; mpsc&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;channel&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;String&lt;&#x2F;span&gt;&lt;span&gt;&amp;gt;();&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    let&lt;&#x2F;span&gt;&lt;span&gt; files&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; [&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt;&amp;quot;foo.txt&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt; &amp;quot;bar.txt&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt; &amp;quot;baz.txt&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;];&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    thread&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;scope&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;|&lt;&#x2F;span&gt;&lt;span&gt;scope&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;|&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;        for&lt;&#x2F;span&gt;&lt;span&gt; file&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; in&lt;&#x2F;span&gt;&lt;span&gt; files {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            scope&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;spawn&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;move ||&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;                let&lt;&#x2F;span&gt;&lt;span&gt; contents&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; fs&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;read_to_string&lt;&#x2F;span&gt;&lt;span&gt;(file);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;                &#x2F;&#x2F; ...&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            });&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    });&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;    &#x2F;&#x2F; Receive messages from the channel&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    for&lt;&#x2F;span&gt;&lt;span&gt; received&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; in&lt;&#x2F;span&gt;&lt;span&gt; rx {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;        println!&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt;&amp;quot;Got: {:?}&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;, received);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;(&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;play.rust-lang.org&#x2F;?version=stable&amp;amp;mode=debug&amp;amp;edition=2021&amp;amp;gist=5b7fa587cf1796089ce7bb374539229e&quot;&gt;Link to playground&lt;&#x2F;a&gt;)&lt;&#x2F;p&gt;
&lt;h2 id=&quot;common-prejudice-against-threads&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#common-prejudice-against-threads&quot; aria-label=&quot;Anchor link for: common-prejudice-against-threads&quot;&gt;Common Prejudice Against Threads&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;p&gt;Asynchronous programming is often seen as the solution to improving performance
and scalability of I&#x2F;O-bound workloads.&lt;&#x2F;p&gt;
&lt;p&gt;In a &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;vorner.github.io&#x2F;async-bench.html&quot;&gt;recent benchmark&lt;&#x2F;a&gt;, traditional
threading outperformed the async approach in scenarios with a limited number of
threads. This underscores the core premise that, in real-world applications, the
performance difference between the two approaches is often negligible, if not
slightly favoring threads. Thus, it’s crucial not to gravitate towards async
Rust driven solely by anticipated performance gains.&lt;&#x2F;p&gt;
&lt;p&gt;Thread-based frameworks, like the now-inactive
&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;iron&#x2F;iron&quot;&gt;iron&lt;&#x2F;a&gt;, showcased the capability to effortlessly
handle &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;iron&#x2F;iron&#x2F;wiki&#x2F;How-to-Benchmark-hello.rs-Example&quot;&gt;tens of thousands of requests per
second&lt;&#x2F;a&gt;.
This is further complemented by the fact modern Linux systems can manage &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;thetechsolo.wordpress.com&#x2F;2016&#x2F;08&#x2F;28&#x2F;scaling-to-thousands-of-threads&#x2F;&quot;&gt;tens
of thousands of
threads&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;strong&gt;Traditional arguments against threads simply don’t apply to Rust.&lt;&#x2F;strong&gt;
Threaded code in Rust is protected from data races, null dereferences, and
dangling references, ensuring a level of safety that prevents many common
pitfalls found in other languages.&lt;&#x2F;p&gt;
&lt;p&gt;As an important caveat, threads are not available or feasible in all
environments, such as embedded systems. My context for this article is primarily
conventional server-side applications that run on top of platforms like Linux or
Windows.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;summary&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#summary&quot; aria-label=&quot;Anchor link for: summary&quot;&gt;Summary&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;h3 id=&quot;use-async-rust-sparingly&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#use-async-rust-sparingly&quot; aria-label=&quot;Anchor link for: use-async-rust-sparingly&quot;&gt;Use Async Rust Sparingly&lt;&#x2F;a&gt;&lt;&#x2F;h3&gt;
&lt;p&gt;My original intention was to advise newcomers to sidestep async Rust for now,
giving the ecosystem time to mature. However, I since acknowledged that this is
not feasible, given that a lot of libraries are async-first and new users will
encounter async Rust one way or another.&lt;&#x2F;p&gt;
&lt;p&gt;Instead, I would recommend to use async Rust only when you really need it. Learn
how to write good synchronous Rust first and then, if necessary, transition to
async Rust. Learn to walk before you run.&lt;&#x2F;p&gt;
&lt;p&gt;If you have to use async Rust, stick to Tokio and well-established libraries
like &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;seanmonstar&#x2F;reqwest&quot;&gt;reqwest&lt;&#x2F;a&gt; and
&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;launchbadge&#x2F;sqlx&quot;&gt;sqlx&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;While it may seem surprising given the context of this article, we can’t
overlook Tokio’s stronghold within the ecosystem. A vast majority of libraries
are tailored specifically for it. Navigating compatibility crates can pose
challenges, and sidestepping Tokio doesn’t guarantee your dependencies won’t
bring it in. I’m hoping for a future shift towards leaner runtimes, but for now,
Tokio stands out as the pragmatic choice for real-world implementations.&lt;&#x2F;p&gt;
&lt;p&gt;However, it’s valuable to know that there are alternatives to Tokio and that
they are worth exploring.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;consider-the-alternatives&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#consider-the-alternatives&quot; aria-label=&quot;Anchor link for: consider-the-alternatives&quot;&gt;Consider The Alternatives&lt;&#x2F;a&gt;&lt;&#x2F;h3&gt;
&lt;p&gt;At its core, Rust and its standard library offer just the absolute
essentials for &lt;code&gt;async&#x2F;await&lt;&#x2F;code&gt;. The bulk of the work is done in
crates developed by the Rust community.
We should make more use of the ability to iterate on async Rust and
experiment with different designs before we settle on a final solution.&lt;&#x2F;p&gt;
&lt;p&gt;In binary crates, think twice if you really need to use async. It’s probably
easier to just spawn a thread and get away with blocking I&#x2F;O. In case you have a
CPU-bound workload, you can use &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;rayon-rs&#x2F;rayon&quot;&gt;rayon&lt;&#x2F;a&gt; to
parallelize your code.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;isolate-async-code&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#isolate-async-code&quot; aria-label=&quot;Anchor link for: isolate-async-code&quot;&gt;Isolate Async Code&lt;&#x2F;a&gt;&lt;&#x2F;h3&gt;
&lt;p&gt;If async is truly indispensable, consider isolating your async code from the
rest of your application.&lt;&#x2F;p&gt;
&lt;p&gt;Keep your domain logic synchronous and only use async for I&#x2F;O and external
services. Following these guidelines will make your code &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;journal.stuffwithstuff.com&#x2F;2015&#x2F;02&#x2F;01&#x2F;what-color-is-your-function&#x2F;&quot;&gt;more
composable&lt;&#x2F;a&gt;
and accessible. On top of that, the error messages of sync Rust are much easier
to reason about than those of async Rust.&lt;&#x2F;p&gt;
&lt;p&gt;In your public library code, avoid async-only interfaces to make downstream
integration easier.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;keep-it-simple&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#keep-it-simple&quot; aria-label=&quot;Anchor link for: keep-it-simple&quot;&gt;Keep It Simple&lt;&#x2F;a&gt;&lt;&#x2F;h3&gt;
&lt;p&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.chiark.greenend.org.uk&#x2F;~ianmdlvl&#x2F;rust-polyglot&#x2F;async.html&quot;&gt;Async Rust feels like a different
dialect&lt;&#x2F;a&gt;,
that is significantly more brittle than the rest of the language at the moment.&lt;&#x2F;p&gt;
&lt;p&gt;When writing libraries, &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;nullderef.com&#x2F;blog&#x2F;rust-async-sync&#x2F;&quot;&gt;the maintenance
overhead&lt;&#x2F;a&gt; of supporting both async
and sync interfaces is not to be underestimated.&lt;&#x2F;p&gt;
&lt;p&gt;The default mode for writing Rust should be &lt;em&gt;synchronous&lt;&#x2F;em&gt;. Freely after
&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=22206779&quot;&gt;Stroustrup&lt;&#x2F;a&gt;:&lt;br &#x2F;&gt;
&lt;em&gt;Inside Rust, there is a smaller, simpler language that is waiting to get out.&lt;&#x2F;em&gt;
It is this language that most Rust code should be written in.&lt;&#x2F;p&gt;
</description>
      </item>
      <item>
          <title>Tweede Golf</title>
          <pubDate>Thu, 08 Feb 2024 00:00:00 +0000</pubDate>
          <author>Matthias Endler</author>
          <link>https://corrode.dev/podcast/s01e05-tweede-golf/</link>
          <guid>https://corrode.dev/podcast/s01e05-tweede-golf/</guid>
          <description xml:base="https://corrode.dev/podcast/s01e05-tweede-golf/">&lt;div&gt;&lt;script id=&quot;letscast-player-b30f560a&quot; src=&quot;https:&#x2F;&#x2F;letscast.fm&#x2F;podcasts&#x2F;rust-in-production-82281512&#x2F;episodes&#x2F;rust-in-production-ep-5-tweede-golf-s-folkert-de-vries&#x2F;player.js?size=s&quot;&gt;&lt;&#x2F;script&gt;&lt;&#x2F;div&gt;
&lt;p&gt;In this episode, we talk to Folkert de Vries, Systems Software Engineer at Tweede Golf, about how they use Rust to modernize the NTP protocol and build a new generation of time synchronization services.&lt;&#x2F;p&gt;</description>
      </item>
      <item>
          <title>Learning Material for Idiomatic Rust</title>
          <pubDate>Sun, 28 Jan 2024 00:00:00 +0000</pubDate>
          <author>Matthias Endler</author>
          <link>https://corrode.dev/blog/idiomatic-rust-resources/</link>
          <guid>https://corrode.dev/blog/idiomatic-rust-resources/</guid>
          <description xml:base="https://corrode.dev/blog/idiomatic-rust-resources/">&lt;p&gt;Here’s a curated list of resources to &lt;strong&gt;help you write ergonomic and idiomatic Rust code&lt;&#x2F;strong&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;The list is open source and &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;mre&#x2F;idiomatic-rust&quot;&gt;maintained on GitHub&lt;&#x2F;a&gt;, and contributions are always welcome!&lt;&#x2F;p&gt;
&lt;p&gt;Discover a wealth of tutorials, workshops, and articles created by Rust experts, all aimed at helping you become a better Rust programmer. Each resource is peer-reviewed to ensure adherence to Rust best practices. Plus, you can easily filter, sort, and search by tags, year, and difficulty level to find exactly what you need.&lt;&#x2F;p&gt;
&lt;script src=&quot;https:&#x2F;&#x2F;ajax.googleapis.com&#x2F;ajax&#x2F;libs&#x2F;jquery&#x2F;3.7.1&#x2F;jquery.min.js&quot;&gt;&lt;&#x2F;script&gt;
&lt;script src=&quot;https:&#x2F;&#x2F;cdn.datatables.net&#x2F;1.13.7&#x2F;js&#x2F;jquery.dataTables.min.js&quot;&gt;&lt;&#x2F;script&gt;
&lt;script src=&quot;dataTables.checkboxes.min.js&quot;&gt;&lt;&#x2F;script&gt;
&lt;script src=&quot;table.js&quot;&gt;&lt;&#x2F;script&gt;
&lt;div style=&quot;margin-bottom: 20px&quot;&gt;
    &lt;button class=&quot;button reset-filter&quot;&gt;Reset filters&lt;&#x2F;button&gt;
&lt;&#x2F;div&gt;
&lt;div&gt;
    Extra columns: 
    &lt;a class=&quot;toggle-vis&quot; data-column=&quot;6&quot;&gt;Official&lt;&#x2F;a&gt; - 
    &lt;a class=&quot;toggle-vis&quot; data-column=&quot;7&quot;&gt;Year&lt;&#x2F;a&gt; - 
    &lt;a class=&quot;toggle-vis&quot; data-column=&quot;9&quot;&gt;Duration&lt;&#x2F;a&gt; - 
    &lt;a class=&quot;toggle-vis&quot; data-column=&quot;11&quot;&gt;Free&#x2F;Commercial&lt;&#x2F;a&gt;
&lt;&#x2F;div&gt;
&lt;div&gt;
  Click on the triangle &lt;span style=&quot;font-family: Arial, sans-serif&quot;&gt;▶&lt;&#x2F;span&gt; to show more details for
  each entry.
&lt;&#x2F;div&gt;
&lt;table id=&quot;data-table&quot; class=&quot;compact order-column hover stripe&quot; style=&quot;width:100%&quot;&gt;
&lt;&#x2F;table&gt;
&lt;link rel=&quot;stylesheet&quot; type=&quot;text&#x2F;css&quot; href=&quot;https:&#x2F;&#x2F;cdn.datatables.net&#x2F;1.13.7&#x2F;css&#x2F;jquery.dataTables.min.css&quot; &#x2F;&gt;
&lt;style&gt;
&#x2F;* DataTables overrides *&#x2F;
.dataTables_wrapper .dataTables_filter {
    margin: 20px 0 40px;
}

.dataTables_filter input[type=&quot;search&quot;] {
    font-size: 18px;
    margin: 0 0 0 10px;
    padding: 8px 16px;
    width: 350px;
    color: #111;
    border: 2px solid rgba(17, 17, 17, 0.3);
    border-radius: 4px;
    background: transparent;
}

.dataTables_filter input[type=&quot;search&quot;]:focus {
    outline: none;
    border-color: #111;
}

&#x2F;* Tag badges - similar to conference badges *&#x2F;
.dataTables_wrapper code {
    cursor: pointer;
}

code {
    border-radius: 4px;
    padding: 5px 10px;
    margin: 3px;
    font-size: 0.85rem;
    font-family: JetBrainsMono;
    color: #111;
    background: transparent;
    border: 2px solid rgba(17, 17, 17, 0.2);
    cursor: pointer;
    display: inline-block;
    transition: all 0.2s ease;
}

code:hover {
    border-color: #111;
    background: rgba(17, 17, 17, 0.05);
}

code.active {
    color: white;
    background: #111;
    border-color: #111;
}

&#x2F;* Reset filter button - minimal override of .button class *&#x2F;
.reset-filter {
    display: none;
}

.toggle-vis {
    cursor: pointer;
    text-decoration: underline;
    text-decoration-color: rgba(17, 17, 17, 0.3);
}

.toggle-vis:hover {
    text-decoration-color: #111;
}

.toggle-vis.active {
    font-weight: bold;
}

.dt-control {
    font-family: Arial, sans-serif;
}

table.dataTable td.dt-control::before {
  color: #111;
}

&#x2F;* Dark mode support *&#x2F;
@media (prefers-color-scheme: dark) {
    .dataTables_filter input[type=&quot;search&quot;] {
        color: white;
        border-color: rgba(255, 255, 255, 0.3);
    }

    .dataTables_filter input[type=&quot;search&quot;]:focus {
        border-color: rgba(255, 255, 255, 0.6);
    }

    code {
        color: white;
        border-color: rgba(255, 255, 255, 0.2);
    }

    code:hover {
        border-color: rgba(255, 255, 255, 0.5);
        background: rgba(255, 255, 255, 0.1);
    }

    code.active {
        color: #111;
        background: white;
        border-color: white;
    }

    .toggle-vis {
        text-decoration-color: rgba(255, 255, 255, 0.3);
    }

    .toggle-vis:hover {
        text-decoration-color: white;
    }

    table.dataTable td.dt-control::before {
      color: white;
    }

    .difficultyLevel {
      color: transparent;
      text-shadow: 0 0 0 #ee3856;
    }
}

table.dataTable.dt-checkboxes-select tbody tr,
table.dataTable thead th.dt-checkboxes-select-all,
table.dataTable tbody td.dt-checkboxes-cell {
  cursor: pointer;
}

table.dataTable thead th.dt-checkboxes-select-all,
table.dataTable tbody td.dt-checkboxes-cell {
  text-align: center;
}

div.dataTables_wrapper span.select-info,
div.dataTables_wrapper span.select-item {
  margin-left: 0.5em;
}

@media screen and (max-width: 640px) {
  div.dataTables_wrapper span.select-info,
  div.dataTables_wrapper span.select-item {
    margin-left: 0;
    display: block;
  }
}

&lt;&#x2F;style&gt;
</description>
      </item>
      <item>
          <title>Arroyo</title>
          <pubDate>Thu, 25 Jan 2024 00:00:00 +0000</pubDate>
          <author>Matthias Endler</author>
          <link>https://corrode.dev/podcast/s01e04-arroyo/</link>
          <guid>https://corrode.dev/podcast/s01e04-arroyo/</guid>
          <description xml:base="https://corrode.dev/podcast/s01e04-arroyo/">&lt;div&gt;&lt;script id=&quot;letscast-player-9614e85c&quot; src=&quot;https:&#x2F;&#x2F;letscast.fm&#x2F;podcasts&#x2F;rust-in-production-82281512&#x2F;episodes&#x2F;rust-in-production-ep-4-arroyo-s-micah-wylde&#x2F;player.js?size=s&quot;&gt;&lt;&#x2F;script&gt;&lt;&#x2F;div&gt;
&lt;p&gt;In this episode, we talk to Micah Wylde, Co-founder and CEO of
&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.arroyo.dev&#x2F;&quot;&gt;Arroyo&lt;&#x2F;a&gt;, about how they simplified stream processing
for data engineers with Rust.&lt;&#x2F;p&gt;</description>
      </item>
      <item>
          <title>Tips For Faster Rust Compile Times</title>
          <pubDate>Fri, 12 Jan 2024 00:00:00 +0000</pubDate>
          <author>Matthias Endler</author>
          <link>https://corrode.dev/blog/tips-for-faster-rust-compile-times/</link>
          <guid>https://corrode.dev/blog/tips-for-faster-rust-compile-times/</guid>
          <description xml:base="https://corrode.dev/blog/tips-for-faster-rust-compile-times/">&lt;p&gt;&lt;strong&gt;Slow Rust Builds?&lt;&#x2F;strong&gt;&lt;&#x2F;p&gt;
&lt;p&gt;Here are some tips to speed up your compile times.
This list was originally released on my &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;endler.dev&#x2F;&quot;&gt;private blog&lt;&#x2F;a&gt;, but I decided to
update it and move it here.&lt;&#x2F;p&gt;
&lt;p&gt;All tips are roughly ordered by impact so you can start from the top and work your way down.&lt;&#x2F;p&gt;
&lt;h2&gt;Table of Contents&lt;&#x2F;h2&gt;
&lt;details class=&quot;toc&quot;&gt;
&lt;summary&gt;
Click here to expand the table of contents.
&lt;&#x2F;summary&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;https:&#x2F;&#x2F;corrode.dev&#x2F;blog&#x2F;tips-for-faster-rust-compile-times&#x2F;#general-tips&quot;&gt;General Tips&lt;&#x2F;a&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;https:&#x2F;&#x2F;corrode.dev&#x2F;blog&#x2F;tips-for-faster-rust-compile-times&#x2F;#update-the-rust-compiler-and-toolchain&quot;&gt;Update The Rust Compiler And Toolchain&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a href=&quot;https:&#x2F;&#x2F;corrode.dev&#x2F;blog&#x2F;tips-for-faster-rust-compile-times&#x2F;#use-cargo-check-instead-of-cargo-build&quot;&gt;Use cargo check Instead Of cargo build&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a href=&quot;https:&#x2F;&#x2F;corrode.dev&#x2F;blog&#x2F;tips-for-faster-rust-compile-times&#x2F;#remove-unused-dependencies&quot;&gt;Remove Unused Dependencies&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a href=&quot;https:&#x2F;&#x2F;corrode.dev&#x2F;blog&#x2F;tips-for-faster-rust-compile-times&#x2F;#update-dependencies&quot;&gt;Update Dependencies&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a href=&quot;https:&#x2F;&#x2F;corrode.dev&#x2F;blog&#x2F;tips-for-faster-rust-compile-times&#x2F;#find-the-slow-crate-in-your-codebase&quot;&gt;Find the slow crate in your codebase&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a href=&quot;https:&#x2F;&#x2F;corrode.dev&#x2F;blog&#x2F;tips-for-faster-rust-compile-times&#x2F;#profile-compile-times&quot;&gt;Profile Compile Times&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a href=&quot;https:&#x2F;&#x2F;corrode.dev&#x2F;blog&#x2F;tips-for-faster-rust-compile-times&#x2F;#troubleshoot-slow-incremental-builds&quot;&gt;Troubleshoot Slow Incremental Builds&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a href=&quot;https:&#x2F;&#x2F;corrode.dev&#x2F;blog&#x2F;tips-for-faster-rust-compile-times&#x2F;#replace-heavy-dependencies&quot;&gt;Replace Heavy Dependencies&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a href=&quot;https:&#x2F;&#x2F;corrode.dev&#x2F;blog&#x2F;tips-for-faster-rust-compile-times&#x2F;#split-big-crates-into-smaller-ones-using-workspaces&quot;&gt;Split Big Crates Into Smaller Ones Using Workspaces&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a href=&quot;https:&#x2F;&#x2F;corrode.dev&#x2F;blog&#x2F;tips-for-faster-rust-compile-times&#x2F;#disable-unused-features-of-crate-dependencies&quot;&gt;Disable Unused Features Of Crate Dependencies&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a href=&quot;https:&#x2F;&#x2F;corrode.dev&#x2F;blog&#x2F;tips-for-faster-rust-compile-times&#x2F;#add-features-for-expensive-code&quot;&gt;Add Features For Expensive Code&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a href=&quot;https:&#x2F;&#x2F;corrode.dev&#x2F;blog&#x2F;tips-for-faster-rust-compile-times&#x2F;#find-the-root-cause-for-rebuilds&quot;&gt;Find The Root Cause For Rebuilds&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a href=&quot;https:&#x2F;&#x2F;corrode.dev&#x2F;blog&#x2F;tips-for-faster-rust-compile-times&#x2F;#cache-dependencies-with-sccache&quot;&gt;Cache Dependencies With sccache&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a href=&quot;https:&#x2F;&#x2F;corrode.dev&#x2F;blog&#x2F;tips-for-faster-rust-compile-times&#x2F;#cranelift-the-alternative-rust-compiler&quot;&gt;Cranelift: The Alternative Rust Compiler&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a href=&quot;https:&#x2F;&#x2F;corrode.dev&#x2F;blog&#x2F;tips-for-faster-rust-compile-times&#x2F;#switch-to-a-faster-linker&quot;&gt;Switch To A Faster Linker&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a href=&quot;https:&#x2F;&#x2F;corrode.dev&#x2F;blog&#x2F;tips-for-faster-rust-compile-times&#x2F;#macos-only-faster-incremental-debug-builds&quot;&gt;macOS Only: Faster Incremental Debug Builds&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a href=&quot;https:&#x2F;&#x2F;corrode.dev&#x2F;blog&#x2F;tips-for-faster-rust-compile-times&#x2F;#macos-only-exclude-rust-compilations-from-gatekeeper&quot;&gt;macOS Only: Exclude Rust Compilations From Gatekeeper&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a href=&quot;https:&#x2F;&#x2F;corrode.dev&#x2F;blog&#x2F;tips-for-faster-rust-compile-times&#x2F;#windows-only-set-up-dev-drive-for-rust&quot;&gt;Windows Only: Set Up Dev Drive For Rust&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a href=&quot;https:&#x2F;&#x2F;corrode.dev&#x2F;blog&#x2F;tips-for-faster-rust-compile-times&#x2F;#tweak-codegen-options-and-compiler-flags&quot;&gt;Tweak Codegen Options And Compiler Flags&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a href=&quot;https:&#x2F;&#x2F;corrode.dev&#x2F;blog&#x2F;tips-for-faster-rust-compile-times&#x2F;#avoid-procedural-macro-crates&quot;&gt;Avoid Procedural Macro Crates&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a href=&quot;https:&#x2F;&#x2F;corrode.dev&#x2F;blog&#x2F;tips-for-faster-rust-compile-times&#x2F;#find-expensive-proc-macros&quot;&gt;Find Expensive Proc Macros&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a href=&quot;https:&#x2F;&#x2F;corrode.dev&#x2F;blog&#x2F;tips-for-faster-rust-compile-times&#x2F;#conditional-compilation-for-procedural-macros&quot;&gt;Conditional Compilation for Procedural Macros&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a href=&quot;https:&#x2F;&#x2F;corrode.dev&#x2F;blog&#x2F;tips-for-faster-rust-compile-times&#x2F;#generics-use-an-inner-non-generic-function&quot;&gt;Generics: Use an Inner Non-Generic Function&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a href=&quot;https:&#x2F;&#x2F;corrode.dev&#x2F;blog&#x2F;tips-for-faster-rust-compile-times&#x2F;#improve-workspace-build-times-with-cargo-hakari&quot;&gt;Improve Workspace Build Times with cargo-hakari&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a href=&quot;https:&#x2F;&#x2F;corrode.dev&#x2F;blog&#x2F;tips-for-faster-rust-compile-times&#x2F;#speeding-up-incremental-rust-compilation-with-dylibs&quot;&gt;Speeding up incremental Rust compilation with dylibs&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a href=&quot;https:&#x2F;&#x2F;corrode.dev&#x2F;blog&#x2F;tips-for-faster-rust-compile-times&#x2F;#switch-to-the-new-parallel-compiler-frontend&quot;&gt;Switch To The New Parallel Compiler Frontend&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a href=&quot;https:&#x2F;&#x2F;corrode.dev&#x2F;blog&#x2F;tips-for-faster-rust-compile-times&#x2F;#use-a-scratch-disk-for-faster-builds&quot;&gt;Use A Scratch Disk For Faster Builds&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a href=&quot;https:&#x2F;&#x2F;corrode.dev&#x2F;blog&#x2F;tips-for-faster-rust-compile-times&#x2F;#invest-in-better-hardware&quot;&gt;Invest In Better Hardware&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a href=&quot;https:&#x2F;&#x2F;corrode.dev&#x2F;blog&#x2F;tips-for-faster-rust-compile-times&#x2F;#compile-in-the-cloud&quot;&gt;Compile in the Cloud&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a href=&quot;https:&#x2F;&#x2F;corrode.dev&#x2F;blog&#x2F;tips-for-faster-rust-compile-times&#x2F;#cache-all-crates-locally&quot;&gt;Cache All Crates Locally&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a href=&quot;https:&#x2F;&#x2F;corrode.dev&#x2F;blog&#x2F;tips-for-faster-rust-compile-times&#x2F;#test-execution&quot;&gt;Test Execution&lt;&#x2F;a&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;https:&#x2F;&#x2F;corrode.dev&#x2F;blog&#x2F;tips-for-faster-rust-compile-times&#x2F;#use-cargo-nextest-instead-of-cargo-test&quot;&gt;Use Cargo Nextest Instead of &lt;code&gt;cargo test&lt;&#x2F;code&gt;&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a href=&quot;https:&#x2F;&#x2F;corrode.dev&#x2F;blog&#x2F;tips-for-faster-rust-compile-times&#x2F;#combine-all-integration-tests-into-a-single-binary&quot;&gt;Combine All Integration Tests Into A Single Binary&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a href=&quot;https:&#x2F;&#x2F;corrode.dev&#x2F;blog&#x2F;tips-for-faster-rust-compile-times&#x2F;#put-slow-tests-behind-an-environment-variable&quot;&gt;Put slow tests behind an environment variable&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a href=&quot;https:&#x2F;&#x2F;corrode.dev&#x2F;blog&#x2F;tips-for-faster-rust-compile-times&#x2F;#ci-builds&quot;&gt;CI Builds&lt;&#x2F;a&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;https:&#x2F;&#x2F;corrode.dev&#x2F;blog&#x2F;tips-for-faster-rust-compile-times&#x2F;#use-a-cache-for-your-dependencies&quot;&gt;Use A Cache For Your Dependencies&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a href=&quot;https:&#x2F;&#x2F;corrode.dev&#x2F;blog&#x2F;tips-for-faster-rust-compile-times&#x2F;#split-up-compile-and-test-steps&quot;&gt;Split Up Compile And Test Steps&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a href=&quot;https:&#x2F;&#x2F;corrode.dev&#x2F;blog&#x2F;tips-for-faster-rust-compile-times&#x2F;#disable-incremental-compilation-in-ci&quot;&gt;Disable Incremental Compilation In CI&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a href=&quot;https:&#x2F;&#x2F;corrode.dev&#x2F;blog&#x2F;tips-for-faster-rust-compile-times&#x2F;#turn-off-debuginfo&quot;&gt;Turn Off Debuginfo&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a href=&quot;https:&#x2F;&#x2F;corrode.dev&#x2F;blog&#x2F;tips-for-faster-rust-compile-times&#x2F;#deny-warnings-through-an-environment-variable&quot;&gt;Deny Warnings Through An Environment Variable&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a href=&quot;https:&#x2F;&#x2F;corrode.dev&#x2F;blog&#x2F;tips-for-faster-rust-compile-times&#x2F;#switch-to-a-faster-github-actions-runner&quot;&gt;Switch To A Faster Github Actions Runner&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a href=&quot;https:&#x2F;&#x2F;corrode.dev&#x2F;blog&#x2F;tips-for-faster-rust-compile-times&#x2F;#faster-docker-builds&quot;&gt;Faster Docker Builds&lt;&#x2F;a&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;https:&#x2F;&#x2F;corrode.dev&#x2F;blog&#x2F;tips-for-faster-rust-compile-times&#x2F;#use-cargo-chef-to-speed-up-docker-builds&quot;&gt;Use &lt;code&gt;cargo-chef&lt;&#x2F;code&gt; To Speed Up Docker Builds&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a href=&quot;https:&#x2F;&#x2F;corrode.dev&#x2F;blog&#x2F;tips-for-faster-rust-compile-times&#x2F;#consider-earthly-for-better-build-caching&quot;&gt;Consider Earthly For Better Build Caching&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a href=&quot;https:&#x2F;&#x2F;corrode.dev&#x2F;blog&#x2F;tips-for-faster-rust-compile-times&#x2F;#ide-specific-optimizations&quot;&gt;IDE Specific Optimizations&lt;&#x2F;a&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;https:&#x2F;&#x2F;corrode.dev&#x2F;blog&#x2F;tips-for-faster-rust-compile-times&#x2F;#slow-debug-sessions-in-visual-studio-code&quot;&gt;Slow Debug Sessions In Visual Studio Code&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a href=&quot;https:&#x2F;&#x2F;corrode.dev&#x2F;blog&#x2F;tips-for-faster-rust-compile-times&#x2F;#close-unrelated-projects&quot;&gt;Close Unrelated Projects&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a href=&quot;https:&#x2F;&#x2F;corrode.dev&#x2F;blog&#x2F;tips-for-faster-rust-compile-times&#x2F;#fix-rust-analyzer-cache-invalidation&quot;&gt;Fix Rust Analyzer Cache Invalidation&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;details&gt;
&lt;h2 id=&quot;general-tips&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#general-tips&quot; aria-label=&quot;Anchor link for: general-tips&quot;&gt;General Tips&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;h3 id=&quot;update-the-rust-compiler-and-toolchain&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#update-the-rust-compiler-and-toolchain&quot; aria-label=&quot;Anchor link for: update-the-rust-compiler-and-toolchain&quot;&gt;Update The Rust Compiler And Toolchain&lt;&#x2F;a&gt;&lt;&#x2F;h3&gt;
&lt;p&gt;Make sure you use the latest Rust version:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;plain&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;rustup update&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Making the Rust compiler faster is an &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;blog.mozilla.org&#x2F;nnethercote&#x2F;2020&#x2F;04&#x2F;24&#x2F;how-to-speed-up-the-rust-compiler-in-2020&#x2F;&quot;&gt;ongoing process&lt;&#x2F;a&gt;.
Thanks to their hard work, compiler speed has improved &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.reddit.com&#x2F;r&#x2F;rust&#x2F;comments&#x2F;cezxjn&#x2F;compiler_speed_has_improved_3040_across_the_board&#x2F;&quot;&gt;30-40% across the board
year-to-date, with some projects seeing up to 45%+ improvements&lt;&#x2F;a&gt;. It pays off to keep your toolchain up-to-date.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;use-cargo-check-instead-of-cargo-build&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#use-cargo-check-instead-of-cargo-build&quot; aria-label=&quot;Anchor link for: use-cargo-check-instead-of-cargo-build&quot;&gt;Use cargo check Instead Of cargo build&lt;&#x2F;a&gt;&lt;&#x2F;h3&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;shellscript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;# Slow 🐢&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;cargo&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt; build&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;# Fast 🐇 (2x-3x speedup)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;cargo&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt; check&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Most of the time, you don’t even have to &lt;em&gt;compile&lt;&#x2F;em&gt; your project at all; you just
want to know if you messed up somewhere. Whenever you can, &lt;strong&gt;skip compilation
altogether&lt;&#x2F;strong&gt;. What you need instead is laser-fast code linting, type- and
borrow-checking.&lt;&#x2F;p&gt;
&lt;p&gt;Use &lt;code&gt;cargo check&lt;&#x2F;code&gt; instead of &lt;code&gt;cargo build&lt;&#x2F;code&gt; whenever possible.
It will only check your code for errors, but not produce an executable binary.&lt;&#x2F;p&gt;
&lt;p&gt;Consider the differences in the number of instructions between &lt;code&gt;cargo check&lt;&#x2F;code&gt; on
the left and &lt;code&gt;cargo debug&lt;&#x2F;code&gt; in the middle. (Pay attention to the different
scales.)&lt;&#x2F;p&gt;
&lt;p&gt;&lt;img src=&quot;https:&#x2F;&#x2F;corrode.dev&#x2F;blog&#x2F;tips-for-faster-rust-compile-times&#x2F;cargo-check.png&quot; alt=&quot;Speedup factors: check 1, debug 5, opt 20&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;p&gt;A sweet trick I use is to run it in the background with &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;passcod&#x2F;cargo-watch&quot;&gt;&lt;code&gt;cargo watch&lt;&#x2F;code&gt;&lt;&#x2F;a&gt;. This way, it will &lt;code&gt;cargo check&lt;&#x2F;code&gt;
whenever you change a file.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;strong&gt;Bonus&lt;&#x2F;strong&gt;: Use &lt;code&gt;cargo watch -c&lt;&#x2F;code&gt; to clear the screen before every run.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;remove-unused-dependencies&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#remove-unused-dependencies&quot; aria-label=&quot;Anchor link for: remove-unused-dependencies&quot;&gt;Remove Unused Dependencies&lt;&#x2F;a&gt;&lt;&#x2F;h3&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;shellscript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;# Install cargo-machete 🔪️&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;cargo&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt; install cargo-machete&lt;&#x2F;span&gt;&lt;span&gt; &amp;amp;&amp;amp;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; cargo&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt; machete&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;# Install cargo-shear ✂️🐑&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;cargo&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt; install cargo-shear&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;# Install cargo-udeps 🧼🧹️&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;cargo&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt; install cargo-udeps&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt; --locked&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Dependencies sometimes become obsolete after refactoring. From time to time
it helps to check if you can remove any unused dependencies.&lt;&#x2F;p&gt;
&lt;p&gt;The above tools will list all unused dependencies in your project.
Each tool has its limitations, producing both false positives and false negatives. Using all three tools together provides the best results.&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;shellscript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;Analyzing&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt; dependencies of crates in this directory...&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;cargo-machete&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt; found the following unused dependencies in&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; &amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt;projec&lt;&#x2F;span&gt;&lt;span&gt;t&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt;:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;crate1&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt; --&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; &amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt;projec&lt;&#x2F;span&gt;&lt;span&gt;t&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt;&#x2F;Cargo.toml:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;        clap&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;crate2&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt; --&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; &amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt;projec&lt;&#x2F;span&gt;&lt;span&gt;t&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt;&#x2F;crate2&#x2F;Cargo.toml:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;        anyhow&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;        async-once-cell&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #8BE9FD;&quot;&gt;        dirs&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;        log&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;        tracing&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;        url&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;More info on the &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;bnjbvr&#x2F;cargo-machete&quot;&gt;cargo-machete&lt;&#x2F;a&gt;, &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;Boshen&#x2F;cargo-shear&quot;&gt;cargo-shear&lt;&#x2F;a&gt;, and &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;est31&#x2F;cargo-udeps&quot;&gt;cargo-udeps&lt;&#x2F;a&gt; project pages.&lt;&#x2F;p&gt;
&lt;p&gt;Thanks for mentioning &lt;code&gt;cargo-shear&lt;&#x2F;code&gt; and &lt;code&gt;cargo-udeps&lt;&#x2F;code&gt; to reader &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;nnethercote.github.io&#x2F;&quot;&gt;Nicholas Nethercote&lt;&#x2F;a&gt; who is the author of the &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;nnethercote.github.io&#x2F;perf-book&#x2F;&quot;&gt;Rust Performance Book&lt;&#x2F;a&gt; and the famous &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;nnethercote.github.io&#x2F;2025&#x2F;05&#x2F;22&#x2F;how-to-speed-up-the-rust-compiler-in-may-2025.html&quot;&gt;How to speed up the Rust compiler series&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;update-dependencies&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#update-dependencies&quot; aria-label=&quot;Anchor link for: update-dependencies&quot;&gt;Update Dependencies&lt;&#x2F;a&gt;&lt;&#x2F;h3&gt;
&lt;ol&gt;
&lt;li&gt;Run &lt;code&gt;cargo update&lt;&#x2F;code&gt; to update to the latest &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;semver.org&#x2F;&quot;&gt;semver&lt;&#x2F;a&gt;
compatible version.&lt;&#x2F;li&gt;
&lt;li&gt;Run &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;kbknapp&#x2F;cargo-outdated&quot;&gt;&lt;code&gt;cargo outdated -wR&lt;&#x2F;code&gt;&lt;&#x2F;a&gt; to find newer, possibly incompatible dependencies.
Update those and fix code as needed.&lt;&#x2F;li&gt;
&lt;li&gt;Run &lt;code&gt;cargo tree --duplicate&lt;&#x2F;code&gt; to find dependencies which come in multiple versions.
Aim to consolidate to a single version by updating dependencies that rely on older versions.
(Thanks to &#x2F;u&#x2F;dbdr for &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.reddit.com&#x2F;r&#x2F;rust&#x2F;comments&#x2F;hdb5m4&#x2F;tips_for_faster_rust_compile_times&#x2F;fvm1r2w&#x2F;&quot;&gt;pointing this out&lt;&#x2F;a&gt;.)&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;p&gt;(Instructions by &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.reddit.com&#x2F;r&#x2F;rust&#x2F;comments&#x2F;gi7v2v&#x2F;is_it_wrong_of_me_to_think_that_rust_crates_have&#x2F;fqe848y&quot;&gt;&#x2F;u&#x2F;oherrala on Reddit&lt;&#x2F;a&gt;.)&lt;&#x2F;p&gt;
&lt;p&gt;On top of that, use &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;RustSec&#x2F;cargo-audit&quot;&gt;&lt;code&gt;cargo audit&lt;&#x2F;code&gt;&lt;&#x2F;a&gt; to
get notified about any vulnerabilities which need to be addressed, or deprecated
crates which need a replacement.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;find-the-slow-crate-in-your-codebase&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#find-the-slow-crate-in-your-codebase&quot; aria-label=&quot;Anchor link for: find-the-slow-crate-in-your-codebase&quot;&gt;Find the slow crate in your codebase&lt;&#x2F;a&gt;&lt;&#x2F;h3&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;shellscript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;cargo&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt; build&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt; --timings&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;This gives information about how long each crate takes to compile.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;img src=&quot;https:&#x2F;&#x2F;corrode.dev&#x2F;blog&#x2F;tips-for-faster-rust-compile-times&#x2F;cargo-concurrency-over-time.png&quot; alt=&quot;Diagram of cargo build –timings&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;p&gt;The red line in this diagram shows the number of units (crates) that are
currently waiting to be compiled (and are blocked by another crate).
If there are a large number of crates bottlenecked on a single crate, focus your
attention on improving that one crate to improve parallelism.&lt;&#x2F;p&gt;
&lt;p&gt;The meaning of the colors:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;em&gt;Waiting&lt;&#x2F;em&gt; (red) — Crates waiting for a CPU slot to open.&lt;&#x2F;li&gt;
&lt;li&gt;&lt;em&gt;Inactive&lt;&#x2F;em&gt; (blue) — Crates that are waiting for their dependencies to finish.&lt;&#x2F;li&gt;
&lt;li&gt;&lt;em&gt;Active&lt;&#x2F;em&gt; (green) — Crates currently being compiled.&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;More info &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;doc.rust-lang.org&#x2F;cargo&#x2F;reference&#x2F;timings.html&quot;&gt;in the documentation&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;profile-compile-times&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#profile-compile-times&quot; aria-label=&quot;Anchor link for: profile-compile-times&quot;&gt;Profile Compile Times&lt;&#x2F;a&gt;&lt;&#x2F;h3&gt;
&lt;p&gt;If you like to dig deeper than &lt;code&gt;cargo --timings&lt;&#x2F;code&gt;, Rust compilation can be profiled with &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;blog.rust-lang.org&#x2F;inside-rust&#x2F;2020&#x2F;02&#x2F;25&#x2F;intro-rustc-self-profile.html#profiling-the-compiler&quot;&gt;&lt;code&gt;cargo rustc -- -Zself-profile&lt;&#x2F;code&gt;&lt;&#x2F;a&gt;.
The resulting trace file can be visualized with a flamegraph or the Chromium
profiler:&lt;&#x2F;p&gt;
&lt;p&gt;&lt;img src=&quot;https:&#x2F;&#x2F;corrode.dev&#x2F;blog&#x2F;tips-for-faster-rust-compile-times&#x2F;chrome_profiler.png&quot; alt=&quot;Image of Chrome profiler with all crates&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;p&gt;Another golden one is
&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;dtolnay&#x2F;cargo-llvm-lines&quot;&gt;&lt;code&gt;cargo-llvm-lines&lt;&#x2F;code&gt;&lt;&#x2F;a&gt;, which shows
the number of lines generated and the number of copies of each generic function in the
final binary. This can help you identify which functions are the most expensive
to compile.&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;plain&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;$ cargo llvm-lines | head -20&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  Lines        Copies         Function name&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  -----        ------         -------------&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  30737 (100%)   1107 (100%)  (TOTAL)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;   1395 (4.5%)     83 (7.5%)  core::ptr::drop_in_place&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    760 (2.5%)      2 (0.2%)  alloc::slice::merge_sort&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    734 (2.4%)      2 (0.2%)  alloc::raw_vec::RawVec&amp;lt;T,A&amp;gt;::reserve_internal&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    666 (2.2%)      1 (0.1%)  cargo_llvm_lines::count_lines&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    490 (1.6%)      1 (0.1%)  &amp;lt;std::process::Command as cargo_llvm_lines::PipeTo&amp;gt;::pipe_to&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    476 (1.5%)      6 (0.5%)  core::result::Result&amp;lt;T,E&amp;gt;::map&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    440 (1.4%)      1 (0.1%)  cargo_llvm_lines::read_llvm_ir&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    422 (1.4%)      2 (0.2%)  alloc::slice::merge&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    399 (1.3%)      4 (0.4%)  alloc::vec::Vec&amp;lt;T&amp;gt;::extend_desugared&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    388 (1.3%)      2 (0.2%)  alloc::slice::insert_head&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    366 (1.2%)      5 (0.5%)  core::option::Option&amp;lt;T&amp;gt;::map&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    304 (1.0%)      6 (0.5%)  alloc::alloc::box_free&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    296 (1.0%)      4 (0.4%)  core::result::Result&amp;lt;T,E&amp;gt;::map_err&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    295 (1.0%)      1 (0.1%)  cargo_llvm_lines::wrap_args&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    291 (0.9%)      1 (0.1%)  core::char::methods::&amp;lt;impl char&amp;gt;::encode_utf8&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    286 (0.9%)      1 (0.1%)  cargo_llvm_lines::run_cargo_rustc&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    284 (0.9%)      4 (0.4%)  core::option::Option&amp;lt;T&amp;gt;::ok_or_else&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;&lt;h3 id=&quot;troubleshoot-slow-incremental-builds&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#troubleshoot-slow-incremental-builds&quot; aria-label=&quot;Anchor link for: troubleshoot-slow-incremental-builds&quot;&gt;Troubleshoot Slow Incremental Builds&lt;&#x2F;a&gt;&lt;&#x2F;h3&gt;
&lt;p&gt;If your incremental builds are slower than expected, you might be bottlenecked on a particular crate in the rustc backend.&lt;&#x2F;p&gt;
&lt;p&gt;To diagnose this, you can use &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;mstange&#x2F;samply&quot;&gt;&lt;code&gt;samply&lt;&#x2F;code&gt;&lt;&#x2F;a&gt; combined with the &lt;code&gt;-Zhuman_readable_cgu_names=yes&lt;&#x2F;code&gt; flag to profile the compiler and identify which codegen units are taking the longest to compile:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;shellscript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;samply&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt; record cargo build&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;This will help you identify if a particular crate is the long pole in your build. Once you’ve identified the bottleneck, you may be able to improve compile times by refactoring or splitting the problematic crate.&lt;&#x2F;p&gt;
&lt;p&gt;For more details on back-end parallelism in the Rust compiler, see &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;nnethercote.github.io&#x2F;2023&#x2F;07&#x2F;11&#x2F;back-end-parallelism-in-the-rust-compiler.html&quot;&gt;Nicholas Nethercote’s blog post&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;Another useful flag is &lt;code&gt;-Zprint-mono-items=yes&lt;&#x2F;code&gt;, which prints all &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;rustc-dev-guide.rust-lang.org&#x2F;backend&#x2F;monomorph.html&quot;&gt;monomorphized items&lt;&#x2F;a&gt; during compilation. This can help you understand what’s being generated in each CGU.&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;shellscript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt;RUSTFLAGS&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;=&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E9F284;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt;-Zprint-mono-items=yes&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E9F284;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; cargo&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt; +nightly build                                               ⏎&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;&lt;em&gt;Thanks to &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;slowrush.dev&quot;&gt;Caspar&lt;&#x2F;a&gt; (asparck on &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.reddit.com&#x2F;r&#x2F;rust&#x2F;comments&#x2F;1q8x25s&#x2F;debugging_a_slowcompiling_codegen_unit&#x2F;&quot;&gt;Reddit&lt;&#x2F;a&gt;) for this tip!&lt;&#x2F;em&gt;&lt;&#x2F;p&gt;
&lt;h3 id=&quot;replace-heavy-dependencies&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#replace-heavy-dependencies&quot; aria-label=&quot;Anchor link for: replace-heavy-dependencies&quot;&gt;Replace Heavy Dependencies&lt;&#x2F;a&gt;&lt;&#x2F;h3&gt;
&lt;p&gt;From time to time, it helps to shop around for more lightweight alternatives to
popular crates.&lt;&#x2F;p&gt;
&lt;p&gt;Again, &lt;code&gt;cargo tree&lt;&#x2F;code&gt; is your friend here to help you understand which of your
dependencies are quite &lt;em&gt;heavy&lt;&#x2F;em&gt;: they require many other crates, cause
excessive network I&#x2F;O and slow down your build. Then search for lighter
alternatives.&lt;&#x2F;p&gt;
&lt;p&gt;Also, &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;RazrFalcon&#x2F;cargo-bloat&quot;&gt;&lt;code&gt;cargo-bloat&lt;&#x2F;code&gt;&lt;&#x2F;a&gt; has a &lt;code&gt;--time&lt;&#x2F;code&gt;
flag that shows you the per-crate build time. Very handy!&lt;&#x2F;p&gt;
&lt;p&gt;Here are a few examples:&lt;&#x2F;p&gt;
&lt;table&gt;&lt;thead&gt;&lt;tr&gt;&lt;th style=&quot;text-align: left&quot;&gt;Crate&lt;&#x2F;th&gt;&lt;th style=&quot;text-align: left&quot;&gt;Alternative&lt;&#x2F;th&gt;&lt;&#x2F;tr&gt;&lt;&#x2F;thead&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: left&quot;&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;bnjbvr&#x2F;cargo-machete&quot;&gt;serde&lt;&#x2F;a&gt;&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: left&quot;&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;dtolnay&#x2F;miniserde&quot;&gt;miniserde&lt;&#x2F;a&gt;, &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;not-fl3&#x2F;nanoserde&quot;&gt;nanoserde&lt;&#x2F;a&gt;&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: left&quot;&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;seanmonstar&#x2F;reqwest&quot;&gt;reqwest&lt;&#x2F;a&gt;&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: left&quot;&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;algesten&#x2F;ureq&quot;&gt;ureq&lt;&#x2F;a&gt;&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: left&quot;&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;clap-rs&#x2F;clap&quot;&gt;clap&lt;&#x2F;a&gt;&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: left&quot;&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;blyxxyz&#x2F;lexopt&quot;&gt;lexopt&lt;&#x2F;a&gt;&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;&#x2F;tbody&gt;&lt;&#x2F;table&gt;
&lt;p&gt;Here’s an example where switching crates reduced compile times &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;blog.kodewerx.org&#x2F;2020&#x2F;06&#x2F;the-rust-compiler-isnt-slow-we-are.html&quot;&gt;from 2:22min to
26
seconds&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;split-big-crates-into-smaller-ones-using-workspaces&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#split-big-crates-into-smaller-ones-using-workspaces&quot; aria-label=&quot;Anchor link for: split-big-crates-into-smaller-ones-using-workspaces&quot;&gt;Split Big Crates Into Smaller Ones Using Workspaces&lt;&#x2F;a&gt;&lt;&#x2F;h3&gt;
&lt;p&gt;Cargo has that neat feature called &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;doc.rust-lang.org&#x2F;book&#x2F;ch14-03-cargo-workspaces.html&quot;&gt;workspaces&lt;&#x2F;a&gt;, which allow you to split one
big crate into multiple smaller ones. This code-splitting is great for avoiding
repetitive compilation because only crates with changes have to be recompiled.
Bigger projects like
&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;servo&#x2F;servo&#x2F;blob&#x2F;master&#x2F;Cargo.toml&quot;&gt;servo&lt;&#x2F;a&gt; and
&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;timberio&#x2F;vector&#x2F;blob&#x2F;1629f7f82e459ae87f699e931ca2b89b9080cfde&#x2F;Cargo.toml#L28-L34&quot;&gt;vector&lt;&#x2F;a&gt;
make heavy use of workspaces to reduce compile times.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;disable-unused-features-of-crate-dependencies&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#disable-unused-features-of-crate-dependencies&quot; aria-label=&quot;Anchor link for: disable-unused-features-of-crate-dependencies&quot;&gt;Disable Unused Features Of Crate Dependencies&lt;&#x2F;a&gt;&lt;&#x2F;h3&gt;
&lt;p&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;ToBinio&#x2F;cargo-features-manager&quot;&gt;&lt;code&gt;cargo-features-manager&lt;&#x2F;code&gt;&lt;&#x2F;a&gt; is a relatively new tool that helps you to disable unused features of your dependencies.&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;shellscript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;cargo&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt; install cargo-features-manager&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;cargo&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt; features prune&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;From time to time, check the feature flags of your dependencies. A lot of
library maintainers take the effort to split their crate into separate features
that can be toggled off on demand. Maybe you don’t need all the default
functionality from every crate?&lt;&#x2F;p&gt;
&lt;p&gt;For example, &lt;code&gt;tokio&lt;&#x2F;code&gt; has &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;tokio-rs&#x2F;tokio&#x2F;blob&#x2F;2bc6bc14a82dc4c8d447521005e044028ae199fe&#x2F;tokio&#x2F;Cargo.toml#L26-L91&quot;&gt;a ton of
features&lt;&#x2F;a&gt;
that you can disable if not needed.&lt;&#x2F;p&gt;
&lt;p&gt;Another example is &lt;code&gt;bindgen&lt;&#x2F;code&gt;, which enables &lt;code&gt;clap&lt;&#x2F;code&gt; support by default for its
binary usage. This isn’t needed for library usage, which is the common use-case.
Disabling that feature &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;rust-rocksdb&#x2F;rust-rocksdb&#x2F;pull&#x2F;491&quot;&gt;improved compile time of rust-rocksdb by ~13s and ~9s
for debug and release builds
respectively&lt;&#x2F;a&gt;. Thanks to
reader &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;lilianmoraru&quot;&gt;Lilian Anatolie Moraru&lt;&#x2F;a&gt; for mentioning
this.&lt;&#x2F;p&gt;
&lt;div class=&quot;info&quot;&gt;
  
  &lt;div class=&quot;info-header&quot;&gt;
    
      &lt;span class=&quot;icon icon-warning&quot;&gt;&lt;&#x2F;span&gt;
    
    &lt;h4&gt;&lt;p&gt;Fair Warning&lt;&#x2F;p&gt;
&lt;&#x2F;h4&gt;
  &lt;&#x2F;div&gt;
  
  &lt;p&gt;It seems that switching off features doesn’t always improve
compile time. (See &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;tikv&#x2F;tikv&#x2F;pull&#x2F;4453#issuecomment-481789292&quot;&gt;tikv’s experiences
here&lt;&#x2F;a&gt;.)
It may still be a good idea for improving security by reducing the code’s attack surface.
Furthermore, disabling features can help slim down the dependency tree.&lt;&#x2F;p&gt;

&lt;&#x2F;div&gt;
&lt;p&gt;You get a list of features of a crate when installing it with &lt;code&gt;cargo add&lt;&#x2F;code&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;If you want to look up the feature flags of a crate, they are listed on
&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;docs.rs&#x2F;&quot;&gt;docs.rs&lt;&#x2F;a&gt;. E.g. check out &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;docs.rs&#x2F;crate&#x2F;tokio&#x2F;latest&#x2F;features&quot;&gt;tokio’s feature
flags&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;After you removed unused features, check the diff of your &lt;code&gt;Cargo.lock&lt;&#x2F;code&gt; file to
see all the unnecessary dependencies that got cleaned up.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;add-features-for-expensive-code&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#add-features-for-expensive-code&quot; aria-label=&quot;Anchor link for: add-features-for-expensive-code&quot;&gt;Add Features For Expensive Code&lt;&#x2F;a&gt;&lt;&#x2F;h3&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;toml&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;[&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;&quot;&gt;features&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;# Basic feature for default functionality&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #8BE9FD;&quot;&gt;default&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; []&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;# Optional feature for JSON support&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #8BE9FD;&quot;&gt;json&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; [&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E9F284;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt;serde_json&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E9F284;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;# Another optional feature for more expensive or complex code&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #8BE9FD;&quot;&gt;complex_feature&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; [&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E9F284;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt;some-expensive-crate&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E9F284;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Not all the code in your project is equally expensive to compile. You can use
Cargo features to split up your code into smaller chunks on a more granular
level than crates. This way, you can compile only the functionality you need.&lt;&#x2F;p&gt;
&lt;p&gt;This is a common practice for libraries. For example, &lt;code&gt;serde&lt;&#x2F;code&gt; has a feature
called &lt;code&gt;derive&lt;&#x2F;code&gt; that enables code generation for serialization and
deserialization. It’s not always needed, so it’s disabled by default.
Similarly, &lt;code&gt;Tokio&lt;&#x2F;code&gt; and &lt;code&gt;reqwest&lt;&#x2F;code&gt; have a lot of features that can be enabled or
disabled.&lt;&#x2F;p&gt;
&lt;p&gt;You can do the same in your code. In the above example, the &lt;code&gt;json&lt;&#x2F;code&gt; feature
in your &lt;code&gt;Cargo.toml&lt;&#x2F;code&gt; enables JSON support while the &lt;code&gt;complex_feature&lt;&#x2F;code&gt; feature
enables another expensive code path.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;find-the-root-cause-for-rebuilds&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#find-the-root-cause-for-rebuilds&quot; aria-label=&quot;Anchor link for: find-the-root-cause-for-rebuilds&quot;&gt;Find The Root Cause For Rebuilds&lt;&#x2F;a&gt;&lt;&#x2F;h3&gt;
&lt;p&gt;Sometimes many crates rebuild even when no code has changed, often due to environment variable differences between build processes (like your Makefile builds vs rust-analyzer vs CI builds).&lt;&#x2F;p&gt;
&lt;p&gt;Use cargo’s fingerprint logging to identify exactly why rebuilds are triggered:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;shellscript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;export&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt; CARGO_LOG&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;=&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E9F284;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt;cargo::core::compiler::fingerprint=info&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E9F284;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;export&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt; RUST_LOG&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;=&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt;trace&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;cargo&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt; build&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt; -vv&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Look for lines showing what caused the rebuild.
For example:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;plain&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;INFO prepare_target: cargo::core::compiler::fingerprint: dirty: EnvVarChanged { name: &amp;quot;VIRTUAL_ENV&amp;quot;, old_value: None, new_value: Some(&amp;quot;&#x2F;path&#x2F;to&#x2F;.venv&amp;quot;) }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;Dirty pyo3-build-config v0.24.1: the env variable VIRTUAL_ENV changed&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;See that “Dirty” line? It tells you exactly what caused the rebuild.
You can grep for that line to find all rebuild causes.&lt;&#x2F;p&gt;
&lt;p&gt;Common culprits include:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;Environment variables (CC, CXX, VIRTUAL_ENV, PATH changes)&lt;&#x2F;li&gt;
&lt;li&gt;Feature flag mismatches between different build tools&lt;&#x2F;li&gt;
&lt;li&gt;Different cargo profiles being used&lt;&#x2F;li&gt;
&lt;li&gt;Timestamp differences in generated files&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;Once you identify the cause, ensure consistency across all your build processes. For rust-analyzer in VS Code, you can configure matching environment variables in &lt;code&gt;.vscode&#x2F;settings.json&lt;&#x2F;code&gt;:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;json&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;{&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #8BE9FE;&quot;&gt;  &amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;&quot;&gt;rust-analyzer.check.extraEnv&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FE;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #8BE9FE;&quot;&gt;    &amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;&quot;&gt;CC&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FE;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E9F284;&quot;&gt; &amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt;clang&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E9F284;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #8BE9FE;&quot;&gt;    &amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;&quot;&gt;CXX&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FE;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E9F284;&quot;&gt; &amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt;clang++&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E9F284;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;, &lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #8BE9FE;&quot;&gt;    &amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;&quot;&gt;VIRTUAL_ENV&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FE;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E9F284;&quot;&gt; &amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt;&#x2F;path&#x2F;to&#x2F;your&#x2F;.venv&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E9F284;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  },&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #8BE9FE;&quot;&gt;  &amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;&quot;&gt;rust-analyzer.cargo.features&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FE;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E9F284;&quot;&gt; &amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt;all&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E9F284;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;This debugging approach can dramatically reduce unnecessary rebuilds when different tools use inconsistent environments.&lt;&#x2F;p&gt;
&lt;p&gt;Credit: This technique was mentioned in &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;twitu&#x2F;twitu&#x2F;blob&#x2F;54a8915eac80562a15824988bac629583e6befd1&#x2F;fixing-frequent-full-rust-builds-with-cargo-fingerprints.md&quot;&gt;this write-up&lt;&#x2F;a&gt; by &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;twitu&quot;&gt;Ishan Bhanuka&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;cache-dependencies-with-sccache&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#cache-dependencies-with-sccache&quot; aria-label=&quot;Anchor link for: cache-dependencies-with-sccache&quot;&gt;Cache Dependencies With sccache&lt;&#x2F;a&gt;&lt;&#x2F;h3&gt;
&lt;p&gt;Another neat project is &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;mozilla&#x2F;sccache&quot;&gt;sccache&lt;&#x2F;a&gt; by
Mozilla, which caches compiled crates to avoid repeated compilation.&lt;&#x2F;p&gt;
&lt;p&gt;I had this running on my laptop for a while, but the benefit was rather
negligible, to be honest. It works best if you work on a lot of independent
projects that share dependencies (in the same version). A common use-case is
shared build servers.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;cranelift-the-alternative-rust-compiler&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#cranelift-the-alternative-rust-compiler&quot; aria-label=&quot;Anchor link for: cranelift-the-alternative-rust-compiler&quot;&gt;Cranelift: The Alternative Rust Compiler&lt;&#x2F;a&gt;&lt;&#x2F;h3&gt;
&lt;p&gt;Did you know that the Rust project is using an alternative
compiler that runs in parallel with &lt;code&gt;rustc&lt;&#x2F;code&gt; for every CI build?&lt;&#x2F;p&gt;
&lt;p&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;rust-lang&#x2F;rustc_codegen_cranelift&#x2F;&quot;&gt;rustc_codegen_cranelift&lt;&#x2F;a&gt;,
also called &lt;code&gt;CG_CLIF&lt;&#x2F;code&gt;, is an experimental backend for the Rust compiler that
is based on the &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;cranelift.dev&#x2F;&quot;&gt;Cranelift&lt;&#x2F;a&gt; compiler framework.&lt;&#x2F;p&gt;
&lt;p&gt;Here is a comparison between &lt;code&gt;rustc&lt;&#x2F;code&gt; and Cranelift for some popular crates (blue
means better):&lt;&#x2F;p&gt;
&lt;p&gt;&lt;img src=&quot;https:&#x2F;&#x2F;corrode.dev&#x2F;blog&#x2F;tips-for-faster-rust-compile-times&#x2F;cranelift.png&quot; alt=&quot;LLVM compile time comparison between rustc and cranelift in favor of cranelift&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;p&gt;The compiler creates fully working executable binaries. They won’t be optimized
as much, but they are great for local development.&lt;&#x2F;p&gt;
&lt;p&gt;A more detailed write-up is on &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;jason-williams.co.uk&#x2F;a-possible-new-backend-for-rust&quot;&gt;Jason Williams’
page&lt;&#x2F;a&gt;, and the
project code is &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;bjorn3&#x2F;rustc_codegen_cranelift&quot;&gt;on Github&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;switch-to-a-faster-linker&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#switch-to-a-faster-linker&quot; aria-label=&quot;Anchor link for: switch-to-a-faster-linker&quot;&gt;Switch To A Faster Linker&lt;&#x2F;a&gt;&lt;&#x2F;h3&gt;
&lt;div class=&quot;info&quot;&gt;
  
  &lt;div class=&quot;info-header&quot;&gt;
    
      &lt;span class=&quot;icon icon-info&quot;&gt;&lt;&#x2F;span&gt;
    
    &lt;h4&gt;&lt;p&gt;What is a linker?&lt;&#x2F;p&gt;
&lt;&#x2F;h4&gt;
  &lt;&#x2F;div&gt;
  
  &lt;p&gt;A &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Linker_(computing)&quot;&gt;linker&lt;&#x2F;a&gt; is a tool that
combines multiple object files into a single executable.&lt;br &#x2F;&gt;
It’s the last step in the compilation process.&lt;&#x2F;p&gt;

&lt;&#x2F;div&gt;
&lt;p&gt;You can check if your linker is a bottleneck by running:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;plain&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;cargo clean&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;cargo +nightly rustc --bin &amp;lt;your_binary_name&amp;gt; -- -Z time-passes&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;It will output the timings of each step, including link time:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;plain&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;...&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;time:   0.000   llvm_dump_timing_file&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;time:   0.001   serialize_work_products&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;time:   0.002   incr_comp_finalize_session_directory&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;time:   0.004   link_binary_check_files_are_writeable&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;time:   0.614   run_linker&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;time:   0.000   link_binary_remove_temps&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;time:   0.620   link_binary&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;time:   0.622   link_crate&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;time:   0.757   link&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;time:   3.836   total&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    Finished dev [unoptimized + debuginfo] target(s) in 42.75s&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;If the &lt;code&gt;link&lt;&#x2F;code&gt; step is slow, you can try to switch to a faster alternative:&lt;&#x2F;p&gt;
&lt;table&gt;&lt;thead&gt;&lt;tr&gt;&lt;th style=&quot;text-align: left&quot;&gt;Linker&lt;&#x2F;th&gt;&lt;th style=&quot;text-align: left&quot;&gt;Platform&lt;&#x2F;th&gt;&lt;th style=&quot;text-align: left&quot;&gt;Production Ready&lt;&#x2F;th&gt;&lt;th style=&quot;text-align: left&quot;&gt;Description&lt;&#x2F;th&gt;&lt;&#x2F;tr&gt;&lt;&#x2F;thead&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: left&quot;&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;lld.llvm.org&#x2F;&quot;&gt;&lt;code&gt;lld&lt;&#x2F;code&gt;&lt;&#x2F;a&gt;&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: left&quot;&gt;Linux&#x2F;macOS&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: left&quot;&gt;Yes&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: left&quot;&gt;Drop-in replacement for system linkers&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: left&quot;&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;rui314&#x2F;mold&quot;&gt;&lt;code&gt;mold&lt;&#x2F;code&gt;&lt;&#x2F;a&gt;&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: left&quot;&gt;Linux&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: left&quot;&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=29568454&quot;&gt;Yes&lt;&#x2F;a&gt;&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: left&quot;&gt;Optimized for Linux&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: left&quot;&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;michaeleisel&#x2F;zld&quot;&gt;&lt;code&gt;zld&lt;&#x2F;code&gt;&lt;&#x2F;a&gt;&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: left&quot;&gt;macOS&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: left&quot;&gt;No (deprecated)&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: left&quot;&gt;Drop-in replacement for Apple’s &lt;code&gt;ld&lt;&#x2F;code&gt; linker&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;&#x2F;tbody&gt;&lt;&#x2F;table&gt;
&lt;h3 id=&quot;macos-only-faster-incremental-debug-builds&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#macos-only-faster-incremental-debug-builds&quot; aria-label=&quot;Anchor link for: macos-only-faster-incremental-debug-builds&quot;&gt;macOS Only: Faster Incremental Debug Builds&lt;&#x2F;a&gt;&lt;&#x2F;h3&gt;
&lt;p&gt;Rust 1.51 added a flag for faster incremental debug builds on
macOS. It can make debug builds multiple seconds faster (depending on your use-case).
Some engineers &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;jakedeichert.com&#x2F;blog&#x2F;reducing-rust-incremental-compilation-times-on-macos-by-70-percent&#x2F;&quot;&gt;report&lt;&#x2F;a&gt; that this flag alone reduces compilation times on macOS by &lt;strong&gt;70%&lt;&#x2F;strong&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;Add this to your &lt;code&gt;Cargo.toml&lt;&#x2F;code&gt;:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;toml&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;[&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;&quot;&gt;profile&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;&quot;&gt;dev&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #8BE9FD;&quot;&gt;split-debuginfo&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E9F284;&quot;&gt; &amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt;unpacked&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E9F284;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;The flag might become the standard for macOS soon. It is already the &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;rust-lang&#x2F;cargo&#x2F;pull&#x2F;9298&quot;&gt;default
on nightly&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;macos-only-exclude-rust-compilations-from-gatekeeper&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#macos-only-exclude-rust-compilations-from-gatekeeper&quot; aria-label=&quot;Anchor link for: macos-only-exclude-rust-compilations-from-gatekeeper&quot;&gt;macOS Only: Exclude Rust Compilations From Gatekeeper&lt;&#x2F;a&gt;&lt;&#x2F;h3&gt;
&lt;p&gt;&lt;strong&gt;Gatekeeper&lt;&#x2F;strong&gt; is a system on macOS, which runs security checks on binaries.
This can cause Rust builds to be slower by a few seconds for each iteration.
The solution is to add your terminal to the Developer Tools, which will cause processes run by it to be excluded from Gatekeeper.&lt;&#x2F;p&gt;
&lt;ol&gt;
&lt;li&gt;Run &lt;code&gt;sudo spctl developer-mode enable-terminal&lt;&#x2F;code&gt; in your terminal.&lt;&#x2F;li&gt;
&lt;li&gt;Go to System Preferences, and then to Security &amp;amp; Privacy.&lt;&#x2F;li&gt;
&lt;li&gt;Under the Privacy tab, go to &lt;code&gt;Developer Tools&lt;&#x2F;code&gt;.&lt;&#x2F;li&gt;
&lt;li&gt;Make sure your terminal is listed and enabled. If you’re using any third-party terminals like iTerm or Ghostty, add them to the list as well.&lt;&#x2F;li&gt;
&lt;li&gt;Restart your terminal.&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;p&gt;&lt;img src=&quot;https:&#x2F;&#x2F;corrode.dev&#x2F;blog&#x2F;tips-for-faster-rust-compile-times&#x2F;developer-tools.png&quot; alt=&quot;Excluding the terminal from Gatekeeper inspection in macOS Developer Tools&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;p&gt;Thanks to the &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;nexte.st&#x2F;docs&#x2F;installation&#x2F;macos&#x2F;&quot;&gt;nextest&lt;&#x2F;a&gt; and &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;zed.dev&#x2F;docs&#x2F;development&#x2F;macos#tips--tricks&quot;&gt;Zed&lt;&#x2F;a&gt; developers for the tip.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;windows-only-set-up-dev-drive-for-rust&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#windows-only-set-up-dev-drive-for-rust&quot; aria-label=&quot;Anchor link for: windows-only-set-up-dev-drive-for-rust&quot;&gt;Windows Only: Set Up Dev Drive For Rust&lt;&#x2F;a&gt;&lt;&#x2F;h3&gt;
&lt;p&gt;Windows 11 includes &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;learn.microsoft.com&#x2F;en-us&#x2F;windows&#x2F;dev-drive&#x2F;&quot;&gt;Dev Drive&lt;&#x2F;a&gt;, a file system optimized for development.
According to Microsoft, &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;devblogs.microsoft.com&#x2F;visualstudio&#x2F;devdrive&#x2F;&quot;&gt;you can expect a speed boost of around 20-30%&lt;&#x2F;a&gt; by using Dev Drive:&lt;&#x2F;p&gt;
&lt;p&gt;&lt;img src=&quot;https:&#x2F;&#x2F;corrode.dev&#x2F;blog&#x2F;tips-for-faster-rust-compile-times&#x2F;DevDrivePerfChart.png&quot; alt=&quot;Dev Drive Performance Chart&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;p&gt;To improve Rust compilation speed, move these to a Dev Drive:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;Rust toolchain folder (&lt;code&gt;CARGO_HOME&lt;&#x2F;code&gt;)&lt;&#x2F;li&gt;
&lt;li&gt;Your project code&lt;&#x2F;li&gt;
&lt;li&gt;Cargo’s &lt;code&gt;target&lt;&#x2F;code&gt; directory&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;You can go one step further and &lt;strong&gt;add the above folders to your antivirus exclusions as well&lt;&#x2F;strong&gt;
for another potential speedup.
You can find exclusion settings in Windows Security under Virus &amp;amp; threat protection settings.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;img src=&quot;https:&#x2F;&#x2F;corrode.dev&#x2F;blog&#x2F;tips-for-faster-rust-compile-times&#x2F;windows-antivirus-exclusions.png&quot; alt=&quot;Antivirus Exclusion Settings on Windows&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;p&gt;Thanks to the &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;nexte.st&#x2F;docs&#x2F;installation&#x2F;windows&#x2F;&quot;&gt;nextest team&lt;&#x2F;a&gt; for the tip.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;tweak-codegen-options-and-compiler-flags&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#tweak-codegen-options-and-compiler-flags&quot; aria-label=&quot;Anchor link for: tweak-codegen-options-and-compiler-flags&quot;&gt;Tweak Codegen Options And Compiler Flags&lt;&#x2F;a&gt;&lt;&#x2F;h3&gt;
&lt;p&gt;Rust comes with a huge set of &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;doc.rust-lang.org&#x2F;rustc&#x2F;codegen-options&quot;&gt;settings for code
generation&lt;&#x2F;a&gt;. It can help to
look through the list and tweak the parameters for your project.&lt;&#x2F;p&gt;
&lt;p&gt;There are &lt;strong&gt;many&lt;&#x2F;strong&gt; gems in the &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;doc.rust-lang.org&#x2F;rustc&#x2F;codegen-options&quot;&gt;full list of codegen
options&lt;&#x2F;a&gt;. For inspiration,
here’s &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;bevyengine&#x2F;bevy&#x2F;blob&#x2F;3a2a68852c0a1298c0678a47adc59adebe259a6f&#x2F;.cargo&#x2F;config_fast_builds&quot;&gt;bevy’s config for faster
compilation&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;avoid-procedural-macro-crates&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#avoid-procedural-macro-crates&quot; aria-label=&quot;Anchor link for: avoid-procedural-macro-crates&quot;&gt;Avoid Procedural Macro Crates&lt;&#x2F;a&gt;&lt;&#x2F;h3&gt;
&lt;p&gt;If you heavily use procedural macros in your project (e.g., if you use serde),
it might be worth it to play around with opt-levels in your &lt;code&gt;Cargo.toml&lt;&#x2F;code&gt;.&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;toml&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;[&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;&quot;&gt;profile&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;&quot;&gt;dev&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;&quot;&gt;build-override&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #8BE9FD;&quot;&gt;opt-level&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt; 3&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;As reader &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;jfmontanaro&quot;&gt;jfmontanaro&lt;&#x2F;a&gt; mentioned on
&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;mre&#x2F;endler.dev&#x2F;issues&#x2F;53&quot;&gt;Github&lt;&#x2F;a&gt;:&lt;&#x2F;p&gt;
&lt;blockquote&gt;
&lt;p&gt;I think the reason it helps with build times is because it only applies to
build scripts and proc-macros. Build scripts and proc-macros are unique because
during a normal build, they are not only compiled but also executed (and in the
case of proc-macros, they can be executed repeatedly). When your project uses a
lot of proc-macros, optimizing the macros themselves can in theory save a lot of
time.&lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
&lt;p&gt;Another approach is to try and sidestep the macro impact on compile times with
&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;dtolnay&#x2F;watt&quot;&gt;watt&lt;&#x2F;a&gt;, a tool that offloads macro compilation
to Webassembly.&lt;&#x2F;p&gt;
&lt;p&gt;From the docs:&lt;&#x2F;p&gt;
&lt;blockquote&gt;
&lt;p&gt;By compiling macros ahead-of-time to Wasm, we save all downstream users of the
macro from having to compile the macro logic or its dependencies themselves.&lt;&#x2F;p&gt;
&lt;p&gt;Instead, what they compile is a small self-contained Wasm runtime (~3 seconds,
shared by all macros) and a tiny proc macro shim for each macro crate to hand
off Wasm bytecode into the Watt runtime (~0.3 seconds per proc-macro crate you
depend on). This is much less than the 20+ seconds it can take to compile
complex procedural macros and their dependencies.&lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
&lt;p&gt;Note that this crate is still experimental.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;find-expensive-proc-macros&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#find-expensive-proc-macros&quot; aria-label=&quot;Anchor link for: find-expensive-proc-macros&quot;&gt;Find Expensive Proc Macros&lt;&#x2F;a&gt;&lt;&#x2F;h3&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;shellscript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt;RUSTFLAGS&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;=&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E9F284;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt;-Zmacro-stats&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E9F284;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; cargo&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt; +nightly build&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Some macros have a big compile-time cost; but exactly how big?
It can help to quantify the costs to see if a macro is worth optimizing (or removing).
One way is to understand exactly how much code they generate.&lt;&#x2F;p&gt;
&lt;p&gt;One way is to use &lt;code&gt;cargo expand&lt;&#x2F;code&gt; to see the generated code, but that doesn’t scale to large codebases and the output is hard to quantify.&lt;&#x2F;p&gt;
&lt;p&gt;The alternative is to use the &lt;code&gt;-Zmacro-stats&lt;&#x2F;code&gt; flag to identify proc macros that generate a lot of code.
This tool has already led to successful optimizations in projects like &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;bevyengine&#x2F;bevy&#x2F;issues&#x2F;19873&quot;&gt;Bevy&lt;&#x2F;a&gt; and &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;nnethercote.github.io&#x2F;2025&#x2F;08&#x2F;16&#x2F;speed-wins-when-fuzzing-rust-code-with-derive-arbitrary.html&quot;&gt;Arbitrary&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;For more information, read &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;nnethercote.github.io&#x2F;2025&#x2F;06&#x2F;26&#x2F;how-much-code-does-that-proc-macro-generate.html&quot;&gt;Nicholas Nethercote’s blog post&lt;&#x2F;a&gt; on the topic.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;conditional-compilation-for-procedural-macros&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#conditional-compilation-for-procedural-macros&quot; aria-label=&quot;Anchor link for: conditional-compilation-for-procedural-macros&quot;&gt;Conditional Compilation for Procedural Macros&lt;&#x2F;a&gt;&lt;&#x2F;h3&gt;
&lt;p&gt;Procedural macros need to parse Rust code, and that is a relatively complex
task. Crates that depend on procedural macros will have to wait for the
procedural macro to compile before they can compile. For example, &lt;code&gt;serde&lt;&#x2F;code&gt; can be
a bottleneck in compilation times and can limit CPU utilization.&lt;&#x2F;p&gt;
&lt;p&gt;To improve Rust compile times, consider a strategic approach to handling
serialization with Serde, especially in projects with a shared crate structure.
Instead of placing Serde directly in a shared crate used across different parts
of the project, you can make Serde an optional dependency through Cargo
features.&lt;&#x2F;p&gt;
&lt;p&gt;Use the &lt;code&gt;cfg&lt;&#x2F;code&gt; or &lt;code&gt;cfg_attr&lt;&#x2F;code&gt; attributes to make Serde usage and &lt;code&gt;derive&lt;&#x2F;code&gt; in the
shared crate feature-gated. This way, it becomes an optional dependency that is
only enabled in leaf crates which actually perform
serialization&#x2F;deserialization.&lt;&#x2F;p&gt;
&lt;p&gt;This approach prevents the entire project from waiting on the compilation of
Serde dependencies, which would be the case if Serde were a non-optional, direct
dependency of the shared crate.&lt;&#x2F;p&gt;
&lt;p&gt;Let’s illustrate this with a simplified example. Imagine you have a Rust project
with a shared library crate and a few other crates that depend on it. You don’t
want to compile Serde unnecessarily when building parts of the project that
don’t need it.&lt;&#x2F;p&gt;
&lt;p&gt;Here’s how you can structure your project to use optional features in Cargo:&lt;&#x2F;p&gt;
&lt;p&gt;In your &lt;code&gt;Cargo.toml&lt;&#x2F;code&gt; for the shared crate, declare serde as an optional dependency:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;toml&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;[&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;&quot;&gt;package&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #8BE9FD;&quot;&gt;name&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E9F284;&quot;&gt; &amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt;shared&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E9F284;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #8BE9FD;&quot;&gt;version&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E9F284;&quot;&gt; &amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt;0.1.0&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E9F284;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #8BE9FD;&quot;&gt;edition&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E9F284;&quot;&gt; &amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt;2021&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E9F284;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;[&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;&quot;&gt;dependencies&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #8BE9FD;&quot;&gt;serde&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;&quot;&gt; version&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E9F284;&quot;&gt; &amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt;1.0&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E9F284;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;&quot;&gt; optional&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt; true&lt;&#x2F;span&gt;&lt;span&gt; }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;In this crate, use conditional compilation to include serde only when the feature is enabled:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;#[cfg(feature &lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;=&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt; &amp;quot;serde&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;)]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;use&lt;&#x2F;span&gt;&lt;span&gt; serde&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span&gt;{&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;Serialize&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Deserialize&lt;&#x2F;span&gt;&lt;span&gt;};&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;#[cfg_attr(feature &lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;=&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt; &amp;quot;serde&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;, derive(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;Serialize&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Deserialize&lt;&#x2F;span&gt;&lt;span&gt;))]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;pub struct&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; MySharedStruct&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;    &#x2F;&#x2F; Your struct fields&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;In the other crates, enable the &lt;code&gt;serde&lt;&#x2F;code&gt; feature for the shared crate if needed:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;toml&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;[&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;&quot;&gt;package&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #8BE9FD;&quot;&gt;name&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E9F284;&quot;&gt; &amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt;other&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E9F284;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #8BE9FD;&quot;&gt;version&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E9F284;&quot;&gt; &amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt;0.1.0&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E9F284;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #8BE9FD;&quot;&gt;edition&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E9F284;&quot;&gt; &amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt;2021&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E9F284;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;[&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;&quot;&gt;dependencies&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #8BE9FD;&quot;&gt;shared&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;&quot;&gt; path&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E9F284;&quot;&gt; &amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt;..&#x2F;shared&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E9F284;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;&quot;&gt; features&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; [&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E9F284;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt;serde&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E9F284;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;] }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;You can now use &lt;code&gt;MySharedStruct&lt;&#x2F;code&gt; with Serde’s functionality enabled
without bloating the compilation of crates that don’t need it.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;generics-use-an-inner-non-generic-function&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#generics-use-an-inner-non-generic-function&quot; aria-label=&quot;Anchor link for: generics-use-an-inner-non-generic-function&quot;&gt;Generics: Use an Inner Non-Generic Function&lt;&#x2F;a&gt;&lt;&#x2F;h3&gt;
&lt;p&gt;If you have a generic function, it will be compiled for every type you use it
with. This can be a problem if you have a lot of different types.&lt;&#x2F;p&gt;
&lt;p&gt;A common solution is to use an inner non-generic function. This way, the
compiler will only compile the inner function once.&lt;&#x2F;p&gt;
&lt;p&gt;This is a trick often used in the standard library. For example, here is the
implementation of &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;rust-lang&#x2F;rust&#x2F;blob&#x2F;ae612bedcbfc7098d1711eb35bc7ca994eb17a4c&#x2F;library&#x2F;std&#x2F;src&#x2F;fs.rs#L295-L304&quot;&gt;&lt;code&gt;read_to_string&lt;&#x2F;code&gt;&lt;&#x2F;a&gt;:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;pub fn&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; read_to_string&lt;&#x2F;span&gt;&lt;span&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;P&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; AsRef&lt;&#x2F;span&gt;&lt;span&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;Path&lt;&#x2F;span&gt;&lt;span&gt;&amp;gt;&amp;gt;(path&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; P&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; -&amp;gt;&lt;&#x2F;span&gt;&lt;span&gt; io&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;Result&lt;&#x2F;span&gt;&lt;span&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;String&lt;&#x2F;span&gt;&lt;span&gt;&amp;gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    fn&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; inner&lt;&#x2F;span&gt;&lt;span&gt;(path&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;: &amp;amp;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;Path&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; -&amp;gt;&lt;&#x2F;span&gt;&lt;span&gt; io&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;Result&lt;&#x2F;span&gt;&lt;span&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;String&lt;&#x2F;span&gt;&lt;span&gt;&amp;gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;        let mut&lt;&#x2F;span&gt;&lt;span&gt; file&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; File&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;open&lt;&#x2F;span&gt;&lt;span&gt;(path)&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;?&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;        let&lt;&#x2F;span&gt;&lt;span&gt; size&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; file&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;metadata&lt;&#x2F;span&gt;&lt;span&gt;()&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;map&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;|&lt;&#x2F;span&gt;&lt;span&gt;m&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;|&lt;&#x2F;span&gt;&lt;span&gt; m&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;len&lt;&#x2F;span&gt;&lt;span&gt;()&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; as&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; usize&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;ok&lt;&#x2F;span&gt;&lt;span&gt;();&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;        let mut&lt;&#x2F;span&gt;&lt;span&gt; string&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; String&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;with_capacity&lt;&#x2F;span&gt;&lt;span&gt;(size&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;unwrap_or&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt;0&lt;&#x2F;span&gt;&lt;span&gt;));&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        io&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;default_read_to_string&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;&amp;amp;mut&lt;&#x2F;span&gt;&lt;span&gt; file,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; &amp;amp;mut&lt;&#x2F;span&gt;&lt;span&gt; string, size)&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;?&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;        Ok&lt;&#x2F;span&gt;&lt;span&gt;(string)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;    inner&lt;&#x2F;span&gt;&lt;span&gt;(path&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;as_ref&lt;&#x2F;span&gt;&lt;span&gt;())&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;You can do the same in your code: the outer function is generic, while
it calls the inner non-generic function, which does the actual work.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;improve-workspace-build-times-with-cargo-hakari&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#improve-workspace-build-times-with-cargo-hakari&quot; aria-label=&quot;Anchor link for: improve-workspace-build-times-with-cargo-hakari&quot;&gt;Improve Workspace Build Times with cargo-hakari&lt;&#x2F;a&gt;&lt;&#x2F;h3&gt;
&lt;p&gt;Do you have a large Rust workspace with dependencies that:&lt;&#x2F;p&gt;
&lt;ol&gt;
&lt;li&gt;Are used in multiple crates&lt;&#x2F;li&gt;
&lt;li&gt;Have different feature sets across those crates?&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;p&gt;This situation can lead to long build times, as cargo will build each dependency multiple
times with different features depending on which crate is being built. This is
where &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;docs.rs&#x2F;cargo-hakari&#x2F;latest&#x2F;cargo_hakari&#x2F;about&#x2F;index.html&quot;&gt;&lt;code&gt;cargo-hakari&lt;&#x2F;code&gt;&lt;&#x2F;a&gt; comes in.
It’s a tool designed to automatically manage “workspace-hack” crates.&lt;&#x2F;p&gt;
&lt;p&gt;In some scenarios, this can reduce consecutive build times by up to 50% or more.
To learn more, check out the usage instructions and benchmarks in the &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;docs.rs&#x2F;cargo-hakari&#x2F;latest&#x2F;cargo_hakari&#x2F;about&#x2F;index.html&quot;&gt;official cargo-hakari documentation&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;speeding-up-incremental-rust-compilation-with-dylibs&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#speeding-up-incremental-rust-compilation-with-dylibs&quot; aria-label=&quot;Anchor link for: speeding-up-incremental-rust-compilation-with-dylibs&quot;&gt;Speeding up incremental Rust compilation with dylibs&lt;&#x2F;a&gt;&lt;&#x2F;h3&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;shellscript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;# Install the tool&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;cargo&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt; install cargo-add-dynamic&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;# Add a dynamic library to your project&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;cargo&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt; add-dynamic polars&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt; --features&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt; csv-file,lazy,list,describe,rows,fmt,strings,temporal&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;This will create a wrapper-crate around &lt;code&gt;polars&lt;&#x2F;code&gt; that is compiled as a dynamic
library (&lt;code&gt;.so&lt;&#x2F;code&gt; on Linux, &lt;code&gt;.dylib&lt;&#x2F;code&gt; on macOS, &lt;code&gt;.dll&lt;&#x2F;code&gt; on Windows).&lt;&#x2F;p&gt;
&lt;p&gt;Essentially, it patches the dependency with&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;toml&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;[&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;&quot;&gt;lib&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #8BE9FD;&quot;&gt;crate-type&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; [&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E9F284;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt;dylib&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E9F284;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;With this trick, you can save yourself the linking time of a dependency
when you only change your own code. The dependency itself will only be
recompiled when you change the features or the version.
Of course, this works for any crate, not just &lt;code&gt;polars&lt;&#x2F;code&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;Read more about this on &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;robert.kra.hn&#x2F;posts&#x2F;2022-09-09-speeding-up-incremental-rust-compilation-with-dylibs&#x2F;&quot;&gt;this blog post by Robert Krahn&lt;&#x2F;a&gt;
and the &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;rksm&#x2F;cargo-add-dynamic&quot;&gt;tool’s homepage&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;switch-to-the-new-parallel-compiler-frontend&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#switch-to-the-new-parallel-compiler-frontend&quot; aria-label=&quot;Anchor link for: switch-to-the-new-parallel-compiler-frontend&quot;&gt;Switch To The New Parallel Compiler Frontend&lt;&#x2F;a&gt;&lt;&#x2F;h3&gt;
&lt;p&gt;&lt;strong&gt;In nightly&lt;&#x2F;strong&gt;, you can now enable the new parallel compiler frontend.
To try it out, run the nightly compiler with the &lt;code&gt;-Z threads=8&lt;&#x2F;code&gt; option:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;shellscript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt;RUSTFLAGS&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;=&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E9F284;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt;-Z threads=8&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E9F284;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; cargo&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt; +nightly build&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;If you find that it works well for you, you can make it the default by adding
&lt;code&gt;-Z threads=8&lt;&#x2F;code&gt; to your &lt;code&gt;~&#x2F;.cargo&#x2F;config.toml&lt;&#x2F;code&gt; file:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;toml&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;[&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;&quot;&gt;build&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #8BE9FD;&quot;&gt;rustflags&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; [&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E9F284;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt;-Z&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E9F284;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E9F284;&quot;&gt; &amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt;threads=8&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E9F284;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Alternatively, you can set an alias for &lt;code&gt;cargo&lt;&#x2F;code&gt;
in your shell’s config file (e.g., &lt;code&gt;~&#x2F;.bashrc&lt;&#x2F;code&gt; or &lt;code&gt;~&#x2F;.zshrc&lt;&#x2F;code&gt;):&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;shellscript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;alias&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt; cargo&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;=&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E9F284;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt;RUSTFLAGS=&amp;#39;-Z threads=8&amp;#39; cargo +nightly&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E9F284;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;When the front-end is executed in a multi-threaded setting using &lt;code&gt;-Z threads=8&lt;&#x2F;code&gt;,
benchmarks on actual code indicate that compilation times may decrease by as
much as &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;blog.rust-lang.org&#x2F;2023&#x2F;11&#x2F;09&#x2F;parallel-rustc.html&quot;&gt;50%&lt;&#x2F;a&gt;.
However, the gains fluctuate depending on the code being compiled. It is
certainly worth a try, though.&lt;&#x2F;p&gt;
&lt;p&gt;Here is a visualization of the parallel compiler frontend in action:&lt;&#x2F;p&gt;
&lt;p&gt;&lt;img src=&quot;https:&#x2F;&#x2F;corrode.dev&#x2F;blog&#x2F;tips-for-faster-rust-compile-times&#x2F;samply-parallel.png&quot; alt=&quot;Result of the parallel compiler&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;p&gt;Find out more on the official announcement &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;blog.rust-lang.org&#x2F;2023&#x2F;11&#x2F;09&#x2F;parallel-rustc.html&quot;&gt;on the Rust
blog&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;use-a-scratch-disk-for-faster-builds&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#use-a-scratch-disk-for-faster-builds&quot; aria-label=&quot;Anchor link for: use-a-scratch-disk-for-faster-builds&quot;&gt;Use A Scratch Disk For Faster Builds&lt;&#x2F;a&gt;&lt;&#x2F;h3&gt;
&lt;p&gt;Your filesystem might be the bottleneck. Consider using an in-memory filesystem
like for your build directory.&lt;&#x2F;p&gt;
&lt;p&gt;Traditional temporary filesystem like &lt;code&gt;tmpfs&lt;&#x2F;code&gt; is limited to your RAM plus swap space and can be problematic for builds creating large intermediate artifacts.&lt;&#x2F;p&gt;
&lt;p&gt;Instead, on Linux, mount an &lt;code&gt;ext4&lt;&#x2F;code&gt; volume with the following options:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;plain&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;-o noauto_da_alloc,data=writeback,lazytime,journal_async_commit,commit=999,nobarrier&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;This will store files in the page cache if you have enough RAM, with writebacks occurring later. Treat this as if it were a temporary filesystem, as data may be lost or corrupted after a crash or power loss.&lt;&#x2F;p&gt;
&lt;p&gt;Credits go to &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.reddit.com&#x2F;r&#x2F;rust&#x2F;comments&#x2F;1ddgatd&#x2F;compile_rust_faster_some_tricks&#x2F;l85gzy8&#x2F;&quot;&gt;&#x2F;u&#x2F;The_8472 on Reddit&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;invest-in-better-hardware&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#invest-in-better-hardware&quot; aria-label=&quot;Anchor link for: invest-in-better-hardware&quot;&gt;Invest In Better Hardware&lt;&#x2F;a&gt;&lt;&#x2F;h3&gt;
&lt;p&gt;If you reached this point, the easiest way to improve compile times even more is
probably to spend money on top-of-the-line hardware.&lt;&#x2F;p&gt;
&lt;p&gt;As for laptops, the &lt;code&gt;M-series&lt;&#x2F;code&gt; of Apple’s new Macbooks perform really well
for Rust compilation.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;twitter.com&#x2F;rikarends&#x2F;status&#x2F;1328598935380910082&quot;&gt;&lt;img src=&quot;https:&#x2F;&#x2F;corrode.dev&#x2F;blog&#x2F;tips-for-faster-rust-compile-times&#x2F;tweet.png&quot; alt=&quot;Rik Arends on Twitter&quot; &#x2F;&gt;&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;p&gt;The &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.reddit.com&#x2F;r&#x2F;rust&#x2F;comments&#x2F;qgi421&#x2F;doing_m1_macbook_pro_m1_max_64gb_compile&#x2F;&quot;&gt;benchmarks&lt;&#x2F;a&gt; for a Macbook Pro with M1 Max are absolutely &lt;em&gt;ridiculous&lt;&#x2F;em&gt; — even in comparison to the already fast M1:&lt;&#x2F;p&gt;
&lt;table&gt;&lt;thead&gt;&lt;tr&gt;&lt;th style=&quot;text-align: left&quot;&gt;Project&lt;&#x2F;th&gt;&lt;th style=&quot;text-align: left&quot;&gt;M1 Max&lt;&#x2F;th&gt;&lt;th style=&quot;text-align: left&quot;&gt;M1 Air&lt;&#x2F;th&gt;&lt;&#x2F;tr&gt;&lt;&#x2F;thead&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: left&quot;&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;denoland&quot;&gt;Deno&lt;&#x2F;a&gt;&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: left&quot;&gt;6m11s&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: left&quot;&gt;11m15s&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: left&quot;&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;meilisearch&#x2F;MeiliSearch&quot;&gt;MeiliSearch&lt;&#x2F;a&gt;&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: left&quot;&gt;1m28s&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: left&quot;&gt;3m36s&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: left&quot;&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;sharkdp&#x2F;bat&quot;&gt;bat&lt;&#x2F;a&gt;&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: left&quot;&gt;43s&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: left&quot;&gt;1m23s&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: left&quot;&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;sharkdp&#x2F;hyperfine&quot;&gt;hyperfine&lt;&#x2F;a&gt;&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: left&quot;&gt;23s&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: left&quot;&gt;42s&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: left&quot;&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;BurntSushi&#x2F;ripgrep&quot;&gt;ripgrep&lt;&#x2F;a&gt;&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: left&quot;&gt;16s&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: left&quot;&gt;37s&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;&#x2F;tbody&gt;&lt;&#x2F;table&gt;
&lt;p&gt;That’s a solid 2x performance improvement.&lt;&#x2F;p&gt;
&lt;p&gt;But if you rather like to stick to Linux, people also had great success with a multicore CPU like an &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.reddit.com&#x2F;r&#x2F;rust&#x2F;comments&#x2F;chqu4c&#x2F;building_a_computer_for_fastest_possible_rust&#x2F;&quot;&gt;AMD Ryzen
Threadripper and 32 GB of RAM&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;On portable devices, compiling can drain your battery and be slow. To avoid
that, I’m using my machine at home, a 6-core AMD FX 6300 with 12GB RAM, as a
build machine. I can use it in combination with &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;code.visualstudio.com&#x2F;docs&#x2F;remote&#x2F;remote-overview&quot;&gt;Visual Studio Code Remote
Development&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;compile-in-the-cloud&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#compile-in-the-cloud&quot; aria-label=&quot;Anchor link for: compile-in-the-cloud&quot;&gt;Compile in the Cloud&lt;&#x2F;a&gt;&lt;&#x2F;h3&gt;
&lt;p&gt;If you don’t have a dedicated machine yourself, you can offload the compilation
process to the cloud instead.
&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;features&#x2F;codespaces&quot;&gt;GitHub Codespaces&lt;&#x2F;a&gt; gives you a
fully configured cloud development environment right inside GitHub. You can
spin up a codespace from any repository by clicking the &lt;strong&gt;Code&lt;&#x2F;strong&gt; button and
selecting &lt;strong&gt;Open with Codespaces&lt;&#x2F;strong&gt;. Machine sizes range from 2 cores all the
way up to 32 cores, and every GitHub account includes a free monthly quota
(currently 60 hours on a 2-core machine).&lt;&#x2F;p&gt;
&lt;p&gt;Codespaces supports &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;docs.github.com&#x2F;en&#x2F;codespaces&#x2F;setting-up-your-project-for-codespaces&#x2F;adding-a-dev-container-configuration&quot;&gt;dev container configuration&lt;&#x2F;a&gt; via a &lt;code&gt;.devcontainer&#x2F;devcontainer.json&lt;&#x2F;code&gt;
file, which lets you pre-install the Rust toolchain and any other dependencies
so the environment is ready the moment it starts. This is particularly useful
when reviewing pull requests — open the PR directly in a codespace and
everything is already set up for you.&lt;&#x2F;p&gt;
&lt;p&gt;If you want more control over the build environment, &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;northflank.com&#x2F;pricing&quot;&gt;Northflank&lt;&#x2F;a&gt;
is another option. It lets you run arbitrary build jobs on dedicated cloud
infrastructure, with plans ranging from shared 0.1 vCPU containers up to 32
dedicated vCPUs. There’s a free sandbox tier, and paid plans are billed
per-second so you only pay for actual build time.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;cache-all-crates-locally&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#cache-all-crates-locally&quot; aria-label=&quot;Anchor link for: cache-all-crates-locally&quot;&gt;Cache All Crates Locally&lt;&#x2F;a&gt;&lt;&#x2F;h3&gt;
&lt;p&gt;If you have a slow internet connection, a big part of the initial build
process is fetching all those shiny crates from crates.io. To mitigate that,
you can download &lt;strong&gt;all&lt;&#x2F;strong&gt; crates in advance to have them cached locally.
&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;the-lean-crate&#x2F;criner&quot;&gt;criner&lt;&#x2F;a&gt; does just that:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;plain&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;git clone https:&#x2F;&#x2F;github.com&#x2F;the-lean-crate&#x2F;criner&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;cd criner&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;cargo run --release -- mine&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;The archive size is surprisingly reasonable, with roughly &lt;strong&gt;50GB of required disk
space&lt;&#x2F;strong&gt; (as of today).&lt;&#x2F;p&gt;
&lt;h2 id=&quot;test-execution&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#test-execution&quot; aria-label=&quot;Anchor link for: test-execution&quot;&gt;Test Execution&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;h3 id=&quot;use-cargo-nextest-instead-of-cargo-test&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#use-cargo-nextest-instead-of-cargo-test&quot; aria-label=&quot;Anchor link for: use-cargo-nextest-instead-of-cargo-test&quot;&gt;Use Cargo Nextest Instead of &lt;code&gt;cargo test&lt;&#x2F;code&gt;&lt;&#x2F;a&gt;&lt;&#x2F;h3&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;shellscript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;cargo&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt; install cargo-nextest&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;cargo&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt; nextest run&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;It’s nice that &lt;code&gt;cargo&lt;&#x2F;code&gt; comes with its own little test runner, but especially if
you have to build multiple test binaries, &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;nexte.st&#x2F;&quot;&gt;&lt;code&gt;cargo nextest&lt;&#x2F;code&gt;&lt;&#x2F;a&gt;
can be up to 60% faster than &lt;code&gt;cargo test&lt;&#x2F;code&gt; thanks to its parallel execution
model.
Here are some quick &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;nexte.st&#x2F;book&#x2F;benchmarks.html&quot;&gt;benchmarks&lt;&#x2F;a&gt;:&lt;&#x2F;p&gt;
&lt;table&gt;&lt;thead&gt;&lt;tr&gt;&lt;th&gt;Project&lt;&#x2F;th&gt;&lt;th&gt;Revision&lt;&#x2F;th&gt;&lt;th style=&quot;text-align: right&quot;&gt;Test count&lt;&#x2F;th&gt;&lt;th style=&quot;text-align: right&quot;&gt;cargo test (s)&lt;&#x2F;th&gt;&lt;th style=&quot;text-align: right&quot;&gt;nextest (s)&lt;&#x2F;th&gt;&lt;th style=&quot;text-align: right&quot;&gt;Improvement&lt;&#x2F;th&gt;&lt;&#x2F;tr&gt;&lt;&#x2F;thead&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;crucible&lt;&#x2F;td&gt;&lt;td&gt;&lt;code&gt;cb228c2b&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: right&quot;&gt;483&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: right&quot;&gt;5.14&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: right&quot;&gt;1.52&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: right&quot;&gt;3.38×&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;guppy&lt;&#x2F;td&gt;&lt;td&gt;&lt;code&gt;2cc51b41&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: right&quot;&gt;271&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: right&quot;&gt;6.42&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: right&quot;&gt;2.80&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: right&quot;&gt;2.29×&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;mdBook&lt;&#x2F;td&gt;&lt;td&gt;&lt;code&gt;0079184c&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: right&quot;&gt;199&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: right&quot;&gt;3.85&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: right&quot;&gt;1.66&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: right&quot;&gt;2.31×&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;meilisearch&lt;&#x2F;td&gt;&lt;td&gt;&lt;code&gt;bfb1f927&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: right&quot;&gt;721&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: right&quot;&gt;57.04&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: right&quot;&gt;28.99&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: right&quot;&gt;1.96×&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;omicron&lt;&#x2F;td&gt;&lt;td&gt;&lt;code&gt;e7949cd1&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: right&quot;&gt;619&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: right&quot;&gt;444.08&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: right&quot;&gt;202.50&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: right&quot;&gt;2.19×&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;penumbra&lt;&#x2F;td&gt;&lt;td&gt;&lt;code&gt;4ecd94cc&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: right&quot;&gt;144&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: right&quot;&gt;125.38&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: right&quot;&gt;90.96&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: right&quot;&gt;1.37×&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;reqwest&lt;&#x2F;td&gt;&lt;td&gt;&lt;code&gt;3459b894&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: right&quot;&gt;113&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: right&quot;&gt;5.57&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: right&quot;&gt;2.26&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: right&quot;&gt;2.48×&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;ring&lt;&#x2F;td&gt;&lt;td&gt;&lt;code&gt;450ada28&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: right&quot;&gt;179&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: right&quot;&gt;13.12&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: right&quot;&gt;9.40&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: right&quot;&gt;1.39×&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;tokio&lt;&#x2F;td&gt;&lt;td&gt;&lt;code&gt;1f50c571&lt;&#x2F;code&gt;&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: right&quot;&gt;1138&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: right&quot;&gt;24.27&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: right&quot;&gt;11.60&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: right&quot;&gt;2.09×&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;&#x2F;tbody&gt;&lt;&#x2F;table&gt;
&lt;h3 id=&quot;combine-all-integration-tests-into-a-single-binary&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#combine-all-integration-tests-into-a-single-binary&quot; aria-label=&quot;Anchor link for: combine-all-integration-tests-into-a-single-binary&quot;&gt;Combine All Integration Tests Into A Single Binary&lt;&#x2F;a&gt;&lt;&#x2F;h3&gt;
&lt;p&gt;Have any &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;doc.rust-lang.org&#x2F;rust-by-example&#x2F;testing&#x2F;integration_testing.html&quot;&gt;integration tests&lt;&#x2F;a&gt;? (These are the ones in your &lt;code&gt;tests&lt;&#x2F;code&gt;
folder.)
Did you know that the Rust compiler will create a binary for every single one of them?
And every binary will have to be linked individually.
This can take most of your build time because linking is slooow. 🐢
The reason is that many system linkers (like &lt;code&gt;ld&lt;&#x2F;code&gt;) are &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;stackoverflow.com&#x2F;questions&#x2F;5142753&#x2F;can-gcc-use-multiple-cores-when-linking&quot;&gt;single
threaded&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;To make the linker’s job a little easier, you can put all your tests in one
crate. (Basically create a &lt;code&gt;main.rs&lt;&#x2F;code&gt; in your test folder and add your
test files as &lt;code&gt;mod&lt;&#x2F;code&gt; in there.)&lt;&#x2F;p&gt;
&lt;p&gt;Then the linker will go ahead and build a single binary only. Sounds nice, but
careful: it’s still a trade-off as you’ll need to expose your internal types and
functions (i.e. make them &lt;code&gt;pub&lt;&#x2F;code&gt;).&lt;&#x2F;p&gt;
&lt;p&gt;If you have a lot of integration tests, this can &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;azriel.im&#x2F;will&#x2F;2019&#x2F;10&#x2F;08&#x2F;dev-time-optimization-part-1-1.9x-speedup-65-less-disk-usage&#x2F;&quot;&gt;result in a 50% speedup&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;em&gt;This tip was brought to you by &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;twitter.com&#x2F;algo_luca&quot;&gt;Luca Palmieri&lt;&#x2F;a&gt;,
&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;twitter.com&#x2F;lucio_d_franco&quot;&gt;Lucio Franco&lt;&#x2F;a&gt;, and &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;twitter.com&#x2F;im_azriel&quot;&gt;Azriel
Hoh&lt;&#x2F;a&gt;. Thanks!&lt;&#x2F;em&gt;&lt;&#x2F;p&gt;
&lt;h3 id=&quot;put-slow-tests-behind-an-environment-variable&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#put-slow-tests-behind-an-environment-variable&quot; aria-label=&quot;Anchor link for: put-slow-tests-behind-an-environment-variable&quot;&gt;Put slow tests behind an environment variable&lt;&#x2F;a&gt;&lt;&#x2F;h3&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;#[test]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;fn&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; completion_works_with_real_standard_library&lt;&#x2F;span&gt;&lt;span&gt;() {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;  if&lt;&#x2F;span&gt;&lt;span&gt; std&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span&gt;env&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;var&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt;&amp;quot;RUN_SLOW_TESTS&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;is_err&lt;&#x2F;span&gt;&lt;span&gt;() {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    return&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;  ...&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;If you have slow tests, you can put them behind an environment variable to
disable them by default. This way, you can skip them locally and only run them
on CI.&lt;&#x2F;p&gt;
&lt;p&gt;(A nice trick I learned from &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;matklad.github.io&#x2F;2021&#x2F;05&#x2F;31&#x2F;how-to-test.html&quot;&gt;matklad’s (Alex Kladov) post&lt;&#x2F;a&gt;.)&lt;&#x2F;p&gt;
&lt;h2 id=&quot;ci-builds&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#ci-builds&quot; aria-label=&quot;Anchor link for: ci-builds&quot;&gt;CI Builds&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;div class=&quot;info&quot;&gt;
  
  &lt;div class=&quot;info-header&quot;&gt;
    
      &lt;span class=&quot;icon icon-info&quot;&gt;&lt;&#x2F;span&gt;
    
    &lt;h4&gt;&lt;p&gt;Tips for CI Builds&lt;&#x2F;p&gt;
&lt;&#x2F;h4&gt;
  &lt;&#x2F;div&gt;
  
  &lt;p&gt;Many of the techniques in this article also apply to CI builds. For CI-specific optimizations and best practices, check out my dedicated guide on &lt;a href=&quot;&#x2F;blog&#x2F;tips-for-faster-ci-builds&#x2F;&quot;&gt;Tips for Faster CI Builds&lt;&#x2F;a&gt;, which covers caching strategies, workflow optimization, and GitHub Actions-specific improvements.&lt;&#x2F;p&gt;

&lt;&#x2F;div&gt;
&lt;h3 id=&quot;use-a-cache-for-your-dependencies&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#use-a-cache-for-your-dependencies&quot; aria-label=&quot;Anchor link for: use-a-cache-for-your-dependencies&quot;&gt;Use A Cache For Your Dependencies&lt;&#x2F;a&gt;&lt;&#x2F;h3&gt;
&lt;p&gt;For GitHub actions in particular you can also use &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;Swatinem&#x2F;rust-cache&quot;&gt;Swatinem&#x2F;rust-cache&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;It is as simple as adding a single step to your workflow:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;yaml&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #8BE9FD;&quot;&gt;jobs&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #8BE9FD;&quot;&gt;  test&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #8BE9FD;&quot;&gt;    runs-on&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt; ubuntu-latest&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #8BE9FD;&quot;&gt;    steps&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;      -&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;&quot;&gt; uses&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt; actions&#x2F;checkout@v4&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;      -&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;&quot;&gt; uses&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt; dtolnay&#x2F;rust-toolchain@stable&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;      -&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;&quot;&gt; uses&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt; Swatinem&#x2F;rust-cache@v2&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;      -&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;&quot;&gt; run&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt; cargo test --all&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;With that, your dependencies will be cached between builds, and you can expect
a significant speedup.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;split-up-compile-and-test-steps&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#split-up-compile-and-test-steps&quot; aria-label=&quot;Anchor link for: split-up-compile-and-test-steps&quot;&gt;Split Up Compile And Test Steps&lt;&#x2F;a&gt;&lt;&#x2F;h3&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;yaml&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;-&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;&quot;&gt; name&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt; Compile&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #8BE9FD;&quot;&gt;  run&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt; cargo test --no-run --locked&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;-&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;&quot;&gt; name&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt; Test&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #8BE9FD;&quot;&gt;  run&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt; cargo test -- --nocapture --quiet&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;This makes it easier to find out how much time is spent on compilation and how
much on running the tests.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;disable-incremental-compilation-in-ci&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#disable-incremental-compilation-in-ci&quot; aria-label=&quot;Anchor link for: disable-incremental-compilation-in-ci&quot;&gt;Disable Incremental Compilation In CI&lt;&#x2F;a&gt;&lt;&#x2F;h3&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;yaml&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #8BE9FD;&quot;&gt;env&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #8BE9FD;&quot;&gt;  CARGO_INCREMENTAL&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt; 0&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Since CI builds are more akin to from-scratch builds, incremental compilation adds unnecessary dependency-tracking and IO overhead, reducing caching effectiveness.
&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;rust-analyzer&#x2F;rust-analyzer&#x2F;blob&#x2F;25368d24308d6a94ffe8b99f0122bcf5a2175322&#x2F;.github&#x2F;workflows&#x2F;ci.yaml#L11&quot;&gt;Here’s how to disable it.&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;h3 id=&quot;turn-off-debuginfo&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#turn-off-debuginfo&quot; aria-label=&quot;Anchor link for: turn-off-debuginfo&quot;&gt;Turn Off Debuginfo&lt;&#x2F;a&gt;&lt;&#x2F;h3&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;toml&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;[&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;&quot;&gt;profile&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;&quot;&gt;dev&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #8BE9FD;&quot;&gt;debug&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt; 0&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #8BE9FD;&quot;&gt;strip&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E9F284;&quot;&gt; &amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt;debuginfo&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E9F284;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Avoid linking debug info to speed up your build process, especially if you rarely use an actual debugger. There are two ways to avoid linking debug information: set &lt;code&gt;debug=0&lt;&#x2F;code&gt; to skip compiling it, or set &lt;code&gt;strip=&quot;debuginfo&quot;&lt;&#x2F;code&gt; to skip linking it. Unfortunately, changing these options can trigger a full rebuild with Cargo.&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;On Linux, set both for improved build times.&lt;&#x2F;li&gt;
&lt;li&gt;On Mac, use &lt;code&gt;debug=0&lt;&#x2F;code&gt; since rustc uses an external strip command.&lt;&#x2F;li&gt;
&lt;li&gt;On Windows, test both settings to see which is faster.&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;Note that without debug info, backtraces will only show function names, not line numbers. If needed, use &lt;code&gt;split-debuginfo=&quot;unpacked&quot;&lt;&#x2F;code&gt; for a compromise.&lt;&#x2F;p&gt;
&lt;p&gt;As a nice side-effect, this will also help shrink the size of &lt;code&gt;.&#x2F;target&lt;&#x2F;code&gt;, improving caching efficiency.&lt;&#x2F;p&gt;
&lt;p&gt;Here is a
&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;rust-analyzer&#x2F;rust-analyzer&#x2F;blob&#x2F;48f84a7b60bcbd7ec5fa6434d92d9e7a8eb9731b&#x2F;Cargo.toml#L6-L10&quot;&gt;sample config&lt;&#x2F;a&gt; for how to apply the settings.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;deny-warnings-through-an-environment-variable&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#deny-warnings-through-an-environment-variable&quot; aria-label=&quot;Anchor link for: deny-warnings-through-an-environment-variable&quot;&gt;Deny Warnings Through An Environment Variable&lt;&#x2F;a&gt;&lt;&#x2F;h3&gt;
&lt;p&gt;Avoid using &lt;code&gt;#![deny(warnings)]&lt;&#x2F;code&gt; in your code to prevent repetitive declarations.
Furthermore, it is fine to get warnings during local development.&lt;&#x2F;p&gt;
&lt;p&gt;Instead, &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;rust-analyzer&#x2F;rust-analyzer&#x2F;blob&#x2F;3dae94bf2b3e496adb049da589c7efef272a39b8&#x2F;.github&#x2F;workflows&#x2F;ci.yaml#L15&quot;&gt;add &lt;code&gt;-D warnings&lt;&#x2F;code&gt; to &lt;code&gt;RUSTFLAGS&lt;&#x2F;code&gt;&lt;&#x2F;a&gt; to globally deny warnings in all crates on CI.&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;yaml&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #8BE9FD;&quot;&gt;env&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #8BE9FD;&quot;&gt;  RUSTFLAGS&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt; -D warnings&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;&lt;h3 id=&quot;switch-to-a-faster-github-actions-runner&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#switch-to-a-faster-github-actions-runner&quot; aria-label=&quot;Anchor link for: switch-to-a-faster-github-actions-runner&quot;&gt;Switch To A Faster Github Actions Runner&lt;&#x2F;a&gt;&lt;&#x2F;h3&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;diff&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF5555;&quot;&gt;- runs-on: ubuntu-latest&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;+ runs-on: ubicloud&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Services like &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.ubicloud.com&#x2F;use-cases&#x2F;github-actions&quot;&gt;Ubicloud&lt;&#x2F;a&gt;,
&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;buildjet.com&quot;&gt;BuildJet&lt;&#x2F;a&gt;, or
&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;runs-on&#x2F;runs-on&quot;&gt;RunsOn&lt;&#x2F;a&gt; provide you with faster workers for
your Github Actions builds. Especially for Rust pipelines, the number of cores
can have a significant big impact on compile times, so it might be worth a try.&lt;&#x2F;p&gt;
&lt;p&gt;Here is an example from the &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;facebook&#x2F;folly&quot;&gt;Facebook Folly&lt;&#x2F;a&gt;
project using Ubicloud. Granted, this is a C++ project, but it shows the
potential of faster runners:&lt;&#x2F;p&gt;
&lt;p&gt;&lt;img src=&quot;https:&#x2F;&#x2F;corrode.dev&#x2F;blog&#x2F;tips-for-faster-rust-compile-times&#x2F;ubicloud-facebook-folly.svg&quot; alt=&quot;facebook&#x2F;folly build times&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;p&gt;After signing up with the service, you only need to change the runner
in your Github Actions workflow file.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;faster-docker-builds&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#faster-docker-builds&quot; aria-label=&quot;Anchor link for: faster-docker-builds&quot;&gt;Faster Docker Builds&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;h3 id=&quot;use-cargo-chef-to-speed-up-docker-builds&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#use-cargo-chef-to-speed-up-docker-builds&quot; aria-label=&quot;Anchor link for: use-cargo-chef-to-speed-up-docker-builds&quot;&gt;Use &lt;code&gt;cargo-chef&lt;&#x2F;code&gt; To Speed Up Docker Builds&lt;&#x2F;a&gt;&lt;&#x2F;h3&gt;
&lt;p&gt;Building Docker images from your Rust code?
These can be notoriously slow, because cargo doesn’t support building only a
project’s dependencies yet, invalidating the Docker cache with every build if you
don’t pay attention.
&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.lpalmieri.com&#x2F;posts&#x2F;fast-rust-docker-builds&#x2F;&quot;&gt;&lt;code&gt;cargo-chef&lt;&#x2F;code&gt;&lt;&#x2F;a&gt; to the
rescue! ⚡&lt;&#x2F;p&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;code&gt;cargo-chef&lt;&#x2F;code&gt; can be used to fully leverage Docker layer caching, therefore
massively speeding up Docker builds for Rust projects. On our commercial
codebase (~14k lines of code, ~500 dependencies) we measured a &lt;strong&gt;5x speed-up&lt;&#x2F;strong&gt;: we
cut Docker build times from &lt;strong&gt;~10 minutes to ~2 minutes.&lt;&#x2F;strong&gt;&lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
&lt;p&gt;Here is an example &lt;code&gt;Dockerfile&lt;&#x2F;code&gt; if you’re interested:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;docker&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;# Step 1: Compute a recipe file&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;FROM&lt;&#x2F;span&gt;&lt;span&gt; rust &lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;as&lt;&#x2F;span&gt;&lt;span&gt; planner&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;WORKDIR&lt;&#x2F;span&gt;&lt;span&gt; app&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;RUN&lt;&#x2F;span&gt;&lt;span&gt; cargo install cargo-chef&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;COPY&lt;&#x2F;span&gt;&lt;span&gt; . .&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;RUN&lt;&#x2F;span&gt;&lt;span&gt; cargo chef prepare --recipe-path recipe.json&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;# Step 2: Cache project dependencies&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;FROM&lt;&#x2F;span&gt;&lt;span&gt; rust &lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;as&lt;&#x2F;span&gt;&lt;span&gt; cacher&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;WORKDIR&lt;&#x2F;span&gt;&lt;span&gt; app&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;RUN&lt;&#x2F;span&gt;&lt;span&gt; cargo install cargo-chef&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;COPY&lt;&#x2F;span&gt;&lt;span&gt; --from=planner &#x2F;app&#x2F;recipe.json recipe.json&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;RUN&lt;&#x2F;span&gt;&lt;span&gt; cargo chef cook --release --recipe-path recipe.json&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;# Step 3: Build the binary&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;FROM&lt;&#x2F;span&gt;&lt;span&gt; rust &lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;as&lt;&#x2F;span&gt;&lt;span&gt; builder&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;WORKDIR&lt;&#x2F;span&gt;&lt;span&gt; app&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;COPY&lt;&#x2F;span&gt;&lt;span&gt; . .&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;# Copy over the cached dependencies from above&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;COPY&lt;&#x2F;span&gt;&lt;span&gt; --from=cacher &#x2F;app&#x2F;target target&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;COPY&lt;&#x2F;span&gt;&lt;span&gt; --from=cacher &#x2F;usr&#x2F;local&#x2F;cargo &#x2F;usr&#x2F;local&#x2F;cargo&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;RUN&lt;&#x2F;span&gt;&lt;span&gt; cargo build --release --bin app&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;# Step 4:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;# Create a tiny output image.&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;# It only contains our final binary.&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;FROM&lt;&#x2F;span&gt;&lt;span&gt; rust &lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;as&lt;&#x2F;span&gt;&lt;span&gt; runtime&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;WORKDIR&lt;&#x2F;span&gt;&lt;span&gt; app&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;COPY&lt;&#x2F;span&gt;&lt;span&gt; --from=builder &#x2F;app&#x2F;target&#x2F;release&#x2F;app &#x2F;usr&#x2F;local&#x2F;bin&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;ENTRYPOINT&lt;&#x2F;span&gt;&lt;span&gt; [&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt;&amp;quot;&#x2F;usr&#x2F;local&#x2F;bin&#x2F;app&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;LukeMathWalker&#x2F;cargo-chef&quot;&gt;&lt;code&gt;cargo-chef&lt;&#x2F;code&gt;&lt;&#x2F;a&gt; can help speed up
your continuous integration with Github Actions or your deployment process to Google
Cloud.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;consider-earthly-for-better-build-caching&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#consider-earthly-for-better-build-caching&quot; aria-label=&quot;Anchor link for: consider-earthly-for-better-build-caching&quot;&gt;Consider Earthly For Better Build Caching&lt;&#x2F;a&gt;&lt;&#x2F;h3&gt;
&lt;p&gt;Earthly is a relatively new build tool that is designed to be a replacement for
Makefiles, Dockerfiles, and other build tools. It provides fast, incremental
Rust builds for CI.&lt;&#x2F;p&gt;
&lt;blockquote&gt;
&lt;p&gt;Earthly speeds up Rust builds in CI by effectively implementing Cargo’s
caching and Rust’s incremental compilation. This approach significantly
reduces unnecessary rebuilds in CI, mirroring the efficiency of local Rust
builds.&lt;&#x2F;p&gt;
&lt;p&gt;Source: &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;earthly.dev&#x2F;rust&quot;&gt;Earthly for Rust&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
&lt;p&gt;They use a system called Satellites, which are persistent remote build
runners that retain cache data locally. This can drastically speed up CI build
times by eliminating cache uploads and downloads. Instead of bringing the cache
data to the compute, they colocate the cache data and compute, eliminating cache
transfers altogether. Less I&#x2F;O means faster builds.&lt;&#x2F;p&gt;
&lt;p&gt;Earthly also provides a &lt;code&gt;lib&#x2F;rust&lt;&#x2F;code&gt; library, which abstracts away cache
configuration entirely. It ensures that Rust is caching correctly and building
incrementally in CI. It can be used in your
&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;docs.earthly.dev&#x2F;docs&#x2F;earthfile&quot;&gt;&lt;code&gt;Earthfile&lt;&#x2F;code&gt;&lt;&#x2F;a&gt; like this:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;docker&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;IMPORT github.com&#x2F;earthly&#x2F;lib&#x2F;rust&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;If you’re curious, &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;earthly.dev&#x2F;rust&quot;&gt;Earthly’s Guide for Rust&lt;&#x2F;a&gt; details
a simple Rust example with optimized caching and compilation steps.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;ide-specific-optimizations&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#ide-specific-optimizations&quot; aria-label=&quot;Anchor link for: ide-specific-optimizations&quot;&gt;IDE-Specific Optimizations&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;p&gt;If you find that build times in your development environment are slow, here are
a few additional tips you can try.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;slow-debug-sessions-in-visual-studio-code&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#slow-debug-sessions-in-visual-studio-code&quot; aria-label=&quot;Anchor link for: slow-debug-sessions-in-visual-studio-code&quot;&gt;Slow Debug Sessions In Visual Studio Code&lt;&#x2F;a&gt;&lt;&#x2F;h3&gt;
&lt;p&gt;If you’re using Visual Studio Code and find that &lt;strong&gt;debug sessions&lt;&#x2F;strong&gt; are slow,
make sure you don’t have too many breakpoints set. &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.reddit.com&#x2F;r&#x2F;rust&#x2F;comments&#x2F;1ddktag&#x2F;looking_for_some_help_where_it_takes_a_minute_to&#x2F;&quot;&gt;Each breakpoint can slow down the debug session&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;close-unrelated-projects&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#close-unrelated-projects&quot; aria-label=&quot;Anchor link for: close-unrelated-projects&quot;&gt;Close Unrelated Projects&lt;&#x2F;a&gt;&lt;&#x2F;h3&gt;
&lt;p&gt;In case you have multiple projects open in Visual Studio Code, &lt;strong&gt;each instance runs its
own copy of rust-analyzer&lt;&#x2F;strong&gt;. This can slow down your machine. Close unrelated
projects if they aren’t needed.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;fix-rust-analyzer-cache-invalidation&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#fix-rust-analyzer-cache-invalidation&quot; aria-label=&quot;Anchor link for: fix-rust-analyzer-cache-invalidation&quot;&gt;Fix Rust Analyzer Cache Invalidation&lt;&#x2F;a&gt;&lt;&#x2F;h3&gt;
&lt;p&gt;If you’re using rust-analyzer in VS Code and find that you run into slow build times when saving your changes, it could be that the cache gets invalidated. This also results in dependencies like &lt;code&gt;serde&lt;&#x2F;code&gt; being rebuilt frequently.&lt;&#x2F;p&gt;
&lt;p&gt;You can fix this by configuring a separate target directory for rust-analyzer. Add this to your VS Code settings (preferably user settings):&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;json&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;{&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #8BE9FE;&quot;&gt;    &amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;&quot;&gt;rust-analyzer.cargo.targetDir&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FE;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt; true&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;This will make rust-analyzer build inside &lt;code&gt;target&#x2F;rust-analyzer&lt;&#x2F;code&gt; instead of the default &lt;code&gt;target&#x2F;&lt;&#x2F;code&gt; directory, preventing interference with your regular &lt;code&gt;cargo run&lt;&#x2F;code&gt; builds.&lt;&#x2F;p&gt;
&lt;p&gt;Some users reported &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;rust-lang&#x2F;rust-analyzer&#x2F;issues&#x2F;6007#issuecomment-2563288106&quot;&gt;significant speedups&lt;&#x2F;a&gt; thanks to that:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;plain&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;before: 34.98s user 2.02s system 122% cpu 30.176 total&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;after:   2.62s user 0.60s system 84% cpu 3.803 total&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;This could also help with &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;rust-lang&#x2F;rust-analyzer&#x2F;issues&#x2F;4616&quot;&gt;rust analyzer blocking debug builds&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;Credit: This tip was shared by &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.reddit.com&#x2F;r&#x2F;rust&#x2F;comments&#x2F;1if5wpm&#x2F;high_hopes_for_rust_where_are_we&#x2F;majhmhe&#x2F;&quot;&gt;asparck on Reddit&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;h1 id=&quot;summary&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#summary&quot; aria-label=&quot;Anchor link for: summary&quot;&gt;Summary&lt;&#x2F;a&gt;&lt;&#x2F;h1&gt;
&lt;p&gt;In this article, we’ve covered a lot of ground. We’ve looked at how to speed up
your Rust builds by using better hardware, optimizing your code, and using
better tools.&lt;&#x2F;p&gt;
&lt;p&gt;For CI-specific optimizations, don’t forget to check out &lt;a href=&quot;&#x2F;blog&#x2F;tips-for-faster-ci-builds&#x2F;&quot;&gt;Tips for Faster CI Builds&lt;&#x2F;a&gt;, which complements the techniques discussed here.&lt;&#x2F;p&gt;
&lt;p&gt;I hope that you were able to use some of these tips to speed up your Rust builds.
In case you found other ways to speed up your Rust builds, or if you have any
questions or feedback, I’d love to hear from you.&lt;&#x2F;p&gt;
&lt;div class=&quot;info&quot;&gt;
  
  &lt;div class=&quot;info-header&quot;&gt;
    
      &lt;span class=&quot;icon icon-crab&quot;&gt;&lt;&#x2F;span&gt;
    
    &lt;h4&gt;&lt;p&gt;Get Professional Support&lt;&#x2F;p&gt;
&lt;&#x2F;h4&gt;
  &lt;&#x2F;div&gt;
  
  &lt;p&gt;If you need support for commercial Rust projects,
I can also help you with performance problems and reducing your build times.
&lt;a href=&quot;&#x2F;services&quot;&gt;Get in touch.&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;

&lt;&#x2F;div&gt;
</description>
      </item>
      <item>
          <title>Apollo</title>
          <pubDate>Thu, 11 Jan 2024 00:00:00 +0000</pubDate>
          <author>Matthias Endler</author>
          <link>https://corrode.dev/podcast/s01e03-apollo/</link>
          <guid>https://corrode.dev/podcast/s01e03-apollo/</guid>
          <description xml:base="https://corrode.dev/podcast/s01e03-apollo/">&lt;div&gt;&lt;script id=&quot;letscast-player-b261a895&quot; src=&quot;https:&#x2F;&#x2F;letscast.fm&#x2F;podcasts&#x2F;rust-in-production-82281512&#x2F;episodes&#x2F;rust-in-production-ep-3-apollo-s-nicolas-moutschen&#x2F;player.js?size=s&quot;&gt;&lt;&#x2F;script&gt;&lt;&#x2F;div&gt;
&lt;p&gt;In this episode, we talk to Nicolas Moutschen, Staff Software Engineer at
&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.apollographql.com&#x2F;&quot;&gt;Apollo&lt;&#x2F;a&gt;, about how they use Rust to build the
Apollo GraphQL Platform.&lt;&#x2F;p&gt;</description>
      </item>
      <item>
          <title>PubNub</title>
          <pubDate>Thu, 28 Dec 2023 00:00:00 +0000</pubDate>
          <author>Matthias Endler</author>
          <link>https://corrode.dev/podcast/s01e02-pubnub/</link>
          <guid>https://corrode.dev/podcast/s01e02-pubnub/</guid>
          <description xml:base="https://corrode.dev/podcast/s01e02-pubnub/">&lt;div&gt;&lt;script id=&quot;letscast-player-99d93d84&quot; src=&quot;https:&#x2F;&#x2F;letscast.fm&#x2F;podcasts&#x2F;rust-in-production-82281512&#x2F;episodes&#x2F;rust-in-production-ep-2-pubnub-s-stephen-blum&#x2F;player.js?size=s&quot;&gt;&lt;&#x2F;script&gt;&lt;&#x2F;div&gt;
&lt;p&gt;In this episode, we talk to Stephen Blum, founder and CTO of
&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.pubnub.com&#x2F;&quot;&gt;PubNub&lt;&#x2F;a&gt;, about how they use Rust to build the PubNub
Data Stream Network. We discuss the challenges of building a global network that
handles trillions of messages per month, the reasons for choosing Rust over C
for future projects, and how Rust enables them to ship code to new platforms
faster.&lt;&#x2F;p&gt;</description>
      </item>
      <item>
          <title>InfluxData</title>
          <pubDate>Thu, 14 Dec 2023 00:00:00 +0000</pubDate>
          <author>Matthias Endler</author>
          <link>https://corrode.dev/podcast/s01e01-influxdata/</link>
          <guid>https://corrode.dev/podcast/s01e01-influxdata/</guid>
          <description xml:base="https://corrode.dev/podcast/s01e01-influxdata/">&lt;div&gt;&lt;script id=&quot;letscast-player-4f3d94e8&quot; src=&quot;https:&#x2F;&#x2F;letscast.fm&#x2F;podcasts&#x2F;rust-in-production-82281512&#x2F;episodes&#x2F;rust-in-production-ep-1-influxdata-s-paul-dix&#x2F;player.js?size=s&quot;&gt;&lt;&#x2F;script&gt;&lt;&#x2F;div&gt;
&lt;p&gt;In this episode, we talk to Paul Dix, founder and CTO of
&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.influxdata.com&#x2F;&quot;&gt;InfluxData&lt;&#x2F;a&gt;, about how they use Rust to build the
InfluxDB time series database and related products. We discuss the challenges of
building a database that scales to handle millions of writes per second, the
reasons for choosing Rust, and how Rust enables them to ship more reliable
software that customers can depend on.&lt;&#x2F;p&gt;
&lt;div class=&quot;info dashed&quot;&gt;
  &lt;div class=&quot;info-header&quot;&gt;
    &lt;i class=&quot;icon icon-info&quot;&gt;&lt;&#x2F;i&gt;
    &lt;h4&gt;Proudly Supported by CodeCrafters&lt;&#x2F;h4&gt;
  &lt;&#x2F;div&gt;
  &lt;p&gt;
    CodeCrafters helps you become proficient in Rust by building real-world,
    production-grade projects. Learn hands-on by creating your own shell, HTTP
    server, Redis, Kafka, Git, SQLite, or DNS service from scratch.
  &lt;&#x2F;p&gt;
  &lt;p&gt;
    Start for free today and enjoy 40% off any paid plan by using
    &lt;a href=&quot;https:&#x2F;&#x2F;app.codecrafters.io&#x2F;join?via=mre&quot;&gt;this link&lt;&#x2F;a&gt;.
  &lt;&#x2F;p&gt;
&lt;&#x2F;div&gt;
&lt;h2 id=&quot;show-notes&quot;&gt;Show Notes&lt;&#x2F;h2&gt;
&lt;h3 id=&quot;about-influxdata&quot;&gt;About InfluxData&lt;&#x2F;h3&gt;
&lt;p&gt;InfluxData is the creator of InfluxDB, the leading open source time series
database. They offer a cloud service, InfluxDB Cloud, and a commercial
on-premise product, &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.influxdata.com&#x2F;products&#x2F;influxdb-enterprise&#x2F;&quot;&gt;InfluxDB Enterprise&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;about-paul-dix&quot;&gt;About Paul Dix&lt;&#x2F;h3&gt;
&lt;p&gt;Paul Dix is the founder and CTO of &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.influxdata.com&#x2F;&quot;&gt;InfluxData&lt;&#x2F;a&gt;. He
has helped build software for startups, large companies and organizations like
Microsoft, Google, McAfee, Thomson Reuters, and Air Force Space Command. He is
the series editor for Addison Wesley’s &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.informit.com&#x2F;imprint&#x2F;series_detail.aspx?ser=4255387&quot;&gt;Data &amp;amp; Analytics book and video
series&lt;&#x2F;a&gt;. In
2010 Paul wrote the book &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.oreilly.com&#x2F;library&#x2F;view&#x2F;service-oriented-design-with&#x2F;9780321700124&#x2F;&quot;&gt;“Service Oriented Design with Ruby and
Rails”&lt;&#x2F;a&gt;
for Addison Wesley’s Professional Ruby Series. In 2009 he started the &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.meetup.com&#x2F;nyc-machine-learning&#x2F;&quot;&gt;NYC
Machine Learning Meetup&lt;&#x2F;a&gt;, which
now has over 13,000 members. Paul holds a degree in computer science from
Columbia University.&lt;&#x2F;p&gt;
&lt;p&gt;You can find Paul on &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;twitter.com&#x2F;pauldix&quot;&gt;Twitter&lt;&#x2F;a&gt; and
&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;pauldix&quot;&gt;GitHub&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;official-links&quot;&gt;Official Links&lt;&#x2F;h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.influxdata.com&#x2F;&quot;&gt;InfluxData&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.influxdata.com&#x2F;careers&#x2F;&quot;&gt;Careers at InfluxData&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;Blog post: &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.influxdata.com&#x2F;blog&#x2F;meet-founders-who-rewrote-in-rust&#x2F;&quot;&gt;Meet the Founders Who Rewrote in Rust&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;Reddit: &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.reddit.com&#x2F;r&#x2F;rust&#x2F;comments&#x2F;16v13l5&#x2F;influxdb_officially_made_the_switch_from_go_rust&#x2F;&quot;&gt;Details and discussion on the Rust rewrite&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;Blog post: &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.influxdata.com&#x2F;blog&#x2F;the-plan-for-influxdb-3-0-open-source&#x2F;&quot;&gt;The Plan for InfluxDB 3.0 Open Source&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
</description>
      </item>
      <item>
          <title>Teaser</title>
          <pubDate>Mon, 11 Dec 2023 00:00:00 +0000</pubDate>
          <author>Matthias Endler</author>
          <link>https://corrode.dev/podcast/s01e00-teaser/</link>
          <guid>https://corrode.dev/podcast/s01e00-teaser/</guid>
          <description xml:base="https://corrode.dev/podcast/s01e00-teaser/">&lt;div&gt;&lt;script id=&quot;letscast-player-ff3abca4&quot; src=&quot;https:&#x2F;&#x2F;letscast.fm&#x2F;podcasts&#x2F;rust-in-production-82281512&#x2F;episodes&#x2F;rust-in-production-series-teaser&#x2F;player.js?size=s&quot;&gt;&lt;&#x2F;script&gt;&lt;&#x2F;div&gt;
&lt;p&gt;There are a lot of awesome podcasts about Rust.
We loved listening to &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;newrustacean.com&#x2F;&quot;&gt;New Rustacean&lt;&#x2F;a&gt;
and are excited about the new &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;rustacean-station.org&#x2F;&quot;&gt;Rustacean Station&lt;&#x2F;a&gt; and
&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.marcoieni.com&#x2F;2023&#x2F;08&#x2F;rustship-a-new-rust-podcast&#x2F;&quot;&gt;RustShip&lt;&#x2F;a&gt;
episodes.&lt;&#x2F;p&gt;
&lt;p&gt;But we felt that there is a gap in the Rust podcast landscape: We
wanted to hear more about how companies use Rust in production.&lt;&#x2F;p&gt;
&lt;p&gt;So we decided to sit down and create the content we wanted to listen to. We
interviewed people from companies that use Rust in production and asked them
the tough questions that you want to hear answered but never get the chance to
ask:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;Why did they choose Rust?&lt;&#x2F;li&gt;
&lt;li&gt;What are the real challenges of using Rust in production?&lt;&#x2F;li&gt;
&lt;li&gt;How did your team get up to speed with Rust?&lt;&#x2F;li&gt;
&lt;li&gt;Did you notice any performance improvements?&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;These and other questions are top of mind for developers and decision makers
who are considering Rust for their next project. We want to help them
understand the benefits and challenges of using Rust in production before
they head down that path.&lt;&#x2F;p&gt;
&lt;p&gt;And we’re starting with a bang: In the
first episode we will talk to Paul Dix, founder and CTO of
&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.influxdata.com&#x2F;&quot;&gt;InfluxData&lt;&#x2F;a&gt;, about how the company rewrote the
core of their time series database in Rust. Stay tuned! We will release the
first episode on Thursday, December 14th and then biweekly episodes every Thursday.&lt;&#x2F;p&gt;</description>
      </item>
      <item>
          <title>Navigating Programming Paradigms in Rust</title>
          <pubDate>Mon, 04 Dec 2023 00:00:00 +0000</pubDate>
          <author>Matthias Endler</author>
          <link>https://corrode.dev/blog/paradigms/</link>
          <guid>https://corrode.dev/blog/paradigms/</guid>
          <description xml:base="https://corrode.dev/blog/paradigms/">&lt;p&gt;Rust is a multi-paradigm programming language, accommodating imperative,
object-oriented, and functional programming styles. The choice of style often
depends on a developer’s background and the specific problem they’re addressing.&lt;&#x2F;p&gt;
&lt;p&gt;With Rust attracting developers from varied backgrounds such as C++, Java,
Python, and Haskell, it has shaped its own &lt;em&gt;unique&lt;&#x2F;em&gt; set of styles and idioms.
This diversity is a strength, but it also leads to uncertainty about which style
to use in various scenarios.&lt;&#x2F;p&gt;
&lt;p&gt;As the &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;doc.rust-lang.org&#x2F;book&#x2F;ch17-00-oop.html&quot;&gt;Rust Book explains&lt;&#x2F;a&gt;:&lt;&#x2F;p&gt;
&lt;blockquote&gt;
&lt;p&gt;Many competing definitions describe what Object-Oriented Programming
is, and by some of these definitions Rust is object-oriented.&lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
&lt;p&gt;However, it &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;doc.rust-lang.org&#x2F;book&#x2F;ch13-00-functional-features.html&quot;&gt;also states&lt;&#x2F;a&gt;:&lt;&#x2F;p&gt;
&lt;blockquote&gt;
&lt;p&gt;Rust’s design has taken inspiration from many existing languages and
techniques, and one significant influence is functional programming.&lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
&lt;p&gt;These statements are not contradictory, but they do leave a lot of room for
interpretation and personal preference.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;guiding-principles-for-choosing-the-right-paradigm&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#guiding-principles-for-choosing-the-right-paradigm&quot; aria-label=&quot;Anchor link for: guiding-principles-for-choosing-the-right-paradigm&quot;&gt;Guiding Principles For Choosing The Right Paradigm&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;p&gt;Rust is certainly influenced by object-oriented programming concepts. One factor
that sets it apart from other object-oriented languages is its composition-based
nature, as opposed to being inheritance-based. Its trait system is a core
component of this object-oriented design, a concept absent in languages like C++
and Java.&lt;&#x2F;p&gt;
&lt;p&gt;Similarly, Rust’s design encourages patterns that align closely with functional
programming principles: immutability, iterator patterns, algebraic data types,
and pattern matching.&lt;&#x2F;p&gt;
&lt;p&gt;Just as Rust adopts certain object-oriented principles without being a purely
object-oriented language, it similarly embraces functional programming concepts
without being a purely functional language. It allows side effects everywhere
and does not strictly enforce &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Referential_transparency&quot;&gt;referential
transparency&lt;&#x2F;a&gt; — the
ability to replace an expression with its value without changing the program’s
behavior.&lt;&#x2F;p&gt;
&lt;p&gt;In conclusion, providing some guidance on using different paradigms in Rust
might be helpful, especially for developers transitioning from other languages.
This article explores my personal decision-making process when choosing between
different paradigms in Rust, a process that has by now become almost second
nature.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;a-small-example&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#a-small-example&quot; aria-label=&quot;Anchor link for: a-small-example&quot;&gt;A Small Example&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;p&gt;There is nothing wrong with simple &lt;code&gt;for&lt;&#x2F;code&gt; loops in Rust.&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;let mut&lt;&#x2F;span&gt;&lt;span&gt; sum&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt; 0&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;for&lt;&#x2F;span&gt;&lt;span&gt; i&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; in&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt; 0&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;..&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt;10&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    sum&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; +=&lt;&#x2F;span&gt;&lt;span&gt; i;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;But even in such a short example, we can see a discrepancy between the problem
we’re trying to solve and the code we’re writing: The intermediate values of
&lt;code&gt;sum&lt;&#x2F;code&gt; are irrelevant! We only care about the final result.&lt;&#x2F;p&gt;
&lt;p&gt;Compare that to a more functional version:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;let&lt;&#x2F;span&gt;&lt;span&gt; sum&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; u32&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; (&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt;0&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;..&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt;10&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;sum&lt;&#x2F;span&gt;&lt;span&gt;();&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;In small examples like this, it might not matter much, but when we start working
with nested loops, we see that in the imperative approach, more lines are
dedicated to bookkeeping than to the actual problem. This causes the code’s
accidental complexity (the unnecessary complexity we introduce ourselves)
to increase. Complexity, no matter how small, costs attention.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;a-slightly-bigger-example-nested-loops&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#a-slightly-bigger-example-nested-loops&quot; aria-label=&quot;Anchor link for: a-slightly-bigger-example-nested-loops&quot;&gt;A Slightly Bigger Example: Nested Loops&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;p&gt;Let’s consider a slightly bigger example. Imagine we had a list of programming
languages, their supported paradigms, and the number of production users for
each language. The task is to find the top five languages that support
functional programming and have the most users.&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;&#x2F;&#x2F; All data is made up for the sake of this example! We love you, Haskell.&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;let&lt;&#x2F;span&gt;&lt;span&gt; languages&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; vec!&lt;&#x2F;span&gt;&lt;span&gt;[&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;    Language&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;new&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt;&amp;quot;Rust&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; vec!&lt;&#x2F;span&gt;&lt;span&gt;[Paradigm&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;Functional&lt;&#x2F;span&gt;&lt;span&gt;, Paradigm&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;ObjectOriented&lt;&#x2F;span&gt;&lt;span&gt;],&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt; 100_000&lt;&#x2F;span&gt;&lt;span&gt;),&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;    Language&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;new&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt;&amp;quot;Go&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; vec!&lt;&#x2F;span&gt;&lt;span&gt;[Paradigm&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;ObjectOriented&lt;&#x2F;span&gt;&lt;span&gt;],&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt; 200_000&lt;&#x2F;span&gt;&lt;span&gt;),&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;    Language&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;new&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt;&amp;quot;Haskell&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; vec!&lt;&#x2F;span&gt;&lt;span&gt;[Paradigm&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;Functional&lt;&#x2F;span&gt;&lt;span&gt;],&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt; 5_000&lt;&#x2F;span&gt;&lt;span&gt;),&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;    Language&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;new&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt;&amp;quot;Java&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; vec!&lt;&#x2F;span&gt;&lt;span&gt;[Paradigm&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;ObjectOriented&lt;&#x2F;span&gt;&lt;span&gt;],&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt; 1_000_000&lt;&#x2F;span&gt;&lt;span&gt;),&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;    Language&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;new&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt;&amp;quot;C++&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; vec!&lt;&#x2F;span&gt;&lt;span&gt;[Paradigm&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;ObjectOriented&lt;&#x2F;span&gt;&lt;span&gt;],&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt; 1_000_000&lt;&#x2F;span&gt;&lt;span&gt;),&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;    Language&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;new&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt;&amp;quot;Python&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; vec!&lt;&#x2F;span&gt;&lt;span&gt;[Paradigm&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;ObjectOriented&lt;&#x2F;span&gt;&lt;span&gt;, Paradigm&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;Functional&lt;&#x2F;span&gt;&lt;span&gt;],&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt; 1_000_000&lt;&#x2F;span&gt;&lt;span&gt;),&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;];&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Here is a &lt;em&gt;painfully&lt;&#x2F;em&gt; explicit solution using nested &lt;code&gt;for&lt;&#x2F;code&gt; loops:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;&#x2F;&#x2F; Filter languages to keep only the functional ones&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;let mut&lt;&#x2F;span&gt;&lt;span&gt; functional_languages&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; vec!&lt;&#x2F;span&gt;&lt;span&gt;[];&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;for&lt;&#x2F;span&gt;&lt;span&gt; language&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; in&lt;&#x2F;span&gt;&lt;span&gt; languages {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    if&lt;&#x2F;span&gt;&lt;span&gt; language&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span&gt;paradigms&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;contains&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;&amp;amp;&lt;&#x2F;span&gt;&lt;span&gt;Paradigm&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;Functional&lt;&#x2F;span&gt;&lt;span&gt;) {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        functional_languages&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;push&lt;&#x2F;span&gt;&lt;span&gt;(language);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;&#x2F;&#x2F; Sort the functional languages by the number of users in descending order&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;for&lt;&#x2F;span&gt;&lt;span&gt; i&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; in&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt; 1&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;..&lt;&#x2F;span&gt;&lt;span&gt;functional_languages&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;len&lt;&#x2F;span&gt;&lt;span&gt;() {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    let mut&lt;&#x2F;span&gt;&lt;span&gt; j&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; i;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    while&lt;&#x2F;span&gt;&lt;span&gt; j&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; &amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt; 0&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; &amp;amp;&amp;amp;&lt;&#x2F;span&gt;&lt;span&gt; functional_languages[j]&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span&gt;users&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; &amp;gt;&lt;&#x2F;span&gt;&lt;span&gt; functional_languages[j&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; -&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt; 1&lt;&#x2F;span&gt;&lt;span&gt;]&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span&gt;users {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        functional_languages&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;swap&lt;&#x2F;span&gt;&lt;span&gt;(j, j&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; -&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt; 1&lt;&#x2F;span&gt;&lt;span&gt;);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        j&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; -=&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt; 1&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;&#x2F;&#x2F; Keep only the top 5 languages&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;while&lt;&#x2F;span&gt;&lt;span&gt; functional_languages&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;len&lt;&#x2F;span&gt;&lt;span&gt;() &amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt; 5&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    functional_languages&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;pop&lt;&#x2F;span&gt;&lt;span&gt;();&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;(&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;play.rust-lang.org&#x2F;?version=stable&amp;amp;mode=debug&amp;amp;edition=2021&amp;amp;gist=f9b28b96acde1f9d11e8dd5957539826&quot;&gt;Rust Playground&lt;&#x2F;a&gt;)&lt;&#x2F;p&gt;
&lt;p&gt;This is a &lt;em&gt;very verbose&lt;&#x2F;em&gt;, imperative solution. We mutate the vector in-place and
destroy the intermediate results in the process. While it’s not incorrect, I
would argue that it’s not the most idiomatic Rust code either.&lt;&#x2F;p&gt;
&lt;p&gt;In practice, you would probably reach for a few more helper methods from the
standard library:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;let mut&lt;&#x2F;span&gt;&lt;span&gt; top_languages&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; vec!&lt;&#x2F;span&gt;&lt;span&gt;[];&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;for&lt;&#x2F;span&gt;&lt;span&gt; language&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; in&lt;&#x2F;span&gt;&lt;span&gt; languages {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    if&lt;&#x2F;span&gt;&lt;span&gt; language&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span&gt;paradigms&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;contains&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;&amp;amp;&lt;&#x2F;span&gt;&lt;span&gt;Paradigm&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;Functional&lt;&#x2F;span&gt;&lt;span&gt;) {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        top_languages&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;push&lt;&#x2F;span&gt;&lt;span&gt;(language);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;&#x2F;&#x2F; Sort our languages in descending order of popularity.&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;&#x2F;&#x2F; This line is already somewhat functional in nature.&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;top_languages&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;sort_by_key&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;|&lt;&#x2F;span&gt;&lt;span&gt;lang&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;|&lt;&#x2F;span&gt;&lt;span&gt; std&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span&gt;cmp&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;Reverse&lt;&#x2F;span&gt;&lt;span&gt;(lang&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span&gt;users));&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;top_languages&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;truncate&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt;5&lt;&#x2F;span&gt;&lt;span&gt;);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Since we’re consuming &lt;code&gt;languages&lt;&#x2F;code&gt; anyway, we might as well be a little more
concise when filtering:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;let mut&lt;&#x2F;span&gt;&lt;span&gt; top_languages&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; languages;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;top_languages&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;retain&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;|&lt;&#x2F;span&gt;&lt;span&gt;language&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;|&lt;&#x2F;span&gt;&lt;span&gt; language&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span&gt;paradigms&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;contains&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;&amp;amp;&lt;&#x2F;span&gt;&lt;span&gt;Paradigm&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;Functional&lt;&#x2F;span&gt;&lt;span&gt;));&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;We still use a mutable variable, but now the code looks more succinct. &lt;code&gt;retain&lt;&#x2F;code&gt;
is a higher-order method that takes a closure as an argument, so the code
naturally became a little more functional. Let’s continue down this path and
see where it takes us next.&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;let mut&lt;&#x2F;span&gt;&lt;span&gt; top_languages&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; languages&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;clone&lt;&#x2F;span&gt;&lt;span&gt;();&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;top_languages&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;sort&lt;&#x2F;span&gt;&lt;span&gt;();&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;let&lt;&#x2F;span&gt;&lt;span&gt; top_languages&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Vec&lt;&#x2F;span&gt;&lt;span&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;Language&lt;&#x2F;span&gt;&lt;span&gt;&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; top_languages&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    .&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;into_iter&lt;&#x2F;span&gt;&lt;span&gt;()&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;    &#x2F;&#x2F; Only keep functional languages&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    .&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;filter&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;|&lt;&#x2F;span&gt;&lt;span&gt;language&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;|&lt;&#x2F;span&gt;&lt;span&gt; language&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span&gt;paradigms&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;contains&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;&amp;amp;&lt;&#x2F;span&gt;&lt;span&gt;Paradigm&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;Functional&lt;&#x2F;span&gt;&lt;span&gt;))&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;    &#x2F;&#x2F; Keep only the top 5 languages&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    .&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;take&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt;5&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;    &#x2F;&#x2F; Collect the results into a vector&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    .&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;collect&lt;&#x2F;span&gt;&lt;span&gt;();&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Or, if external crates are an option, we could use &lt;code&gt;sorted_by_key&lt;&#x2F;code&gt; from
&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;docs.rs&#x2F;itertools&#x2F;latest&#x2F;itertools&#x2F;trait.Itertools.html#method.sorted_by_key&quot;&gt;&lt;code&gt;itertools&lt;&#x2F;code&gt;&lt;&#x2F;a&gt;
to chain all intermediate operations:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;let&lt;&#x2F;span&gt;&lt;span&gt; top_languages&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Vec&lt;&#x2F;span&gt;&lt;span&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;Language&lt;&#x2F;span&gt;&lt;span&gt;&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; languages&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    .&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;iter&lt;&#x2F;span&gt;&lt;span&gt;()&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;    &#x2F;&#x2F; Only keep functional languages&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    .&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;filter&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;|&lt;&#x2F;span&gt;&lt;span&gt;language&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;|&lt;&#x2F;span&gt;&lt;span&gt; language&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span&gt;paradigms&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;contains&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;&amp;amp;&lt;&#x2F;span&gt;&lt;span&gt;Paradigm&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;Functional&lt;&#x2F;span&gt;&lt;span&gt;))&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;    &#x2F;&#x2F; Sort our languages in descending order of popularity.&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    .&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;sorted_by_key&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;|&lt;&#x2F;span&gt;&lt;span&gt;lang&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;|&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; Reverse&lt;&#x2F;span&gt;&lt;span&gt;(lang&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span&gt;users))&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;    &#x2F;&#x2F; Keep only the top 5 languages&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    .&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;take&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt;5&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;    &#x2F;&#x2F; Collect the results into a new vector&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    .&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;collect&lt;&#x2F;span&gt;&lt;span&gt;();&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;(&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;play.rust-lang.org&#x2F;?version=stable&amp;amp;mode=debug&amp;amp;edition=2021&amp;amp;gist=8c1d45de856b6a7980ea48ebeaf43290&quot;&gt;Rust Playground&lt;&#x2F;a&gt;)&lt;&#x2F;p&gt;
&lt;p&gt;Sorting the entire list (even if it’s filtered) to extract just the top 5
elements seems somewhat inefficient. This highlights a limitation in Rust
compared to C++, which offers a
&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;en.cppreference.com&#x2F;w&#x2F;cpp&#x2F;algorithm&#x2F;partial_sort&quot;&gt;partial_sort&lt;&#x2F;a&gt;
function in its standard library. While Rust doesn’t have an equivalent in std,
there are third-party crates. Alternatively, a &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;doc.rust-lang.org&#x2F;std&#x2F;collections&#x2F;struct.BinaryHeap.html&quot;&gt;BinaryHeap&lt;&#x2F;a&gt;
can be used.&lt;&#x2F;p&gt;
&lt;p&gt;To me, this solution is easier to reason about. The operations are
neatly aligned below each other, and the code reads like a description of what
we’re trying to achieve. I do admit, however, that it takes some getting used
to, especially if you’re not familiar with functional programming patterns.&lt;&#x2F;p&gt;
&lt;p&gt;One could say that I hand-picked a problem that is well-suited for functional
programming, and that is certainly the case. The truth is, that this way of
method chaining just feels natural after a while — especially for ad-hoc
transformations on immutable data structures.&lt;&#x2F;p&gt;
&lt;p&gt;There are a few reasons for this:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Readability&lt;&#x2F;strong&gt;: The steps are easy to follow.&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Library Support&lt;&#x2F;strong&gt;: The Rust standard library and external crates provide
many helpful combinators for iterators, which play nicely with immutable data structures.&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Efficiency&lt;&#x2F;strong&gt;: Under the hood, methods like &lt;code&gt;map&lt;&#x2F;code&gt; and &lt;code&gt;filter&lt;&#x2F;code&gt; create new
iterators that operate on the previous iterator and do not incur any allocations.
The actual computations (like adding 1 or filtering even numbers) are only
executed when the final iterator is consumed, in this case by
the &lt;code&gt;collect&lt;&#x2F;code&gt; method. The &lt;code&gt;collect&lt;&#x2F;code&gt; method makes a single allocation to store the
results in a new vector. Our higher-level abstractions incur no runtime
overhead.&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Parallelism&lt;&#x2F;strong&gt;: The functional approach lends itself to parallel computation.
Each chain of operations is independent of the others, allowing them
to be executed simultaneously on modern hardware.&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;The result is clean, readable, and efficient code, which is why you’ll see this
pattern a lot.&lt;&#x2F;p&gt;
&lt;blockquote&gt;
&lt;p&gt;No matter what language you work in, programming in a functional style provides
benefits. You should do it whenever it is convenient, and you should think hard
about the decision when it isn’t convenient. — &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;web.archive.org&#x2F;web&#x2F;20120427212006&#x2F;www.altdevblogaday.com&#x2F;2012&#x2F;04&#x2F;26&#x2F;functional-programming-in-c&#x2F;&quot;&gt;John Carmack&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
&lt;p&gt;Carmack talks about &lt;em&gt;convenience&lt;&#x2F;em&gt; here. What is the tipping point where
functional programming becomes inconvenient? Let’s explore that with a more
realistic example.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;real-world-example-filtering-a-list-of-files&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#real-world-example-filtering-a-list-of-files&quot; aria-label=&quot;Anchor link for: real-world-example-filtering-a-list-of-files&quot;&gt;Real-World Example: Filtering a List of Files&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;p&gt;Here is a little Rust exercise: how would you list all XML files in a directory?
Before you continue, feel free to try this yourself. See
which style you would naturally lean towards. Why not try different approaches
and see which one you prefer?&lt;&#x2F;p&gt;
&lt;h3 id=&quot;imperative-style&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#imperative-style&quot; aria-label=&quot;Anchor link for: imperative-style&quot;&gt;Imperative Style&lt;&#x2F;a&gt;&lt;&#x2F;h3&gt;
&lt;p&gt;Here is my imperative solution:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;fn&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; xml_files&lt;&#x2F;span&gt;&lt;span&gt;(p&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;: &amp;amp;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;Path&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; -&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Result&lt;&#x2F;span&gt;&lt;span&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;Vec&lt;&#x2F;span&gt;&lt;span&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;PathBuf&lt;&#x2F;span&gt;&lt;span&gt;&amp;gt;&amp;gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    let mut&lt;&#x2F;span&gt;&lt;span&gt; files&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Vec&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;new&lt;&#x2F;span&gt;&lt;span&gt;();&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    for&lt;&#x2F;span&gt;&lt;span&gt; f&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; in&lt;&#x2F;span&gt;&lt;span&gt; fs&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;read_dir&lt;&#x2F;span&gt;&lt;span&gt;(p)&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;?&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;        &#x2F;&#x2F; This line is necessary, because the file could have&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;        &#x2F;&#x2F; been deleted since the call to `read_dir`.&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;        let&lt;&#x2F;span&gt;&lt;span&gt; f&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; f&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;?&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;        if&lt;&#x2F;span&gt;&lt;span&gt; f&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;path&lt;&#x2F;span&gt;&lt;span&gt;()&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;extension&lt;&#x2F;span&gt;&lt;span&gt;()&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; ==&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Some&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;OsStr&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;new&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt;&amp;quot;xml&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;)) {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            files&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;push&lt;&#x2F;span&gt;&lt;span&gt;(f&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;path&lt;&#x2F;span&gt;&lt;span&gt;());&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;    Ok&lt;&#x2F;span&gt;&lt;span&gt;(files)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;(&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;play.rust-lang.org&#x2F;?version=stable&amp;amp;mode=debug&amp;amp;edition=2021&amp;amp;gist=f3314816d1584ea372e8cdf6bdccd426&quot;&gt;Rust Playground&lt;&#x2F;a&gt;)&lt;&#x2F;p&gt;
&lt;p&gt;Not great, not terrible.&lt;&#x2F;p&gt;
&lt;p&gt;We have to do some bookkeeping, and there are some minor paper cuts like &lt;code&gt;let f = f?;&lt;&#x2F;code&gt; and the bit about &lt;code&gt;OsStr::to_str&lt;&#x2F;code&gt;, but overall it’s fine. The paper cuts
are due to the &lt;em&gt;inherent&lt;&#x2F;em&gt; complexity of the problem: dealing with the
possibility of errors and the fact that the file extension might not be valid
UTF-8 on all platforms.&lt;&#x2F;p&gt;
&lt;p&gt;As the &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;doc.rust-lang.org&#x2F;std&#x2F;ffi&#x2F;struct.OsString.html&quot;&gt;documentation for
&lt;code&gt;OsStr&lt;&#x2F;code&gt;&lt;&#x2F;a&gt; explains:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;On Unix systems, strings are often arbitrary sequences of non-zero bytes, in
many cases interpreted as UTF-8.&lt;&#x2F;li&gt;
&lt;li&gt;On Windows, strings are often arbitrary sequences of non-zero 16-bit values,
interpreted as UTF-16 when it is valid to do so.&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;The astute reader might have noticed that we don’t check if the path is
actually a file before we check the extension. This is done in the interest of
brevity.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;functional-style&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#functional-style&quot; aria-label=&quot;Anchor link for: functional-style&quot;&gt;Functional Style&lt;&#x2F;a&gt;&lt;&#x2F;h3&gt;
&lt;p&gt;Let’s see how we can solve this problem in a more functional style:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;fn&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; xml_files&lt;&#x2F;span&gt;&lt;span&gt;(p&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;: &amp;amp;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;Path&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; -&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Result&lt;&#x2F;span&gt;&lt;span&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;Vec&lt;&#x2F;span&gt;&lt;span&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;PathBuf&lt;&#x2F;span&gt;&lt;span&gt;&amp;gt;&amp;gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    let&lt;&#x2F;span&gt;&lt;span&gt; entries&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; fs&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;read_dir&lt;&#x2F;span&gt;&lt;span&gt;(p)&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;?&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;        .&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;filter_map&lt;&#x2F;span&gt;&lt;span&gt;(Result&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span&gt;ok)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;        .&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;map&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;|&lt;&#x2F;span&gt;&lt;span&gt;entry&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;|&lt;&#x2F;span&gt;&lt;span&gt; entry&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;path&lt;&#x2F;span&gt;&lt;span&gt;())&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;        .&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;filter&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;|&lt;&#x2F;span&gt;&lt;span&gt;path&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;|&lt;&#x2F;span&gt;&lt;span&gt; path&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;extension&lt;&#x2F;span&gt;&lt;span&gt;()&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; ==&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Some&lt;&#x2F;span&gt;&lt;span&gt;(OsStr&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;new&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt;&amp;quot;xml&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;)))&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;        .&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;collect&lt;&#x2F;span&gt;&lt;span&gt;();&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;    Ok&lt;&#x2F;span&gt;&lt;span&gt;(entries)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;(&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;play.rust-lang.org&#x2F;?version=stable&amp;amp;mode=debug&amp;amp;edition=2021&amp;amp;gist=448b6246dd4da2d1cd9b8cf1f4e1f09e&quot;&gt;Rust Playground&lt;&#x2F;a&gt;)&lt;&#x2F;p&gt;
&lt;p&gt;This implementation is arguably more streamlined. It maps directory
entries to paths, filters out non-XML files, and collects the results, all
without needing mutable variables or conditional branching.&lt;&#x2F;p&gt;
&lt;p&gt;That said, the solution also has its drawbacks.
Most importantly, it is not equivalent to the imperative version.
That is because &lt;code&gt;filter_map(Result::ok)&lt;&#x2F;code&gt; filters out all errors.&lt;&#x2F;p&gt;
&lt;div class=&quot;info&quot;&gt;
  
  &lt;div class=&quot;info-header&quot;&gt;
    
      &lt;span class=&quot;icon icon-info&quot;&gt;&lt;&#x2F;span&gt;
    
    &lt;h4&gt;&lt;p&gt;What is the difference between &lt;code&gt;filter&lt;&#x2F;code&gt; and &lt;code&gt;filter_map&lt;&#x2F;code&gt;?&lt;&#x2F;p&gt;
&lt;&#x2F;h4&gt;
  &lt;&#x2F;div&gt;
  
  &lt;p&gt;In Rust, &lt;code&gt;filter&lt;&#x2F;code&gt; takes a closure that returns a &lt;code&gt;bool&lt;&#x2F;code&gt; to decide whether to
include an element in the resulting iterator, whereas &lt;code&gt;filter_map&lt;&#x2F;code&gt; takes a
closure that returns an &lt;code&gt;Option&amp;lt;T&amp;gt;&lt;&#x2F;code&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;For &lt;code&gt;filter_map&lt;&#x2F;code&gt;, if the closure returns &lt;code&gt;Some(value)&lt;&#x2F;code&gt;, that value is included
in the new iterator; if it returns &lt;code&gt;None&lt;&#x2F;code&gt;, the element is excluded. Essentially,
&lt;code&gt;filter_map&lt;&#x2F;code&gt; allows filtering and mapping in a single step.&lt;&#x2F;p&gt;

&lt;&#x2F;div&gt;
&lt;p&gt;Whether we want to ignore errors depends on the use case;
it is a tradeoff between correctness and ergonomics.
In production code, we should at least log all errors, though.
We can use &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;doc.rust-lang.org&#x2F;std&#x2F;iter&#x2F;trait.Iterator.html#method.inspect&quot;&gt;&lt;code&gt;inspect&lt;&#x2F;code&gt;&lt;&#x2F;a&gt;
to do that:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;fn&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; xml_files&lt;&#x2F;span&gt;&lt;span&gt;(p&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;: &amp;amp;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;Path&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; -&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Result&lt;&#x2F;span&gt;&lt;span&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;Vec&lt;&#x2F;span&gt;&lt;span&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;PathBuf&lt;&#x2F;span&gt;&lt;span&gt;&amp;gt;&amp;gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    let&lt;&#x2F;span&gt;&lt;span&gt; entries&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; fs&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;read_dir&lt;&#x2F;span&gt;&lt;span&gt;(p)&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;?&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;        &#x2F;&#x2F; Logs each element of the iterator to stderr for debugging, then passes the value on.&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;        .&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;inspect&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;|&lt;&#x2F;span&gt;&lt;span&gt;entry&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;|&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;            if let&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Err&lt;&#x2F;span&gt;&lt;span&gt;(e)&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; entry {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;                eprintln!&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt;&amp;quot;Error: {}&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;, e);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        })&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;        .&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;filter_map&lt;&#x2F;span&gt;&lt;span&gt;(Result&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span&gt;ok)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;        .&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;map&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;|&lt;&#x2F;span&gt;&lt;span&gt;entry&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;|&lt;&#x2F;span&gt;&lt;span&gt; entry&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;path&lt;&#x2F;span&gt;&lt;span&gt;())&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;        .&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;filter&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;|&lt;&#x2F;span&gt;&lt;span&gt;path&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;|&lt;&#x2F;span&gt;&lt;span&gt; path&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;extension&lt;&#x2F;span&gt;&lt;span&gt;()&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; ==&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Some&lt;&#x2F;span&gt;&lt;span&gt;(OsStr&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;new&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt;&amp;quot;xml&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;)))&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;        .&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;collect&lt;&#x2F;span&gt;&lt;span&gt;();&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;    Ok&lt;&#x2F;span&gt;&lt;span&gt;(entries)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;(&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;play.rust-lang.org&#x2F;?version=stable&amp;amp;mode=debug&amp;amp;edition=2021&amp;amp;gist=f3bd287c8c82ff661b9ec9616b5514a9&quot;&gt;Rust Playground&lt;&#x2F;a&gt;)&lt;&#x2F;p&gt;
&lt;p&gt;So far, I would still lean towards the functional version, but let’s see
how both approaches hold up as we add more complexity.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;making-filtering-more-generic&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#making-filtering-more-generic&quot; aria-label=&quot;Anchor link for: making-filtering-more-generic&quot;&gt;Making Filtering More Generic&lt;&#x2F;a&gt;&lt;&#x2F;h3&gt;
&lt;p&gt;What if we wanted to filter by arbitrary file attributes?
For instance, we might want to find all files with a given prefix or extension.&lt;&#x2F;p&gt;
&lt;p&gt;We could introduce a new parameter, &lt;code&gt;valid&lt;&#x2F;code&gt;, which would be a function that
takes a &lt;code&gt;Path&lt;&#x2F;code&gt; and returns a &lt;code&gt;bool&lt;&#x2F;code&gt;. (This is also known as a &lt;em&gt;predicate&lt;&#x2F;em&gt; in
functional programming.)&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;fn&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; filter_files&lt;&#x2F;span&gt;&lt;span&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;F&lt;&#x2F;span&gt;&lt;span&gt;&amp;gt;(p&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;: &amp;amp;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;Path&lt;&#x2F;span&gt;&lt;span&gt;, valid&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;: &amp;amp;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;F&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; -&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Result&lt;&#x2F;span&gt;&lt;span&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;Vec&lt;&#x2F;span&gt;&lt;span&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;PathBuf&lt;&#x2F;span&gt;&lt;span&gt;&amp;gt;&amp;gt;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;where&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;    F&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; Fn&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;&amp;amp;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;Path&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; -&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; bool&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;{&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;    Ok&lt;&#x2F;span&gt;&lt;span&gt;(fs&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;read_dir&lt;&#x2F;span&gt;&lt;span&gt;(p)&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;?&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;        .&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;filter_map&lt;&#x2F;span&gt;&lt;span&gt;(Result&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span&gt;ok)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;        .&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;map&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;|&lt;&#x2F;span&gt;&lt;span&gt;entry&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;|&lt;&#x2F;span&gt;&lt;span&gt; entry&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;path&lt;&#x2F;span&gt;&lt;span&gt;())&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;        .&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;filter&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;|&lt;&#x2F;span&gt;&lt;span&gt;path&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;|&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; valid&lt;&#x2F;span&gt;&lt;span&gt;(path))&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;        .&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;collect&lt;&#x2F;span&gt;&lt;span&gt;())&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;This is a generic function that can be used for many different use cases.
Higher-order functions like this are a typical pattern in functional programming
and are also available in Rust.&lt;&#x2F;p&gt;
&lt;p&gt;The imperative version, while concise, now incorporates a higher-order function,
demonstrating that the line between functional and imperative programming is
often blurry:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;fn&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; filter_files&lt;&#x2F;span&gt;&lt;span&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;F&lt;&#x2F;span&gt;&lt;span&gt;&amp;gt;(p&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;: &amp;amp;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;Path&lt;&#x2F;span&gt;&lt;span&gt;, valid&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;: &amp;amp;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;F&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; -&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Result&lt;&#x2F;span&gt;&lt;span&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;Vec&lt;&#x2F;span&gt;&lt;span&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;PathBuf&lt;&#x2F;span&gt;&lt;span&gt;&amp;gt;&amp;gt; &lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;where&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;    F&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; Fn&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;&amp;amp;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;Path&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; -&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; bool&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;{&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    let mut&lt;&#x2F;span&gt;&lt;span&gt; files&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Vec&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;new&lt;&#x2F;span&gt;&lt;span&gt;();&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    for&lt;&#x2F;span&gt;&lt;span&gt; f&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; in&lt;&#x2F;span&gt;&lt;span&gt; fs&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;read_dir&lt;&#x2F;span&gt;&lt;span&gt;(p)&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;?&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;        let&lt;&#x2F;span&gt;&lt;span&gt; f&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; f&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;?&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;        if&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; valid&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;&amp;amp;&lt;&#x2F;span&gt;&lt;span&gt;f&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;path&lt;&#x2F;span&gt;&lt;span&gt;()) {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            files&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;push&lt;&#x2F;span&gt;&lt;span&gt;(f&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;path&lt;&#x2F;span&gt;&lt;span&gt;());&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;    Ok&lt;&#x2F;span&gt;&lt;span&gt;(files)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;(&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;play.rust-lang.org&#x2F;?version=stable&amp;amp;mode=debug&amp;amp;edition=2021&amp;amp;gist=d89eb67e614ad324de56b7d94204dc7f&quot;&gt;Rust Playground&lt;&#x2F;a&gt;)&lt;&#x2F;p&gt;
&lt;h3 id=&quot;recursively-filtering-directories-for-files&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#recursively-filtering-directories-for-files&quot; aria-label=&quot;Anchor link for: recursively-filtering-directories-for-files&quot;&gt;Recursively Filtering Directories For Files&lt;&#x2F;a&gt;&lt;&#x2F;h3&gt;
&lt;p&gt;Let’s go one more step further.&lt;&#x2F;p&gt;
&lt;p&gt;So far, our solution only works for a single directory. What if we wanted to
&lt;em&gt;recursively&lt;&#x2F;em&gt; filter a directory and all its subdirectories for files?&lt;&#x2F;p&gt;
&lt;p&gt;First, the (mostly) imperative version with mutable state:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;fn&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; filter_files&lt;&#x2F;span&gt;&lt;span&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;F&lt;&#x2F;span&gt;&lt;span&gt;&amp;gt;(p&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;: &amp;amp;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;Path&lt;&#x2F;span&gt;&lt;span&gt;, valid&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;: &amp;amp;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;F&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; -&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Result&lt;&#x2F;span&gt;&lt;span&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;Vec&lt;&#x2F;span&gt;&lt;span&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;PathBuf&lt;&#x2F;span&gt;&lt;span&gt;&amp;gt;&amp;gt;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;where&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;    F&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; Fn&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;&amp;amp;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;Path&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; -&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; bool&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;{&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    let mut&lt;&#x2F;span&gt;&lt;span&gt; files&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Vec&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;new&lt;&#x2F;span&gt;&lt;span&gt;();&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    for&lt;&#x2F;span&gt;&lt;span&gt; f&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; in&lt;&#x2F;span&gt;&lt;span&gt; fs&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;read_dir&lt;&#x2F;span&gt;&lt;span&gt;(p)&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;?&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;        let&lt;&#x2F;span&gt;&lt;span&gt; f&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; f&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;?&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;        if&lt;&#x2F;span&gt;&lt;span&gt; f&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;path&lt;&#x2F;span&gt;&lt;span&gt;()&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;is_dir&lt;&#x2F;span&gt;&lt;span&gt;() {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;            &#x2F;&#x2F; Recursively filter the directory&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            files&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;extend&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;filter_files&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;&amp;amp;&lt;&#x2F;span&gt;&lt;span&gt;f&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;path&lt;&#x2F;span&gt;&lt;span&gt;(), valid)&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;?&lt;&#x2F;span&gt;&lt;span&gt;);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        }&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; else if&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; valid&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;&amp;amp;&lt;&#x2F;span&gt;&lt;span&gt;f&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;path&lt;&#x2F;span&gt;&lt;span&gt;()) {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            files&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;push&lt;&#x2F;span&gt;&lt;span&gt;(f&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;path&lt;&#x2F;span&gt;&lt;span&gt;());&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;    Ok&lt;&#x2F;span&gt;&lt;span&gt;(files)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;(&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;play.rust-lang.org&#x2F;?version=stable&amp;amp;mode=debug&amp;amp;edition=2021&amp;amp;gist=e55738f928e70d9f42e2408e10166e1e&quot;&gt;Rust Playground&lt;&#x2F;a&gt;)&lt;&#x2F;p&gt;
&lt;p&gt;While we have one more level of nesting, the imperative version holds up
reasonably well.&lt;&#x2F;p&gt;
&lt;p&gt;Next, the functional version:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;fn&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; filter_files&lt;&#x2F;span&gt;&lt;span&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;F&lt;&#x2F;span&gt;&lt;span&gt;&amp;gt;(p&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;: &amp;amp;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;Path&lt;&#x2F;span&gt;&lt;span&gt;, valid&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;: &amp;amp;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;F&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; -&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Result&lt;&#x2F;span&gt;&lt;span&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;Vec&lt;&#x2F;span&gt;&lt;span&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;PathBuf&lt;&#x2F;span&gt;&lt;span&gt;&amp;gt;&amp;gt;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;where&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;    F&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; Fn&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;&amp;amp;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;Path&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; -&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; bool&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;{&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;    Ok&lt;&#x2F;span&gt;&lt;span&gt;(fs&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;read_dir&lt;&#x2F;span&gt;&lt;span&gt;(p)&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;?&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;        .&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;filter_map&lt;&#x2F;span&gt;&lt;span&gt;(Result&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span&gt;ok)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;        .&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;map&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;|&lt;&#x2F;span&gt;&lt;span&gt;entry&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;|&lt;&#x2F;span&gt;&lt;span&gt; entry&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;path&lt;&#x2F;span&gt;&lt;span&gt;())&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;        .&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;flat_map&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;|&lt;&#x2F;span&gt;&lt;span&gt;path&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;| match&lt;&#x2F;span&gt;&lt;span&gt; path {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            p&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; if&lt;&#x2F;span&gt;&lt;span&gt; p&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;is_dir&lt;&#x2F;span&gt;&lt;span&gt;()&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; filter_files&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;&amp;amp;&lt;&#x2F;span&gt;&lt;span&gt;p, valid)&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;unwrap_or_default&lt;&#x2F;span&gt;&lt;span&gt;(),&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            p&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; if&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; valid&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;&amp;amp;&lt;&#x2F;span&gt;&lt;span&gt;p)&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; vec!&lt;&#x2F;span&gt;&lt;span&gt;[p],&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            _&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; vec!&lt;&#x2F;span&gt;&lt;span&gt;[],&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        })&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;        .&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;collect&lt;&#x2F;span&gt;&lt;span&gt;())&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;We’re dealing with an iterator of iterators here, so we need to flatten it to
get a single iterator of paths with the help of &lt;code&gt;flat_map&lt;&#x2F;code&gt;. However, this also
means that we need to return a vector of paths in all cases, even if it’s empty.
The &lt;code&gt;unwrap_or_default&lt;&#x2F;code&gt; is a symptom of this.&lt;&#x2F;p&gt;
&lt;p&gt;I will let you be the judge of which version you prefer.&lt;&#x2F;p&gt;
&lt;p&gt;Either way, this is where I feel the flow of logic is in need of improvement.
What I want is better encapsulation and modularity to keep
the complexity in check. Rust allows us to seamlessly transition to an
object-oriented style to do just that.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;transitioning-to-object-oriented-rust&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#transitioning-to-object-oriented-rust&quot; aria-label=&quot;Anchor link for: transitioning-to-object-oriented-rust&quot;&gt;Transitioning to Object-Oriented Rust&lt;&#x2F;a&gt;&lt;&#x2F;h3&gt;
&lt;p&gt;In contrast to the functional and imperative examples discussed earlier,
let’s introduce a new struct, &lt;code&gt;FileFilter&lt;&#x2F;code&gt;, which encapsulates the logic for
filtering files and file iteration.&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;pub struct&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; FileFilter&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    predicates&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Vec&lt;&#x2F;span&gt;&lt;span&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;Box&lt;&#x2F;span&gt;&lt;span&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;Predicate&lt;&#x2F;span&gt;&lt;span&gt;&amp;gt;&amp;gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    start&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Option&lt;&#x2F;span&gt;&lt;span&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;PathBuf&lt;&#x2F;span&gt;&lt;span&gt;&amp;gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    stack&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Vec&lt;&#x2F;span&gt;&lt;span&gt;&amp;lt;fs&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;ReadDir&lt;&#x2F;span&gt;&lt;span&gt;&amp;gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Each &lt;code&gt;FileFilter&lt;&#x2F;code&gt; object carries its state: a collection of predicates for
filtering, a starting path, and a stack of directories for iteration.&lt;&#x2F;p&gt;
&lt;p&gt;A predicate is defined like this:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;type&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Predicate&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; = dyn&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; Fn&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;&amp;amp;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;Path&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; -&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; bool&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;You might be surprised to see a &lt;code&gt;dyn&lt;&#x2F;code&gt; here.
In Rust, no two closures, even if identical, have the same type!&lt;&#x2F;p&gt;
&lt;blockquote&gt;
&lt;p&gt;A closure expression produces a closure value with a unique, anonymous type
that cannot be written out. - &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;doc.rust-lang.org&#x2F;reference&#x2F;types&#x2F;closure.html&quot;&gt;The Rust Reference&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
&lt;p&gt;To accommodate this in a collection like a Vec, we use a trait object with
&lt;em&gt;dynamic dispatch&lt;&#x2F;em&gt;. By ‘boxing’ these closures, we create a &lt;code&gt;Box&amp;lt;Predicate&amp;gt;&lt;&#x2F;code&gt;
(essentially &lt;code&gt;Box&amp;lt;dyn Fn(&amp;amp;Path) -&amp;gt; bool&amp;gt;&lt;&#x2F;code&gt;), which allows us to store different
predicate closures in the same &lt;code&gt;Vec&lt;&#x2F;code&gt; despite their unique types.&lt;&#x2F;p&gt;
&lt;h4 id=&quot;adding-filters&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#adding-filters&quot; aria-label=&quot;Anchor link for: adding-filters&quot;&gt;Adding Filters&lt;&#x2F;a&gt;&lt;&#x2F;h4&gt;
&lt;p&gt;In functional programming, we leveraged the power of iterators and closures to
filter files. In the imperative style, we directly manipulated vectors with
loops and conditions. The FileFilter, however, abstracts these details away.&lt;&#x2F;p&gt;
&lt;p&gt;Consider the &lt;code&gt;add_filter&lt;&#x2F;code&gt; method:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;pub fn&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; add_filter&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;mut&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;font-style: italic;&quot;&gt; self&lt;&#x2F;span&gt;&lt;span&gt;, predicate&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;: impl&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; Fn&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;&amp;amp;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;Path&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; -&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; bool&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; +&lt;&#x2F;span&gt;&lt;span&gt; &amp;#39;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;static&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; -&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;font-style: italic;&quot;&gt; Self&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #BD93F9;font-style: italic;&quot;&gt;    self&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span&gt;predicates&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;push&lt;&#x2F;span&gt;&lt;span&gt;(Box&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;new&lt;&#x2F;span&gt;&lt;span&gt;(predicate));&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #BD93F9;font-style: italic;&quot;&gt;    self&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;This allows us to easily add multiple filters by chaining calls —
something that was previously closely coupled with the iteration logic.&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;let&lt;&#x2F;span&gt;&lt;span&gt; filter&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; FileFilter&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;new&lt;&#x2F;span&gt;&lt;span&gt;()&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    .&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;add_filter&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;|&lt;&#x2F;span&gt;&lt;span&gt;path&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;|&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;        &#x2F;&#x2F; check if path begins with &amp;quot;foo&amp;quot;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        path&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;file_name&lt;&#x2F;span&gt;&lt;span&gt;()&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;            .&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;and_then&lt;&#x2F;span&gt;&lt;span&gt;(OsStr&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span&gt;to_str)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;            .&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;map&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;|&lt;&#x2F;span&gt;&lt;span&gt;name&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;|&lt;&#x2F;span&gt;&lt;span&gt; name&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;starts_with&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt;&amp;quot;foo&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;))&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;            .&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;unwrap_or&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt;false&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    })  &lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    .&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;add_filter&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;|&lt;&#x2F;span&gt;&lt;span&gt;path&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;|&lt;&#x2F;span&gt;&lt;span&gt; path&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;extension&lt;&#x2F;span&gt;&lt;span&gt;()&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; ==&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Some&lt;&#x2F;span&gt;&lt;span&gt;(OsStr&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;new&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt;&amp;quot;xml&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;)));&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;&lt;h4 id=&quot;iterator-implementation&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#iterator-implementation&quot; aria-label=&quot;Anchor link for: iterator-implementation&quot;&gt;Iterator Implementation&lt;&#x2F;a&gt;&lt;&#x2F;h4&gt;
&lt;p&gt;What truly showcases the OOP approach in Rust is the implementation of the
&lt;code&gt;Iterator&lt;&#x2F;code&gt; trait for &lt;code&gt;FileFilter&lt;&#x2F;code&gt;:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;impl&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Iterator&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; for&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; FileFilter&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    type&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Item&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Result&lt;&#x2F;span&gt;&lt;span&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;PathBuf&lt;&#x2F;span&gt;&lt;span&gt;&amp;gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    fn&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; next&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;&amp;amp;mut&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;font-style: italic;&quot;&gt; self&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; -&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Option&lt;&#x2F;span&gt;&lt;span&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;font-style: italic;&quot;&gt;Self&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;Item&lt;&#x2F;span&gt;&lt;span&gt;&amp;gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;        &#x2F;&#x2F; Iteration logic to filter entries.&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;        &#x2F;&#x2F; This is outside the scope of this article&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;        &#x2F;&#x2F; Check out the full implementation on GitHub&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;        &#x2F;&#x2F; or on the Rust Playground&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;In doing so, &lt;code&gt;FileFilter&lt;&#x2F;code&gt; becomes a building block that neatly integrates
with Rust’s powerful iterator ecosystem and can be used in all the same places
as any other iterator. This design allows for complex iteration logic to be
encapsulated
&lt;em&gt;within&lt;&#x2F;em&gt; the object, abstracting away the details from the user.&lt;&#x2F;p&gt;
&lt;p&gt;You can find the full implementation of &lt;code&gt;FileFilter&lt;&#x2F;code&gt; &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;corrode&#x2F;filefilter&quot;&gt;on
GitHub&lt;&#x2F;a&gt; or &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;play.rust-lang.org&#x2F;?version=stable&amp;amp;mode=debug&amp;amp;edition=2021&amp;amp;gist=d0b5ce70c858b39151ca46cf9dc07369&quot;&gt;on the Rust
Playground&lt;&#x2F;a&gt;.
The code was closely modeled after the excellent
&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;BurntSushi&#x2F;walkdir&quot;&gt;Walkdir&lt;&#x2F;a&gt; crate, which I recommend for
production use.&lt;&#x2F;p&gt;
&lt;h4 id=&quot;encapsulation-and-reusability&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#encapsulation-and-reusability&quot; aria-label=&quot;Anchor link for: encapsulation-and-reusability&quot;&gt;Encapsulation and Reusability&lt;&#x2F;a&gt;&lt;&#x2F;h4&gt;
&lt;p&gt;The &lt;code&gt;FileFilter&lt;&#x2F;code&gt; example illustrates how OOP in Rust can lead to solid
encapsulation and modularity. Unlike the earlier examples where the logic for
filtering files was tightly coupled with iteration, we now separate
the &lt;em&gt;what&lt;&#x2F;em&gt; (the predicates) from the &lt;em&gt;how&lt;&#x2F;em&gt; (the iteration and filtering logic).
The trait system allows us to easily integrate our custom iterator with the
rest of the ecosystem.
Having these tools at our disposal makes the code more composable and reusable.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;summary&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#summary&quot; aria-label=&quot;Anchor link for: summary&quot;&gt;Summary&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;p&gt;Mixing different styles is not only possible, but encouraged in Rust! This can
also be seen by taking a look at &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;doc.rust-lang.org&#x2F;reference&#x2F;influences.html&quot;&gt;Rust’s key influences on its language
design&lt;&#x2F;a&gt;. Influences as
diverse as C++, Haskell, OCaml, and Erlang have shaped Rust’s design.&lt;&#x2F;p&gt;
&lt;p&gt;In the beginning, Rust was more functional in nature, but it has since evolved
into a more balanced language, supporting a variety of styles. The question is
where to draw the line between different programming paradigms.&lt;&#x2F;p&gt;
&lt;p&gt;I found that I often use a functional core with an imperative shell. The core
consists of small, composable functions that transform data, while the shell
provides the necessary control flow. I often use object-oriented constructs to
organize larger parts of my application, encapsulating related data and
functions.&lt;&#x2F;p&gt;
&lt;p&gt;Here are my personal rules of thumb:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Embrace object-oriented patterns for organization.&lt;&#x2F;strong&gt; For organizing larger
parts of your application, consider object-oriented constructs. Using structs or enums can encapsulate related data and functions, providing a clear structure without worrying about the details.&lt;&#x2F;p&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Leverage functional patterns for data transformations.&lt;&#x2F;strong&gt; Especially within
smaller scopes like functions and closures, functional methods such as
mapping, filtering, or reducing can make your code both concise and clear.
Use functional programming when you can phrase your problem as a series of transformations over some data.&lt;&#x2F;p&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Use imperative style for granular control.&lt;&#x2F;strong&gt; In scenarios where you’re
working close to the hardware, or when you need explicit step-by-step
execution, the imperative style is often a necessity. It allows for precise
control over operations, especially with mutable data. This style can be
particularly useful in performance-critical sections or when interfacing with
external systems where exact sequencing matters. However, always weigh its
performance gains against potential readability trade-offs. If possible,
encapsulate imperative code within a limited scope.&lt;&#x2F;p&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Prioritize readability and maintainability.&lt;&#x2F;strong&gt; Regardless of your chosen
paradigm, always write code that’s straightforward and easy to maintain. It
benefits not only your future self, but also your colleagues who might work on
the same codebase.&lt;&#x2F;p&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Avoid premature optimization.&lt;&#x2F;strong&gt; Don’t prematurely optimize for performance
at the cost of readability. The real bottleneck might be elsewhere. Measure
first, then optimize. Elegant solutions can be turned into fast ones, but
the reverse is not always true.&lt;&#x2F;p&gt;
&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;Lastly, avoid bias towards any particular paradigm. You can write better code if
you test your assumptions every now and then.&lt;&#x2F;p&gt;
</description>
      </item>
      <item>
          <title>Aim For Immutability in Rust</title>
          <pubDate>Thu, 21 Sep 2023 00:00:00 +0000</pubDate>
          <author>Matthias Endler</author>
          <link>https://corrode.dev/blog/immutability/</link>
          <guid>https://corrode.dev/blog/immutability/</guid>
          <description xml:base="https://corrode.dev/blog/immutability/">&lt;p&gt;Some Rustaceans go to great lengths to avoid copying data — even once.&lt;&#x2F;p&gt;
&lt;p&gt;This is typically noticeable among those with a background in systems
programming, who are deeply conscious of performance and memory usage, sometimes
to the detriment of code readability. They make heavy use of &lt;code&gt;mut&lt;&#x2F;code&gt; to mutate
data in place and frequently try to sidestep &lt;code&gt;.clone()&lt;&#x2F;code&gt; calls at every turn in
an attempt to (prematurely) optimize their code.&lt;&#x2F;p&gt;
&lt;p&gt;I believe this approach is misguided. Immutability — which means once something
is created, it can’t be changed — results in code that is easier to
understand, refactor and parallelize and it doesn’t have to be slow either.&lt;&#x2F;p&gt;
&lt;p&gt;Immutability is an incredible complexity killer.&lt;&#x2F;p&gt;
&lt;blockquote&gt;
&lt;p&gt;Mutable objects are the new spaghetti code. And by that, I mean that you, eventually, with mutable objects, create an intractable mess. And encapsulation does not get rid of that. Encapsulation just means: well, I am in charge of this mess. But the real mess comes from this network that you create of objects that can change, and your inability to look at the state of a system and understand how it got there, how to get it there to test it next time. So it is hard to understand a program where things can change out from underneath you.
— &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;matthiasn&#x2F;talk-transcripts&#x2F;blob&#x2F;master&#x2F;Hickey_Rich&#x2F;ClojureConcurrency.md&quot;&gt;Rick Hickey&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
&lt;p&gt;The &lt;code&gt;mut&lt;&#x2F;code&gt; keyword should be used sparingly; preferably only in tight scopes.&lt;&#x2F;p&gt;
&lt;p&gt;This article aims to convince you that &lt;strong&gt;embracing immutability is central to
writing idiomatic Rust&lt;&#x2F;strong&gt;.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;immutability-and-state&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#immutability-and-state&quot; aria-label=&quot;Anchor link for: immutability-and-state&quot;&gt;Immutability and State&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;p&gt;As programmers, we think a lot about state.&lt;&#x2F;p&gt;
&lt;p&gt;The problem is, that humans are pretty bad at keeping track of state transitions
and multiple moving parts.
(That is, unless you’re a chess grandmaster or the parent of a toddler, of course.)&lt;&#x2F;p&gt;
&lt;blockquote&gt;
&lt;p&gt;A large fraction of the flaws in software development are due to programmers
not fully understanding all the possible states their code may execute in.&lt;br &#x2F;&gt;
— &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;http:&#x2F;&#x2F;www.sevangelatos.com&#x2F;john-carmack-on&#x2F;&quot;&gt;John Carmack&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
&lt;p&gt;Immutability can help us reduce the cognitive load of keeping track of state.
Instead of having to keep track of all the ways in which a variable can change,
we know that it can’t change at all.&lt;&#x2F;p&gt;
&lt;p&gt;This brings us to Rust, a language that has chosen to prioritize immutability.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;why-did-rust-choose-immutability-by-default&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#why-did-rust-choose-immutability-by-default&quot; aria-label=&quot;Anchor link for: why-did-rust-choose-immutability-by-default&quot;&gt;Why Did Rust Choose Immutability By Default?&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;p&gt;In Rust, variables are immutable by default, which means that once a
variable is bound to a value, it cannot be changed
(unless you &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;stackoverflow.com&#x2F;a&#x2F;54242058&#x2F;270334&quot;&gt;try excruciatingly hard to shoot yourself in the foot&lt;&#x2F;a&gt;).&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;let&lt;&#x2F;span&gt;&lt;span&gt; x&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt; 42&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;x&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt; 23&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt; &#x2F;&#x2F; error: re-assignment of immutable variable `x`&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Especially C and C++ programmers &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;users.rust-lang.org&#x2F;t&#x2F;is-immutability-by-default-worth-the-hassle&#x2F;83668&quot;&gt;tend to be surprised by that design
decision&lt;&#x2F;a&gt;
and their first Rust programs typically contain a lot of &lt;code&gt;mut&lt;&#x2F;code&gt; keywords.&lt;&#x2F;p&gt;
&lt;p&gt;In my opinion, choosing immutability was a good decision, because it helps
reduce mental overhead. It is a nod to &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;doc.rust-lang.org&#x2F;reference&#x2F;influences.html&quot;&gt;Rust’s functional
roots&lt;&#x2F;a&gt; and a consequence of
its focus on safety.&lt;&#x2F;p&gt;
&lt;p&gt;If the default was mutability, you’d have to check every
function to see if it changes the value of a variable.&lt;&#x2F;p&gt;
&lt;p&gt;Instead, Rust is very explicit about mutability.
It makes you write it out every time you create or pass a mutable variable.&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;fn&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; main&lt;&#x2F;span&gt;&lt;span&gt;() {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    let mut&lt;&#x2F;span&gt;&lt;span&gt; x&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt; 42&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;    black_box&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;&amp;amp;mut&lt;&#x2F;span&gt;&lt;span&gt; x);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;    println!&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt;&amp;quot;{}&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;, x);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;fn&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; black_box&lt;&#x2F;span&gt;&lt;span&gt;(x&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;: &amp;amp;mut&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; i32&lt;&#x2F;span&gt;&lt;span&gt;) {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    *&lt;&#x2F;span&gt;&lt;span&gt;x&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt; 23&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Oh, how awfully, painfully explicit!&lt;&#x2F;p&gt;
&lt;p&gt;Warning signs all over the place, which indicate that we are leaking state
changes to the outside world.&lt;&#x2F;p&gt;
&lt;p&gt;Compare that to C++:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;cpp&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;#include&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E9F284;&quot;&gt; &amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt;iostream&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E9F284;&quot;&gt;&amp;gt;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;void&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; black_box&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;int*&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FFB86C;font-style: italic;&quot;&gt; x&lt;&#x2F;span&gt;&lt;span&gt;) {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    *&lt;&#x2F;span&gt;&lt;span&gt;x &lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;=&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt; 23&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;int&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; main&lt;&#x2F;span&gt;&lt;span&gt;() {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    int&lt;&#x2F;span&gt;&lt;span&gt; x &lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;=&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt; 42&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;    black_box&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;&amp;amp;&lt;&#x2F;span&gt;&lt;span&gt;x);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    std&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span&gt;cout &lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;&amp;lt;&amp;lt;&lt;&#x2F;span&gt;&lt;span&gt; x &lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;&amp;lt;&amp;lt;&lt;&#x2F;span&gt;&lt;span&gt; std&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span&gt;endl;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Here we have to read the function body to see if it modifies our
variable. We need to use the &lt;code&gt;const&lt;&#x2F;code&gt; keyword in C++ to indicate that a pointer
shouldn’t modify the data it points to.&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;cpp&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;void&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; black_box&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;const int*&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FFB86C;font-style: italic;&quot;&gt; x&lt;&#x2F;span&gt;&lt;span&gt;) {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;    &#x2F;&#x2F; This would be an error&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;    &#x2F;&#x2F; *x = 23;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;This is somewhat analogous to Rust’s immutability, &lt;em&gt;but it is opt-in in C++&lt;&#x2F;em&gt;,
meaning you have to remember to use it.&lt;&#x2F;p&gt;
&lt;p&gt;In Rust, explicit mutability is part of the function signature, which makes it
easier to understand the implications of that function call at a glance. It even
warns you if something is mutable, but needn’t be!&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;fn&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; main&lt;&#x2F;span&gt;&lt;span&gt;() {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    let mut&lt;&#x2F;span&gt;&lt;span&gt; x&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt; 42&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;    black_box&lt;&#x2F;span&gt;&lt;span&gt;(x);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;warning&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span&gt; variable does not need to be mutable&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; --&amp;gt;&lt;&#x2F;span&gt;&lt;span&gt; src&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;&#x2F;&lt;&#x2F;span&gt;&lt;span&gt;main&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span&gt;rs&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt;4&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt;9&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;  |&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt;4&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; |     let mut&lt;&#x2F;span&gt;&lt;span&gt; x&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt; 42&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;  |         ----^&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;  |         |&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;  |&lt;&#x2F;span&gt;&lt;span&gt;         help&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span&gt; remove this `&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;mut&lt;&#x2F;span&gt;&lt;span&gt;`&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;  |&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;  =&lt;&#x2F;span&gt;&lt;span&gt; note&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span&gt; `#[warn(unused_mut)]` on by default&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Rust’s immutability-by-default is not just a syntactic choice; it’s a deliberate
decision to promote code clarity and safety. By requiring explicit mutability,
Rust ensures developers are acutely aware of its implications. Especially in
concurrent programming, where mutable states can introduce complexity, this can be a lifesaver.&lt;&#x2F;p&gt;
&lt;p&gt;Mutability means state: a thing can be in one of many states. Immutability means no state: the thing won’t change.
That’s why immutability is a good default: most of the time you don’t need all that state in the first place.&lt;&#x2F;p&gt;
&lt;p&gt;The real-world implications of immutability can be less straightforward.
Let’s explore a concrete example to illustrate how an immutable approach can impact our design decisions for the better.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;side-note-function-signatures&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#side-note-function-signatures&quot; aria-label=&quot;Anchor link for: side-note-function-signatures&quot;&gt;Side Note: Function Signatures&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;p&gt;In Rust, function signatures are very explicit about what a function does.
For instance, what is the difference between these two function signatures?&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;fn&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; my_function1&lt;&#x2F;span&gt;&lt;span&gt;(a&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;: &amp;amp;mut&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; T&lt;&#x2F;span&gt;&lt;span&gt;) {&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; ...&lt;&#x2F;span&gt;&lt;span&gt; }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;fn&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; my_function2&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;mut&lt;&#x2F;span&gt;&lt;span&gt; a&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;: &amp;amp;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;T&lt;&#x2F;span&gt;&lt;span&gt;) {&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; ...&lt;&#x2F;span&gt;&lt;span&gt; }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;The first function takes an immutable reference to a mutable value.
This means that the value being pointed to can be modified through the reference, but the reference itself cannot be reassigned.&lt;&#x2F;p&gt;
&lt;p&gt;The second function takes a mutable binding to an immutable reference.
This means that the binding &lt;code&gt;a&lt;&#x2F;code&gt; can be reassigned to point to different values, but cannot modify any value it points to.&lt;&#x2F;p&gt;
&lt;p&gt;The difference is subtle, but it goes to show how Rust makes you think about mutability in a very explicit way.&lt;&#x2F;p&gt;
&lt;p&gt;You would typically use the first form (&lt;code&gt;a: &amp;amp;mut T&lt;&#x2F;code&gt;) when you need to modify the original value in place, like updating a struct’s fields or modifying an element in a data structure.
The second form (&lt;code&gt;mut a: &amp;amp;T&lt;&#x2F;code&gt;) is less common and is used when you need to temporarily point to different values within a function, like when comparing multiple values or iterating through a collection of references.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;controlling-mutability&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#controlling-mutability&quot; aria-label=&quot;Anchor link for: controlling-mutability&quot;&gt;Controlling Mutability&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;p&gt;Consider the following (problematic) implementation of a &lt;code&gt;Mailbox&lt;&#x2F;code&gt;:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;pub struct&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Mailbox&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;    &#x2F;&#x2F;&#x2F; The emails in the mailbox&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;    &#x2F;&#x2F; Obviously, don&amp;#39;t represent emails as strings in real code!&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;    &#x2F;&#x2F; Use higher-level abstractions instead.&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    emails&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Vec&lt;&#x2F;span&gt;&lt;span&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;String&lt;&#x2F;span&gt;&lt;span&gt;&amp;gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;    &#x2F;&#x2F;&#x2F; The total number of words in all emails&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    total_word_count&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; usize&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;impl&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Mailbox&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    pub fn&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; new&lt;&#x2F;span&gt;&lt;span&gt;()&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; -&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;font-style: italic;&quot;&gt; Self&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;        Mailbox&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            emails&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Vec&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;new&lt;&#x2F;span&gt;&lt;span&gt;(),&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            total_word_count&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt; 0&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    pub fn&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; add_email&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;&amp;amp;mut&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;font-style: italic;&quot;&gt; self&lt;&#x2F;span&gt;&lt;span&gt;, email&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;: &amp;amp;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;str&lt;&#x2F;span&gt;&lt;span&gt;) {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #BD93F9;font-style: italic;&quot;&gt;        self&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span&gt;emails&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;push&lt;&#x2F;span&gt;&lt;span&gt;(email&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;to_string&lt;&#x2F;span&gt;&lt;span&gt;());&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;        &#x2F;&#x2F; Misguided optimization: Track the total word count&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;        let&lt;&#x2F;span&gt;&lt;span&gt; word_count&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; usize&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; email&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;split_whitespace&lt;&#x2F;span&gt;&lt;span&gt;()&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;count&lt;&#x2F;span&gt;&lt;span&gt;();&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #BD93F9;font-style: italic;&quot;&gt;        self&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span&gt;total_word_count &lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;+=&lt;&#x2F;span&gt;&lt;span&gt; word_count;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    pub fn&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; get_word_count&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;&amp;amp;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;font-style: italic;&quot;&gt;self&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; -&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; usize&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #BD93F9;font-style: italic;&quot;&gt;        self&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span&gt;total_word_count&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;    &#x2F;&#x2F; ... other methods ...&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;&lt;div class=&quot;info&quot;&gt;
  
  &lt;div class=&quot;info-header&quot;&gt;
    
      &lt;span class=&quot;icon icon-info&quot;&gt;&lt;&#x2F;span&gt;
    
    &lt;h4&gt;&lt;p&gt;Note&lt;&#x2F;p&gt;
&lt;&#x2F;h4&gt;
  &lt;&#x2F;div&gt;
  
  &lt;p&gt;This is a contrived example and not idiomatic Rust code!
In a real-world scenario, we should use better abstractions, such as a &lt;code&gt;Message&lt;&#x2F;code&gt;
struct of some sort, which encapsulates the email’s content and metadata, but
bear with me for the sake of the argument.&lt;&#x2F;p&gt;

&lt;&#x2F;div&gt;
&lt;p&gt;Note how &lt;code&gt;add_email&lt;&#x2F;code&gt; takes a &lt;code&gt;&amp;amp;mut self&lt;&#x2F;code&gt;, changing both the &lt;code&gt;emails&lt;&#x2F;code&gt; and
&lt;code&gt;total_word_count&lt;&#x2F;code&gt; fields.&lt;&#x2F;p&gt;
&lt;p&gt;The idea here was to optimize for performance by keeping track of the total word
count on insertion, so that we don’t have to iterate over all emails every time
we want to get the word count later.
In what may have been a well-intentioned effort to optimize, &lt;code&gt;emails&lt;&#x2F;code&gt; and
&lt;code&gt;total_word_count&lt;&#x2F;code&gt; have now become tightly coupled.
We might refactor the code and forget to update the &lt;code&gt;total_word_count&lt;&#x2F;code&gt; field, causing bugs!&lt;&#x2F;p&gt;
&lt;h2 id=&quot;immutability-in-purely-functional-programming&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#immutability-in-purely-functional-programming&quot; aria-label=&quot;Anchor link for: immutability-in-purely-functional-programming&quot;&gt;Immutability In Purely Functional Programming&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;p&gt;Issues with mutable state are less prevalent in purely functional programming
languages. For example, Haskell &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;wiki.haskell.org&#x2F;Mutable_variable&quot;&gt;doesn’t even have mutable variables except when
using the state monad&lt;&#x2F;a&gt;. Therefore,
our naive &lt;code&gt;Mailbox&lt;&#x2F;code&gt; type might look like this in Haskell:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;haskell&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;newtype&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Mailbox&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt; Mailbox&lt;&#x2F;span&gt;&lt;span&gt; [&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;String&lt;&#x2F;span&gt;&lt;span&gt;]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;addEmail&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; ::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Mailbox&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; -&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; String&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; -&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Mailbox&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;addEmail (&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt;Mailbox&lt;&#x2F;span&gt;&lt;span&gt; emails) email &lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;=&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt; Mailbox&lt;&#x2F;span&gt;&lt;span&gt; (email &lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span&gt; emails)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;getWordCount&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; ::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Mailbox&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; -&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Int&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;getWordCount (&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt;Mailbox&lt;&#x2F;span&gt;&lt;span&gt; emails)&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; sum &lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;$&lt;&#x2F;span&gt;&lt;span&gt; map (length &lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span&gt; words) emails&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;This returns a new &lt;code&gt;Mailbox&lt;&#x2F;code&gt; every time we add a message.&lt;&#x2F;p&gt;
&lt;p&gt;To the keen-eyed systems programmer, this might sound appalling: “A fresh
Mailbox for each email? Really?” But before entirely dismissing that idea, remember that
in purely functional languages like Haskell, such practices are quite common
because they are quite efficient:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;In the &lt;code&gt;addEmail&lt;&#x2F;code&gt; function, you’re prepending an email to the list with the
&lt;code&gt;:&lt;&#x2F;code&gt; operator. Prepending to a linked list in Haskell is an &lt;code&gt;O(1)&lt;&#x2F;code&gt; operation,
so it’s quite performant.&lt;&#x2F;li&gt;
&lt;li&gt;While we’re returning a new &lt;code&gt;Mailbox&lt;&#x2F;code&gt;, Haskell’s lazy evaluation and the way
it handles memory can mitigate some of the potential inefficiencies. For
instance, unchanged parts of a data structure might be shared between the old
and new versions.&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.reddit.com&#x2F;r&#x2F;haskell&#x2F;comments&#x2F;w25rj7&#x2F;how_does_haskell_internally_represent_lists&#x2F;igpurex&#x2F;&quot;&gt;Linked lists in Haskell are similar to “streams” in other languages&lt;&#x2F;a&gt;,
which helps put the performance expectations into perspective.&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;The functional approach pushed us towards a better design, because it made it
obvious that we don’t need the &lt;code&gt;totalWordCount&lt;&#x2F;code&gt; field at all:
It was much easier to write a version which calculates the sum on the fly
instead of mutating state.&lt;&#x2F;p&gt;
&lt;p&gt;The code is a lot easier to reason about and it might not even be slower. While
lazy evaluation has many advantages, its main drawback is that &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;wiki.haskell.org&#x2F;Lazy_evaluation&quot;&gt;memory usage
becomes hard to predict&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;Which brings us back to Rust.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;rust-s-pragmatic-approach-to-mutability&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#rust-s-pragmatic-approach-to-mutability&quot; aria-label=&quot;Anchor link for: rust-s-pragmatic-approach-to-mutability&quot;&gt;Rust’s Pragmatic Approach To Mutability&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;p&gt;Rust does not have lazy evaluation, in part due to its focus on predictable
runtime behavior and its commitment to zero-cost abstractions. Thus, we can’t
rely on the same optimizations as in languages that support lazy evaluation.&lt;&#x2F;p&gt;
&lt;p&gt;Instead, many Rust developers would probably opt for a middle ground:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;pub struct&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Mailbox&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    emails&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Vec&lt;&#x2F;span&gt;&lt;span&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;String&lt;&#x2F;span&gt;&lt;span&gt;&amp;gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;impl&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Mailbox&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    pub fn&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; new&lt;&#x2F;span&gt;&lt;span&gt;()&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; -&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;font-style: italic;&quot;&gt; Self&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;        Mailbox&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            emails&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Vec&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;new&lt;&#x2F;span&gt;&lt;span&gt;(),&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    pub fn&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; add_email&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;&amp;amp;mut&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;font-style: italic;&quot;&gt; self&lt;&#x2F;span&gt;&lt;span&gt;, email&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;: &amp;amp;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;str&lt;&#x2F;span&gt;&lt;span&gt;) {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #BD93F9;font-style: italic;&quot;&gt;        self&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span&gt;emails&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;push&lt;&#x2F;span&gt;&lt;span&gt;(email&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;to_string&lt;&#x2F;span&gt;&lt;span&gt;());&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    pub fn&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; get_word_count&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;&amp;amp;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;font-style: italic;&quot;&gt;self&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; -&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; usize&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #BD93F9;font-style: italic;&quot;&gt;        self&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span&gt;emails&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;            .&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;iter&lt;&#x2F;span&gt;&lt;span&gt;()&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;            &#x2F;&#x2F; In real code, `email` might have a `body` field with a&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;            &#x2F;&#x2F; `word_count()` method instead&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;            .&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;map&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;|&lt;&#x2F;span&gt;&lt;span&gt;email&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;|&lt;&#x2F;span&gt;&lt;span&gt; email&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;split_whitespace&lt;&#x2F;span&gt;&lt;span&gt;()&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;count&lt;&#x2F;span&gt;&lt;span&gt;())&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;            .&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;sum&lt;&#x2F;span&gt;&lt;span&gt;()&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;    &#x2F;&#x2F; ... other methods ...&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;We mutate the original &lt;code&gt;Mailbox&lt;&#x2F;code&gt;, while now avoiding the &lt;code&gt;total_word_count&lt;&#x2F;code&gt;
field from the original code.
We don’t carry the extra state around, and we calculate the word count on the
fly when needed.&lt;&#x2F;p&gt;
&lt;p&gt;The compiler prevents multiple
mutable references to the same data, making this approach safe.&lt;&#x2F;p&gt;
&lt;p&gt;Our Haskell example wasn’t a mere detour; it highlighted how an immutable
mindset can often lead to stronger application design, even outside purely
functional contexts. We should strive to embrace immutability in Rust as well.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;a-word-on-performance&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#a-word-on-performance&quot; aria-label=&quot;Anchor link for: a-word-on-performance&quot;&gt;A Word On Performance&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;p&gt;In case counting the words becomes expensive, an alternative would be to
refactor the the code such that &lt;code&gt;add_email&lt;&#x2F;code&gt; takes a &lt;code&gt;Mail&lt;&#x2F;code&gt; struct, which contains
the metadata:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;pub struct&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Mail&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    body&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; String&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;    &#x2F;&#x2F; Cache word count for faster access&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    word_count&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; usize&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;impl&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Mail&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    pub fn&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; new&lt;&#x2F;span&gt;&lt;span&gt;(body&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;: &amp;amp;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;str&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; -&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;font-style: italic;&quot;&gt; Self&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;        Mail&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            body&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span&gt; body&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;to_string&lt;&#x2F;span&gt;&lt;span&gt;(),&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            word_count&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span&gt; body&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;split_whitespace&lt;&#x2F;span&gt;&lt;span&gt;()&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;count&lt;&#x2F;span&gt;&lt;span&gt;(),&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    pub fn&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; word_count&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;&amp;amp;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;font-style: italic;&quot;&gt;self&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; -&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; usize&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #BD93F9;font-style: italic;&quot;&gt;        self&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span&gt;word_count&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Then our &lt;code&gt;get_word_count&lt;&#x2F;code&gt; method could look like this:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;pub fn&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; get_word_count&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;&amp;amp;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;font-style: italic;&quot;&gt;self&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; -&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; usize&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #BD93F9;font-style: italic;&quot;&gt;    self&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span&gt;emails&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;iter&lt;&#x2F;span&gt;&lt;span&gt;()&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;map&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;|&lt;&#x2F;span&gt;&lt;span&gt;email&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;|&lt;&#x2F;span&gt;&lt;span&gt; email&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;word_count&lt;&#x2F;span&gt;&lt;span&gt;())&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;sum&lt;&#x2F;span&gt;&lt;span&gt;()&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Even in this case, we don’t need any mutable state to implement the global word
count. Our intuition should be finding better abstractions, not mutating state.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;summary&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#summary&quot; aria-label=&quot;Anchor link for: summary&quot;&gt;Summary&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;h3 id=&quot;move-instead-of-mut&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#move-instead-of-mut&quot; aria-label=&quot;Anchor link for: move-instead-of-mut&quot;&gt;Move instead of &lt;code&gt;mut&lt;&#x2F;code&gt;&lt;&#x2F;a&gt;&lt;&#x2F;h3&gt;
&lt;p&gt;Lean into Rust’s ownership model to avoid mutable state.&lt;&#x2F;p&gt;
&lt;p&gt;It is safe to move variables into functions and structs, so use that to your
advantage. This way you can avoid &lt;code&gt;mut&lt;&#x2F;code&gt; in many cases and avoid
copies, which is especially important for large data structures.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;don-t-be-afraid-of-copying-data&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#don-t-be-afraid-of-copying-data&quot; aria-label=&quot;Anchor link for: don-t-be-afraid-of-copying-data&quot;&gt;Don’t Be Afraid Of Copying Data.&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;p&gt;If you have the choice between a lot of &lt;code&gt;mut&lt;&#x2F;code&gt; and a few &lt;code&gt;.clone()&lt;&#x2F;code&gt; calls,
copying data is not as expensive as you might think.&lt;&#x2F;p&gt;
&lt;p&gt;As computers get more cores and memory becomes cheaper, the benefits of
immutability outweigh the costs:
especially in distributed systems, synchronization and coordination of
mutable data structures is hard and has a runtime cost.
Immutability can help you avoid a lot of headaches.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;http:&#x2F;&#x2F;xion.io&#x2F;post&#x2F;code&#x2F;rust-borrowchk-tricks.html&quot;&gt;Don’t worry about a few &lt;code&gt;.clone()&lt;&#x2F;code&gt; calls here and there.&lt;&#x2F;a&gt; Instead, write code that is easy to understand and maintain.&lt;&#x2F;p&gt;
&lt;p&gt;The alternative is often to use locks and these have a runtime cost, too.
On top of that, they are a common source of deadlocks.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;immutability-is-a-great-default&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#immutability-is-a-great-default&quot; aria-label=&quot;Anchor link for: immutability-is-a-great-default&quot;&gt;Immutability Is A Great Default&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;p&gt;Immutable code is easier to test, parallelize, and reason about. It’s also
easier to refactor, because you don’t have to worry about side effects.&lt;&#x2F;p&gt;
&lt;p&gt;Where &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;stackoverflow.com&#x2F;a&#x2F;29682542&#x2F;270334&quot;&gt;C&#x2F;C++ requires you to explicitly declare things as immutable&lt;&#x2F;a&gt;, Rust requires you to explicitly declare things as mutable, making everything else immutable by default.&lt;&#x2F;p&gt;
&lt;p&gt;Rust pushes you towards immutability and offers &lt;code&gt;mut&lt;&#x2F;code&gt; as an opt-in escape hatch
for hot paths and tight loops. Many (perhaps most) other languages do the exact
opposite: they use mutability as the default and require you to consciously
choose immutability.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;limit-mutability-to-tight-scopes&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#limit-mutability-to-tight-scopes&quot; aria-label=&quot;Anchor link for: limit-mutability-to-tight-scopes&quot;&gt;Limit Mutability To Tight Scopes&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;p&gt;Good code keeps mutable state short-lived, making it easier to reason about.
The use of &lt;code&gt;mut&lt;&#x2F;code&gt; should be the exception, not the rule.&lt;&#x2F;p&gt;
</description>
      </item>
      <item>
          <title>Compile-Time Invariants in Rust</title>
          <pubDate>Sun, 27 Aug 2023 00:00:00 +0000</pubDate>
          <author>Matthias Endler</author>
          <link>https://corrode.dev/blog/compile-time-invariants/</link>
          <guid>https://corrode.dev/blog/compile-time-invariants/</guid>
          <description xml:base="https://corrode.dev/blog/compile-time-invariants/">&lt;p&gt;Working on something completely unrelated, I stumbled across this comment in a
Rust project:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;&#x2F;&#x2F; TODO: Make sure this has at least one element&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;let&lt;&#x2F;span&gt;&lt;span&gt; kafka_brokers&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; vec!&lt;&#x2F;span&gt;&lt;span&gt;[&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt;&amp;quot;kafka:9092&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt; &amp;quot;kafka2:9092&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;];&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;The intent here was to make sure that there is at least one Kafka broker
(server) to connect to.&lt;&#x2F;p&gt;
&lt;p&gt;Right now, the program would happily compile with an
empty vector. We’d have to add a runtime check to make sure that the vector is not empty:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;fn&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; connect_to_kafka&lt;&#x2F;span&gt;&lt;span&gt;(brokers&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Vec&lt;&#x2F;span&gt;&lt;span&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;&amp;amp;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;str&lt;&#x2F;span&gt;&lt;span&gt;&amp;gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; -&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Result&lt;&#x2F;span&gt;&lt;span&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;KafkaClient&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Box&lt;&#x2F;span&gt;&lt;span&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;dyn&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Error&lt;&#x2F;span&gt;&lt;span&gt;&amp;gt;&amp;gt; { &lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    if&lt;&#x2F;span&gt;&lt;span&gt; brokers&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;is_empty&lt;&#x2F;span&gt;&lt;span&gt;() {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;        return&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Err&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt;&amp;quot;At least one Kafka broker is required&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;    &#x2F;&#x2F; Connect to brokers&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;That’s not great, because we have to remember to validate the vector before
we use it. During refactoring, the check could be accidentally removed, which
would lead to a runtime error.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;wait-there-s-a-crate-for-that&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#wait-there-s-a-crate-for-that&quot; aria-label=&quot;Anchor link for: wait-there-s-a-crate-for-that&quot;&gt;Wait, there’s a crate for that!&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;p&gt;Maybe you know about the &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;rustonaut&#x2F;vec1&quot;&gt;&lt;code&gt;vec1&lt;&#x2F;code&gt;&lt;&#x2F;a&gt; crate,
which provides a &lt;code&gt;Vec1&lt;&#x2F;code&gt; type that can &lt;strong&gt;only&lt;&#x2F;strong&gt; be constructed with &lt;strong&gt;at least&lt;&#x2F;strong&gt;
one element.&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;let&lt;&#x2F;span&gt;&lt;span&gt; kafka_brokers&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; vec1!&lt;&#x2F;span&gt;&lt;span&gt;[&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt;&amp;quot;kafka:9092&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;];&lt;&#x2F;span&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt; &#x2F;&#x2F; works&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;let&lt;&#x2F;span&gt;&lt;span&gt; kafka_brokers&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; vec1!&lt;&#x2F;span&gt;&lt;span&gt;[];&lt;&#x2F;span&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt; &#x2F;&#x2F; compile error&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Now the program would not compile if we tried to use &lt;code&gt;vec1!&lt;&#x2F;code&gt; with zero
elements, which is exactly what we want!&lt;&#x2F;p&gt;
&lt;h2 id=&quot;type-driven-development&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#type-driven-development&quot; aria-label=&quot;Anchor link for: type-driven-development&quot;&gt;Type-driven development&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;p&gt;There’s a deeper lesson here, which applies to idiomatic Rust code in general:&lt;br &#x2F;&gt;
&lt;strong&gt;If in doubt, lean into the type system to enforce invariants at compile-time.&lt;&#x2F;strong&gt;&lt;&#x2F;p&gt;
&lt;p&gt;An invariant is a condition that must always hold true. You want to enforce
these invariants as early as possible.&lt;&#x2F;p&gt;
&lt;p&gt;I recently learned about the term &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;lexi-lambda.github.io&#x2F;blog&#x2F;2019&#x2F;11&#x2F;05&#x2F;parse-don-t-validate&#x2F;&quot;&gt;type-driven
development&lt;&#x2F;a&gt;,
a practice that emphasizes the use of types to ensure program correctness.&lt;&#x2F;p&gt;
&lt;p&gt;To see how it works, let’s try to implement a basic version of &lt;code&gt;vec1&lt;&#x2F;code&gt; ourselves.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;the-vec1-macro&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#the-vec1-macro&quot; aria-label=&quot;Anchor link for: the-vec1-macro&quot;&gt;The &lt;code&gt;vec1&lt;&#x2F;code&gt; macro&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;p&gt;Let’s create a macro that behaves like &lt;code&gt;vec!&lt;&#x2F;code&gt;, but doesn’t allow an empty vector.&lt;&#x2F;p&gt;
&lt;p&gt;The macro handles two cases:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;The first case matches a single element, followed by zero or more elements.&lt;&#x2F;li&gt;
&lt;li&gt;The second case matches an empty vector and will panic at compile-time.&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;#[macro_export]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;macro_rules! vec1&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;    &#x2F;&#x2F; The first element is mandatory, &lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;    &#x2F;&#x2F; while additional elements are optional (denoted by the `*`).&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;    &#x2F;&#x2F; Just like `vec!`, we also allow a trailing comma (denoted by the `?`).&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    [&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;$&lt;&#x2F;span&gt;&lt;span&gt;x&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span&gt;expr&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; $&lt;&#x2F;span&gt;&lt;span&gt;(,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; $&lt;&#x2F;span&gt;&lt;span&gt;xs&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span&gt;expr)&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;* $&lt;&#x2F;span&gt;&lt;span&gt;(,)&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;?&lt;&#x2F;span&gt;&lt;span&gt;]&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&amp;gt;&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;        &#x2F;&#x2F; Just create an ordinary `Vec`&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;        vec!&lt;&#x2F;span&gt;&lt;span&gt;[&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;$&lt;&#x2F;span&gt;&lt;span&gt;x,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; $&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;$&lt;&#x2F;span&gt;&lt;span&gt;xs),&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;*&lt;&#x2F;span&gt;&lt;span&gt;]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    };&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    []&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&amp;gt;&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;        compile_error!&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt;&amp;quot;vec1! requires at least one element&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    };&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;fn&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; main&lt;&#x2F;span&gt;&lt;span&gt;() {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;    &#x2F;&#x2F; This works&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    let&lt;&#x2F;span&gt;&lt;span&gt; _&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; vec1!&lt;&#x2F;span&gt;&lt;span&gt;[&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt;&amp;quot;Hello&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt; &amp;quot;World&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;];&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;    &#x2F;&#x2F; This will fail to compile, which is what we want.&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    let&lt;&#x2F;span&gt;&lt;span&gt; _&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; vec1!&lt;&#x2F;span&gt;&lt;span&gt;[];&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;(&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;play.rust-lang.org&#x2F;?version=stable&amp;amp;mode=debug&amp;amp;edition=2021&amp;amp;gist=6449703583b75ea1a76a763be9a0ba5f&quot;&gt;Rust Playground&lt;&#x2F;a&gt;)&lt;&#x2F;p&gt;
&lt;p&gt;We use &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;doc.rust-lang.org&#x2F;std&#x2F;macro.compile_error.html&quot;&gt;&lt;code&gt;compile_error!&lt;&#x2F;code&gt;&lt;&#x2F;a&gt;,
from the standard library, which will always fail to compile with the given
error message.&lt;&#x2F;p&gt;
&lt;p&gt;This does indeed look like it solves our problem!&lt;br &#x2F;&gt;
However, it only does so superficially.
There’s a nifty bug hiding in disguise.&lt;&#x2F;p&gt;
&lt;p&gt;Since we return an ordinary &lt;code&gt;Vec&lt;&#x2F;code&gt;, the information that there must be at least one element is not a part of the type and the invariant will &lt;em&gt;not&lt;&#x2F;em&gt; be enforced by the type system later on.
We only handle the case where we construct the vector, but not when we use it.&lt;&#x2F;p&gt;
&lt;p&gt;Nothing keeps us from passing an empty vector to a function that requires at least one element. As a result, we would still need our &lt;code&gt;brokers.is_empty()&lt;&#x2F;code&gt; runtime check from above. Dolorous.&lt;&#x2F;p&gt;
&lt;p&gt;All of the hard work was for naught.&lt;&#x2F;p&gt;
&lt;p&gt;But, can we do better?&lt;&#x2F;p&gt;
&lt;h2 id=&quot;second-try-implementing-a-vec1-type&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#second-try-implementing-a-vec1-type&quot; aria-label=&quot;Anchor link for: second-try-implementing-a-vec1-type&quot;&gt;Second Try: Implementing a &lt;code&gt;Vec1&lt;&#x2F;code&gt; type&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;p&gt;The trick is to create a new type, &lt;code&gt;Vec1&lt;&#x2F;code&gt;, that behaves like an ordinary &lt;code&gt;Vec&lt;&#x2F;code&gt;,
but encapsulates the knowledge we just gained about our input.&lt;&#x2F;p&gt;
&lt;p&gt;We do this by using two fields internally, &lt;code&gt;first&lt;&#x2F;code&gt; and &lt;code&gt;rest&lt;&#x2F;code&gt;:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;&#x2F;&#x2F; Note: Fields are not public, so we can enforce &lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;&#x2F;&#x2F; invariants during construction&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;pub struct&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Vec1&lt;&#x2F;span&gt;&lt;span&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;T&lt;&#x2F;span&gt;&lt;span&gt;&amp;gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;    &#x2F;&#x2F; The first element is mandatory&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    first&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; T&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;    &#x2F;&#x2F; The rest is optional&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    rest&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Vec&lt;&#x2F;span&gt;&lt;span&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;T&lt;&#x2F;span&gt;&lt;span&gt;&amp;gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Let’s update our macro to return a &lt;code&gt;Vec1&lt;&#x2F;code&gt; instead of a &lt;code&gt;Vec&lt;&#x2F;code&gt;:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;#[macro_export]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;macro_rules! vec1&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    [&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;$&lt;&#x2F;span&gt;&lt;span&gt;x&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span&gt;expr&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; $&lt;&#x2F;span&gt;&lt;span&gt;(,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; $&lt;&#x2F;span&gt;&lt;span&gt;xs&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span&gt;expr)&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;* $&lt;&#x2F;span&gt;&lt;span&gt;(,)&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;?&lt;&#x2F;span&gt;&lt;span&gt;]&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&amp;gt;&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;        Vec1&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            first&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;: $&lt;&#x2F;span&gt;&lt;span&gt;x,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            rest&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; vec!&lt;&#x2F;span&gt;&lt;span&gt;[&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;$&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;$&lt;&#x2F;span&gt;&lt;span&gt;xs),&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;*&lt;&#x2F;span&gt;&lt;span&gt;],&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    };&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    []&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&amp;gt;&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;        compile_error!&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt;&amp;quot;vec1! requires at least one element&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    };&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;To make our &lt;code&gt;Vec1&lt;&#x2F;code&gt; behave like any ordinary &lt;code&gt;Vec&lt;&#x2F;code&gt;, we can implement the same traits.&lt;&#x2F;p&gt;
&lt;p&gt;For example, we probably want to
&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;doc.rust-lang.org&#x2F;std&#x2F;iter&#x2F;trait.IntoIterator.html&quot;&gt;iterate&lt;&#x2F;a&gt; over the
elements:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;impl&lt;&#x2F;span&gt;&lt;span&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;T&lt;&#x2F;span&gt;&lt;span&gt;&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; IntoIterator&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; for&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Vec1&lt;&#x2F;span&gt;&lt;span&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;T&lt;&#x2F;span&gt;&lt;span&gt;&amp;gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    type&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Item&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; T&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    type&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; IntoIter&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; iter&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;Chain&lt;&#x2F;span&gt;&lt;span&gt;&amp;lt;iter&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;Once&lt;&#x2F;span&gt;&lt;span&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;T&lt;&#x2F;span&gt;&lt;span&gt;&amp;gt;, vec&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;IntoIter&lt;&#x2F;span&gt;&lt;span&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;font-style: italic;&quot;&gt;Self&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;Item&lt;&#x2F;span&gt;&lt;span&gt;&amp;gt;&amp;gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    fn&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; into_iter&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;font-style: italic;&quot;&gt;self&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; -&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;font-style: italic;&quot;&gt; Self&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;IntoIter&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        iter&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;once&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;font-style: italic;&quot;&gt;self&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span&gt;first)&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;chain&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;font-style: italic;&quot;&gt;self&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span&gt;rest)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;The associated &lt;code&gt;IntoIter&lt;&#x2F;code&gt; type is a bit tricky, but it’s just a way to chain
together the first element and the rest of the elements without additional
allocations.&lt;&#x2F;p&gt;
&lt;p&gt;We also want to &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;doc.rust-lang.org&#x2F;std&#x2F;ops&#x2F;trait.Index.html&quot;&gt;index&lt;&#x2F;a&gt; into our &lt;code&gt;Vec1&lt;&#x2F;code&gt;:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;impl&lt;&#x2F;span&gt;&lt;span&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;T&lt;&#x2F;span&gt;&lt;span&gt;&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Index&lt;&#x2F;span&gt;&lt;span&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;usize&lt;&#x2F;span&gt;&lt;span&gt;&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; for&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Vec1&lt;&#x2F;span&gt;&lt;span&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;T&lt;&#x2F;span&gt;&lt;span&gt;&amp;gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    type&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Output&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; T&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    fn&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; index&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;&amp;amp;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;font-style: italic;&quot;&gt;self&lt;&#x2F;span&gt;&lt;span&gt;, index&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; usize&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; -&amp;gt; &amp;amp;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;font-style: italic;&quot;&gt;Self&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;Output&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;        match&lt;&#x2F;span&gt;&lt;span&gt; index {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt;            0&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&amp;gt; &amp;amp;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;font-style: italic;&quot;&gt;self&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span&gt;first,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;            &#x2F;&#x2F; We can use `index - 1` because we know that&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;            &#x2F;&#x2F; `index` is at least 1.&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            i&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&amp;gt; &amp;amp;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;font-style: italic;&quot;&gt;self&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span&gt;rest[i&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; -&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt; 1&lt;&#x2F;span&gt;&lt;span&gt;],&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;To behave &lt;em&gt;exactly&lt;&#x2F;em&gt; like a &lt;code&gt;Vec&lt;&#x2F;code&gt;, we would need to implement &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;doc.rust-lang.org&#x2F;std&#x2F;vec&#x2F;struct.Vec.html#trait-implementations&quot;&gt;a lot more
traits&lt;&#x2F;a&gt;,
but remember that the goal here is to learn about the general pattern of using
types to enforce invariants.&lt;&#x2F;p&gt;
&lt;p&gt;Note that we cannot simply implement &lt;code&gt;Deref&lt;&#x2F;code&gt; and &lt;code&gt;DerefMut&lt;&#x2F;code&gt; to
delegate to the underlying &lt;code&gt;Vec&lt;&#x2F;code&gt;, because that would allow us to mutate the
vector in a way that violates our invariant. Furthermore, we would need a custom
implementation of &lt;code&gt;remove&lt;&#x2F;code&gt; and &lt;code&gt;pop&lt;&#x2F;code&gt; to make sure that the vector is never
empty.&lt;&#x2F;p&gt;
&lt;p&gt;On the other hand, your own types are probably very specific to your use-case,
so you might not need to implement as many traits.&lt;&#x2F;p&gt;
&lt;p&gt;With that, let’s write some tests:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;#[cfg(test)]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;mod&lt;&#x2F;span&gt;&lt;span&gt; tests {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    use&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;font-style: italic;&quot;&gt; super&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::*&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    #[test]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    fn&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; test_single_element&lt;&#x2F;span&gt;&lt;span&gt;() {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;        let&lt;&#x2F;span&gt;&lt;span&gt; v&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; vec1!&lt;&#x2F;span&gt;&lt;span&gt;[&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt;&amp;quot;Hello&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;];&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;        assert_eq!&lt;&#x2F;span&gt;&lt;span&gt;(v[&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt;0&lt;&#x2F;span&gt;&lt;span&gt;],&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt; &amp;quot;Hello&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    #[test]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    fn&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; test_multiple_elements&lt;&#x2F;span&gt;&lt;span&gt;() {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;        let&lt;&#x2F;span&gt;&lt;span&gt; v&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; vec1!&lt;&#x2F;span&gt;&lt;span&gt;[&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt;&amp;quot;Hello&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt; &amp;quot;World&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;];&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;        assert_eq!&lt;&#x2F;span&gt;&lt;span&gt;(v[&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt;0&lt;&#x2F;span&gt;&lt;span&gt;],&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt; &amp;quot;Hello&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;        assert_eq!&lt;&#x2F;span&gt;&lt;span&gt;(v[&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt;1&lt;&#x2F;span&gt;&lt;span&gt;],&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt; &amp;quot;World&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    #[test]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    fn&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; test_other_type&lt;&#x2F;span&gt;&lt;span&gt;() {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;        let&lt;&#x2F;span&gt;&lt;span&gt; _v&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; vec1!&lt;&#x2F;span&gt;&lt;span&gt;[&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt;1&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt;2&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt;3&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt;4&lt;&#x2F;span&gt;&lt;span&gt;];&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;    &#x2F;&#x2F; This won&amp;#39;t compile, which is what we want to enforce the invariant.&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;    &#x2F;&#x2F; Uncommenting the next line will break the compilation.&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;    &#x2F;&#x2F; #[test]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;    &#x2F;&#x2F; fn test_zero_elements() {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;    &#x2F;&#x2F;     let v = vec1![];&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;    &#x2F;&#x2F; }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;We now have a vector with at least one element.
If you want to play around with the code, &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;play.rust-lang.org&#x2F;?version=stable&amp;amp;mode=debug&amp;amp;edition=2021&amp;amp;gist=316d933bfa7bf97eac0f4c8f152d5d61&quot;&gt;here’s a link to the Rust
playground&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;In any real-world scenario, you would probably want to use the &lt;code&gt;vec1&lt;&#x2F;code&gt; crate
instead of rolling your own implementation. And yes, the &lt;code&gt;vec1&lt;&#x2F;code&gt; crate
implements all the necessary traits to make &lt;code&gt;Vec1&lt;&#x2F;code&gt; behave like a &lt;code&gt;Vec&lt;&#x2F;code&gt;
in a similar fashion to what we did above.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;using-a-fixed-size-array&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#using-a-fixed-size-array&quot; aria-label=&quot;Anchor link for: using-a-fixed-size-array&quot;&gt;Using a fixed-size array&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;p&gt;If we assume that the list of Kafka brokers doesn’t change at runtime (a
reasonable assumption, given that it’s a configuration setting) we could also use
a &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;doc.rust-lang.org&#x2F;std&#x2F;primitive.array.html&quot;&gt;fixed-size array&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;By using an array, we can statically allocate the whole collection, which is
more efficient than using a &lt;code&gt;Vec&lt;&#x2F;code&gt; (a dynamically allocated datatype on the heap).&lt;&#x2F;p&gt;
&lt;p&gt;Here is the same code as above, but using an array instead of a &lt;code&gt;Vec&lt;&#x2F;code&gt;.&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;pub struct&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Array1&lt;&#x2F;span&gt;&lt;span&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;T&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; const&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt; N&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; usize&lt;&#x2F;span&gt;&lt;span&gt;&amp;gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    first&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; T&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    rest&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span&gt; [&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;T&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; N&lt;&#x2F;span&gt;&lt;span&gt;],&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;#[macro_export]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;macro_rules! array1&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    [&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;$&lt;&#x2F;span&gt;&lt;span&gt;x&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span&gt;expr&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; $&lt;&#x2F;span&gt;&lt;span&gt;(,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; $&lt;&#x2F;span&gt;&lt;span&gt;xs&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span&gt;expr)&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;* $&lt;&#x2F;span&gt;&lt;span&gt;(,)&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;?&lt;&#x2F;span&gt;&lt;span&gt;]&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&amp;gt;&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;        Array1&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            first&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;: $&lt;&#x2F;span&gt;&lt;span&gt;x,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            rest&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span&gt; [&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;$&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;$&lt;&#x2F;span&gt;&lt;span&gt;xs),&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;*&lt;&#x2F;span&gt;&lt;span&gt;],&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    };&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    []&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&amp;gt;&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;        compile_error!&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt;&amp;quot;array1! requires at least one element&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    };&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Note that the compiler will infer &lt;code&gt;N&lt;&#x2F;code&gt; (the number of elements in &lt;code&gt;rest&lt;&#x2F;code&gt;)
as well as &lt;code&gt;T&lt;&#x2F;code&gt; (the type of elements).&lt;&#x2F;p&gt;
&lt;p&gt;Our trait implementations now expect a &lt;code&gt;const&lt;&#x2F;code&gt; parameter, e.g.:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;impl&lt;&#x2F;span&gt;&lt;span&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;T&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; const&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt; N&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; usize&lt;&#x2F;span&gt;&lt;span&gt;&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Index&lt;&#x2F;span&gt;&lt;span&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;usize&lt;&#x2F;span&gt;&lt;span&gt;&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; for&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Array1&lt;&#x2F;span&gt;&lt;span&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;T&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; N&lt;&#x2F;span&gt;&lt;span&gt;&amp;gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;    &#x2F;&#x2F; contents unchanged&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;The unit tests are the same as before.
&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;play.rust-lang.org&#x2F;?version=stable&amp;amp;mode=debug&amp;amp;edition=2021&amp;amp;gist=88011ae90e333502c352e7a50d21c632&quot;&gt;Here’s the entire code&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;I like the fact that this avoids any runtime overhead,
which can be helpful in memory-constrained environments or in situations
where dynamic allocation is not possible.&lt;&#x2F;p&gt;
&lt;p&gt;It depends on your use-case to decide whether this is a better approach than
using a &lt;code&gt;vec1&lt;&#x2F;code&gt;. It’s fun how all of the guarantees can be enforced without any
runtime overhead, though!&lt;&#x2F;p&gt;
&lt;h2 id=&quot;further-improvements&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#further-improvements&quot; aria-label=&quot;Anchor link for: further-improvements&quot;&gt;Further Improvements&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;p&gt;One could think of a few ways to add more checks. For example, since we know
that Kafka brokers get represented as URLs, we could also enforce that invariant
at compile-time.&lt;&#x2F;p&gt;
&lt;p&gt;Which additional checks you want to add depends on your use-case.
For instance, if Kafka brokers are a central part of your application, you might want to create your own &lt;code&gt;KafkaBroker&lt;&#x2F;code&gt; type that enforce additional invariants.&lt;&#x2F;p&gt;
&lt;p&gt;Here’s a nice general rule of thumb:&lt;&#x2F;p&gt;
&lt;blockquote&gt;
&lt;p&gt;Model your data using the most precise data structure you reasonably can.&lt;br &#x2F;&gt;
— &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;lexi-lambda.github.io&#x2F;about.html&quot;&gt;Alexis King&lt;&#x2F;a&gt; in &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;lexi-lambda.github.io&#x2F;blog&#x2F;2019&#x2F;11&#x2F;05&#x2F;parse-don-t-validate&#x2F;&quot;&gt;Parse, don’t validate&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
&lt;h2 id=&quot;conclusion&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#conclusion&quot; aria-label=&quot;Anchor link for: conclusion&quot;&gt;Conclusion&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;p&gt;Rust has great support for type-driven design, which can guide you towards
robust and idiomatic code to enforce invariants at compile-time.&lt;&#x2F;p&gt;
&lt;p&gt;Always be on the lookout for ways to let the type-system guide you towards
stronger abstractions.&lt;&#x2F;p&gt;
&lt;p&gt;If you liked this, you might also be interested in my previous post on &lt;a href=&quot;&#x2F;blog&#x2F;illegal-state&quot;&gt;making illegal states unrepresentable in Rust&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
</description>
      </item>
      <item>
          <title>Using Enums to Represent State</title>
          <pubDate>Tue, 08 Aug 2023 00:00:00 +0000</pubDate>
          <author>Matthias Endler</author>
          <link>https://corrode.dev/blog/enums/</link>
          <guid>https://corrode.dev/blog/enums/</guid>
          <description xml:base="https://corrode.dev/blog/enums/">&lt;p&gt;Many Rust beginners with a background in systems programming tend to use &lt;code&gt;bool&lt;&#x2F;code&gt;
(or even &lt;code&gt;u8&lt;&#x2F;code&gt; – an 8-bit unsigned integer type) to represent &lt;em&gt;“state”&lt;&#x2F;em&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;For example, how about a &lt;code&gt;bool&lt;&#x2F;code&gt; to indicate whether a user is active or not?&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;struct&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; User&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;    &#x2F;&#x2F; ...&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    active&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; bool&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Initially, this might seem fine, but as your codebase grows,
you’ll find that “active” is not a binary state. There are many
different states that a user can be in. For example, a user
might be suspended or deleted. However, extending the user struct
can get problematic, because other parts of the code might
rely on the fact that &lt;code&gt;active&lt;&#x2F;code&gt; is a &lt;code&gt;bool&lt;&#x2F;code&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;Another problem is that &lt;code&gt;bool&lt;&#x2F;code&gt; is not self-documenting. What does
&lt;code&gt;active = false&lt;&#x2F;code&gt; mean? Is the user inactive? Or is the user
deleted? Or is the user suspended? We don’t know!&lt;&#x2F;p&gt;
&lt;p&gt;Alternatively, you could use an unsigned integer to represent state:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;struct&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; User&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;    &#x2F;&#x2F; ...&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    status&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; u8&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;This is &lt;em&gt;slightly&lt;&#x2F;em&gt; better, because we can now use different values
to represent more states:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;const&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt; ACTIVE&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; u8&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt; 0&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;const&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt; INACTIVE&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; u8&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt; 1&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;const&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt; SUSPENDED&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; u8&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt; 2&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;const&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt; DELETED&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; u8&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt; 3&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;let&lt;&#x2F;span&gt;&lt;span&gt; user&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; User&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;    &#x2F;&#x2F; ...&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    status&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt; ACTIVE&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;};&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;A common use-case for &lt;code&gt;u8&lt;&#x2F;code&gt; is when you interface with C code.
In that case, using &lt;code&gt;u8&lt;&#x2F;code&gt; might seemingly be the only option.
However, we could still wrap that &lt;code&gt;u8&lt;&#x2F;code&gt; in a
&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;doc.rust-lang.org&#x2F;rust-by-example&#x2F;generics&#x2F;new_types.html&quot;&gt;newtype&lt;&#x2F;a&gt;!&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;struct&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; User&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;    &#x2F;&#x2F; ...&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    status&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; UserStatus&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;struct&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; UserStatus&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;u8&lt;&#x2F;span&gt;&lt;span&gt;);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;const&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt; ACTIVE&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; UserStatus&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; UserStatus&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt;0&lt;&#x2F;span&gt;&lt;span&gt;);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;const&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt; INACTIVE&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; UserStatus&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; UserStatus&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt;1&lt;&#x2F;span&gt;&lt;span&gt;);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;const&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt; SUSPENDED&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; UserStatus&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; UserStatus&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt;2&lt;&#x2F;span&gt;&lt;span&gt;);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;const&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt; DELETED&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; UserStatus&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; UserStatus&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt;3&lt;&#x2F;span&gt;&lt;span&gt;);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;let&lt;&#x2F;span&gt;&lt;span&gt; user&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; User&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;    &#x2F;&#x2F; ...&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    status&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt; ACTIVE&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;};&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;This way, we can still use &lt;code&gt;u8&lt;&#x2F;code&gt; to represent state, but we can
now also put the type system to work (a common pattern in idiomatic Rust). For
example, we can define methods on &lt;code&gt;UserStatus&lt;&#x2F;code&gt;:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;impl&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; UserStatus&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    fn&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; is_active&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;&amp;amp;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;font-style: italic;&quot;&gt;self&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; -&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; bool&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #BD93F9;font-style: italic;&quot;&gt;        self&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt;0&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; ==&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt; ACTIVE&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt;0&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;And we can even define a constructor that validates the input:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;impl&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; UserStatus&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    fn&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; new&lt;&#x2F;span&gt;&lt;span&gt;(status&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; u8&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; -&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Result&lt;&#x2F;span&gt;&lt;span&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;font-style: italic;&quot;&gt;Self&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; &amp;amp;&lt;&#x2F;span&gt;&lt;span&gt;&amp;#39;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;static str&lt;&#x2F;span&gt;&lt;span&gt;&amp;gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;        match&lt;&#x2F;span&gt;&lt;span&gt; status {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt;            ACTIVE&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt;0&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Ok&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt;ACTIVE&lt;&#x2F;span&gt;&lt;span&gt;),&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt;            INACTIVE&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt;0&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Ok&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt;INACTIVE&lt;&#x2F;span&gt;&lt;span&gt;),&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt;            SUSPENDED&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt;0&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Ok&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt;SUSPENDED&lt;&#x2F;span&gt;&lt;span&gt;),&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt;            DELETED&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt;0&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Ok&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt;DELETED&lt;&#x2F;span&gt;&lt;span&gt;),&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            _&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Err&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt;&amp;quot;Invalid status&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;),&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;It’s still not ideal, however! Not even if you interface with C code, as we will
see in a bit. But first, let’s look at a common way to represent state in Rust.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;use-enums-instead&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#use-enums-instead&quot; aria-label=&quot;Anchor link for: use-enums-instead&quot;&gt;Use Enums Instead!&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;p&gt;&lt;strong&gt;Enums are a great way to model state inside your domain.&lt;&#x2F;strong&gt; They allow you to
express your intent in a very concise way.&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;#[derive(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;Debug&lt;&#x2F;span&gt;&lt;span&gt;)]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;pub enum&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; UserStatus&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;    &#x2F;&#x2F;&#x2F; The user is active and has full access&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;    &#x2F;&#x2F;&#x2F; to their account and any associated features.&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;    Active&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;    &#x2F;&#x2F;&#x2F; The user&amp;#39;s account is inactive.&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;    &#x2F;&#x2F;&#x2F; This state can be reverted to active by&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;    &#x2F;&#x2F;&#x2F; the user or an administrator.&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;    Inactive&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;    &#x2F;&#x2F;&#x2F; The user&amp;#39;s account has been temporarily suspended, &lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;    &#x2F;&#x2F;&#x2F; possibly due to suspicious activity or policy violations.&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;    &#x2F;&#x2F;&#x2F; During this state, the user cannot access their account,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;    &#x2F;&#x2F;&#x2F; and an administrator&amp;#39;s intervention might&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;    &#x2F;&#x2F;&#x2F; be required to restore the account.&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;    Suspended&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;    &#x2F;&#x2F;&#x2F; The user&amp;#39;s account has been permanently &lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;    &#x2F;&#x2F;&#x2F; deleted and cannot be restored.&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;    &#x2F;&#x2F;&#x2F; All associated data with the account might be &lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;    &#x2F;&#x2F;&#x2F; removed, and the user would need to create a new account&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;    &#x2F;&#x2F;&#x2F; to use the service again.&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;    Deleted&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;We can plug this enum into our &lt;code&gt;User&lt;&#x2F;code&gt; struct:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;struct&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; User&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;    &#x2F;&#x2F; ...&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    status&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; UserStatus&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;But that’s not all; in Rust, enums are much more powerful than in many other
languages. For example, we can add data to our enum variants:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;#[derive(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;Debug&lt;&#x2F;span&gt;&lt;span&gt;)]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;pub enum&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; UserStatus&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;    Active&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;    Inactive&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;    Suspended&lt;&#x2F;span&gt;&lt;span&gt; { until&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; DateTime&lt;&#x2F;span&gt;&lt;span&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;Utc&lt;&#x2F;span&gt;&lt;span&gt;&amp;gt; },&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;    Deleted&lt;&#x2F;span&gt;&lt;span&gt; { deleted_at&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; DateTime&lt;&#x2F;span&gt;&lt;span&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;Utc&lt;&#x2F;span&gt;&lt;span&gt;&amp;gt; },&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;We can then model our &lt;strong&gt;state transitions&lt;&#x2F;strong&gt;:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;use&lt;&#x2F;span&gt;&lt;span&gt; chrono&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span&gt;{&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;DateTime&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Utc&lt;&#x2F;span&gt;&lt;span&gt;};&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;#[derive(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;Debug&lt;&#x2F;span&gt;&lt;span&gt;)]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;pub enum&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; UserStatus&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;    Active&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;    Inactive&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;    Suspended&lt;&#x2F;span&gt;&lt;span&gt; { until&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; DateTime&lt;&#x2F;span&gt;&lt;span&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;Utc&lt;&#x2F;span&gt;&lt;span&gt;&amp;gt; },&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;    Deleted&lt;&#x2F;span&gt;&lt;span&gt; { deleted_at&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; DateTime&lt;&#x2F;span&gt;&lt;span&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;Utc&lt;&#x2F;span&gt;&lt;span&gt;&amp;gt; },&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;impl&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; UserStatus&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;    &#x2F;&#x2F;&#x2F; Suspend the user until the given date.&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    fn&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; suspend&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;&amp;amp;mut&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;font-style: italic;&quot;&gt; self&lt;&#x2F;span&gt;&lt;span&gt;, until&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; DateTime&lt;&#x2F;span&gt;&lt;span&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;Utc&lt;&#x2F;span&gt;&lt;span&gt;&amp;gt;) {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;        match&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;font-style: italic;&quot;&gt; self&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;            UserStatus&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;Active&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&amp;gt; *&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;font-style: italic;&quot;&gt;self&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; UserStatus&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;Suspended&lt;&#x2F;span&gt;&lt;span&gt; { until },&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;            &#x2F;&#x2F; For all non-active states, do nothing.&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            _&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&amp;gt;&lt;&#x2F;span&gt;&lt;span&gt; {}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;    &#x2F;&#x2F;&#x2F; Activate the user.&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    fn&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; activate&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;&amp;amp;mut&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;font-style: italic;&quot;&gt; self&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; -&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Result&lt;&#x2F;span&gt;&lt;span&gt;&amp;lt;(),&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; &amp;amp;&lt;&#x2F;span&gt;&lt;span&gt;&amp;#39;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;static str&lt;&#x2F;span&gt;&lt;span&gt;&amp;gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;        match&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;font-style: italic;&quot;&gt; self&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;            &#x2F;&#x2F; A deleted user can&amp;#39;t be activated!&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;            UserStatus&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;Deleted&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; ..&lt;&#x2F;span&gt;&lt;span&gt; }&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&amp;gt; return&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Err&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt;&amp;quot;can&amp;#39;t activate a deleted user&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;),&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            _&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&amp;gt; *&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;font-style: italic;&quot;&gt;self&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; UserStatus&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;Active&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;        Ok&lt;&#x2F;span&gt;&lt;span&gt;(())&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;    &#x2F;&#x2F;&#x2F; Delete the user. This is a permanent action!&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    fn&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; delete&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;&amp;amp;mut&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;font-style: italic;&quot;&gt; self&lt;&#x2F;span&gt;&lt;span&gt;) {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;        if let&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; UserStatus&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;Deleted&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; ..&lt;&#x2F;span&gt;&lt;span&gt; }&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;font-style: italic;&quot;&gt; self&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;            &#x2F;&#x2F; Already deleted. Don&amp;#39;t set the deleted_at field again.&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;            return&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;        *&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;font-style: italic;&quot;&gt;self&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; UserStatus&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;Deleted&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            deleted_at&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Utc&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;now&lt;&#x2F;span&gt;&lt;span&gt;(),&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    fn&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; is_active&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;&amp;amp;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;font-style: italic;&quot;&gt;self&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; -&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; bool&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;        matches!&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;font-style: italic;&quot;&gt;self&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; UserStatus&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;Active&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    fn&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; is_suspended&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;&amp;amp;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;font-style: italic;&quot;&gt;self&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; -&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; bool&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;        matches!&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;font-style: italic;&quot;&gt;self&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; UserStatus&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;Suspended&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; ..&lt;&#x2F;span&gt;&lt;span&gt; })&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    fn&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; is_deleted&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;&amp;amp;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;font-style: italic;&quot;&gt;self&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; -&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; bool&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;        matches!&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;font-style: italic;&quot;&gt;self&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; UserStatus&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;Deleted&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; ..&lt;&#x2F;span&gt;&lt;span&gt; })&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;#[cfg(test)]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;mod&lt;&#x2F;span&gt;&lt;span&gt; tests {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    use&lt;&#x2F;span&gt;&lt;span&gt; chrono&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;Duration&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    use&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;font-style: italic;&quot;&gt; super&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::*&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    #[test]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    fn&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; test_user_status&lt;&#x2F;span&gt;&lt;span&gt;()&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; -&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Result&lt;&#x2F;span&gt;&lt;span&gt;&amp;lt;(),&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; &amp;amp;&lt;&#x2F;span&gt;&lt;span&gt;&amp;#39;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;static str&lt;&#x2F;span&gt;&lt;span&gt;&amp;gt;{&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;        let mut&lt;&#x2F;span&gt;&lt;span&gt; status&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; UserStatus&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;Active&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;        assert!&lt;&#x2F;span&gt;&lt;span&gt;(status&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;is_active&lt;&#x2F;span&gt;&lt;span&gt;());&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;        &#x2F;&#x2F; Suspend until tomorrow&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        status&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;suspend&lt;&#x2F;span&gt;&lt;span&gt;(Utc&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;now&lt;&#x2F;span&gt;&lt;span&gt;()&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; +&lt;&#x2F;span&gt;&lt;span&gt; Duration&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;days&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt;1&lt;&#x2F;span&gt;&lt;span&gt;));&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;        assert!&lt;&#x2F;span&gt;&lt;span&gt;(status&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;is_suspended&lt;&#x2F;span&gt;&lt;span&gt;());&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        status&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;activate&lt;&#x2F;span&gt;&lt;span&gt;()&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;?&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;        assert!&lt;&#x2F;span&gt;&lt;span&gt;(status&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;is_active&lt;&#x2F;span&gt;&lt;span&gt;());&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        status&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;delete&lt;&#x2F;span&gt;&lt;span&gt;();&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;        assert!&lt;&#x2F;span&gt;&lt;span&gt;(status&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;is_deleted&lt;&#x2F;span&gt;&lt;span&gt;());&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;        Ok&lt;&#x2F;span&gt;&lt;span&gt;(())&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    #[test]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    fn&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; test_user_status_transition&lt;&#x2F;span&gt;&lt;span&gt;() {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;        let mut&lt;&#x2F;span&gt;&lt;span&gt; status&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; UserStatus&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;Active&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;        assert!&lt;&#x2F;span&gt;&lt;span&gt;(status&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;is_active&lt;&#x2F;span&gt;&lt;span&gt;());&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        status&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;delete&lt;&#x2F;span&gt;&lt;span&gt;();&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;        assert!&lt;&#x2F;span&gt;&lt;span&gt;(status&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;is_deleted&lt;&#x2F;span&gt;&lt;span&gt;());&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;        &#x2F;&#x2F; Can&amp;#39;t activate a deleted user&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;        assert!&lt;&#x2F;span&gt;&lt;span&gt;(status&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;activate&lt;&#x2F;span&gt;&lt;span&gt;()&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;is_err&lt;&#x2F;span&gt;&lt;span&gt;());&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;We can extend the application with confidence, knowing that
we can’t attempt to delete a user twice (which might have unwanted side effects
like, say, triggering an expensive cleanup job twice) or re-activate a deleted user.&lt;&#x2F;p&gt;
&lt;p&gt;Out of the box, enums don’t prevent us from making invalid state transitions. We
can still write code that transitions from &lt;code&gt;Active&lt;&#x2F;code&gt; to &lt;code&gt;Suspended&lt;&#x2F;code&gt; without
checking if the user is already suspended. A simple fix is to return a &lt;code&gt;Result&lt;&#x2F;code&gt; from the transition methods (as we did above) to indicate if the transition was successful. This way, we can handle errors gracefully at compile-time without too much ceremony.
It’s a simple and effective way towards &lt;a href=&quot;&#x2F;blog&#x2F;illegal-state&#x2F;&quot;&gt;making illegal states unrepresentable&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;Another often mentioned drawback is that you need pattern matching to handle state transitions.&lt;&#x2F;p&gt;
&lt;p&gt;For example, we wrote this code to suspend a user:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;match&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;font-style: italic;&quot;&gt; self&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;    UserStatus&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;Active&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&amp;gt; *&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;font-style: italic;&quot;&gt;self&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; UserStatus&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;Suspended&lt;&#x2F;span&gt;&lt;span&gt; { until },&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;    &#x2F;&#x2F; For all non-active states, do nothing.&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    _&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&amp;gt;&lt;&#x2F;span&gt;&lt;span&gt; {}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;This can become a bit verbose, especially if you have many state transitions.
In practice, I rarely found this to be a problem, though.
Pattern matching is very ergonomic in Rust, and it’s often the most readable way to describe state transitions. On top of that, the compiler will error if you forget to handle a state transition, which is a strong safety net.&lt;&#x2F;p&gt;
&lt;p&gt;Enums offer another key benefit: efficiency. The compiler optimizes them well, often matching the performance of direct integer use. This makes enums ideal for state machines and performance-critical code.
In our example, the UserStatus enum’s size equals that of its largest variant (plus a small tag) &lt;sup class=&quot;footnote-reference&quot; id=&quot;fr-1-1&quot;&gt;&lt;a href=&quot;#fn-1&quot;&gt;1&lt;&#x2F;a&gt;&lt;&#x2F;sup&gt;&lt;&#x2F;p&gt;
&lt;p&gt;Overall, while not perfect, the simplicity, readability, and memory efficiency of enums often outweigh their drawback in practice.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;using-enums-to-interact-with-c-code&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#using-enums-to-interact-with-c-code&quot; aria-label=&quot;Anchor link for: using-enums-to-interact-with-c-code&quot;&gt;Using Enums to Interact with C Code&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;p&gt;Actually, there’s one more advantage! Earlier, I promised that you can still use enums, even if you have to interact with C code.&lt;&#x2F;p&gt;
&lt;p&gt;Suppose you have a C library with a user status type (I’ve omitted the other
fields for brevity).&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;c&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;typedef struct&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    uint8_t&lt;&#x2F;span&gt;&lt;span&gt; status;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;} User;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;User &lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;*&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;create_user&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;uint8_t&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FFB86C;font-style: italic;&quot;&gt; status&lt;&#x2F;span&gt;&lt;span&gt;);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;You can write a Rust enum to represent the status:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;#[repr(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;u8&lt;&#x2F;span&gt;&lt;span&gt;)]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;#[derive(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;Debug&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; PartialEq&lt;&#x2F;span&gt;&lt;span&gt;)]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;pub enum&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; UserStatus&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;    Active&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt; 0&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;    Inactive&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;    Suspended&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;    Deleted&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;impl&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; TryFrom&lt;&#x2F;span&gt;&lt;span&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;u8&lt;&#x2F;span&gt;&lt;span&gt;&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; for&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; UserStatus&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    type&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Error&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; ();&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    fn&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; try_from&lt;&#x2F;span&gt;&lt;span&gt;(value&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; u8&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; -&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Result&lt;&#x2F;span&gt;&lt;span&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;font-style: italic;&quot;&gt;Self&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;font-style: italic;&quot;&gt; Self&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;Error&lt;&#x2F;span&gt;&lt;span&gt;&amp;gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;        match&lt;&#x2F;span&gt;&lt;span&gt; value {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt;            0&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Ok&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;UserStatus&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;Active&lt;&#x2F;span&gt;&lt;span&gt;),&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt;            1&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Ok&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;UserStatus&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;Inactive&lt;&#x2F;span&gt;&lt;span&gt;),&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt;            2&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Ok&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;UserStatus&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;Suspended&lt;&#x2F;span&gt;&lt;span&gt;),&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt;            3&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Ok&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;UserStatus&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;Deleted&lt;&#x2F;span&gt;&lt;span&gt;),&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            _&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Err&lt;&#x2F;span&gt;&lt;span&gt;(()),&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Noticed that &lt;code&gt;#[repr(u8)]&lt;&#x2F;code&gt; attribute? It tells the compiler to represent this
enum as an unsigned 8-bit integer. This is crucial for compatibility with C
code.&lt;&#x2F;p&gt;
&lt;p&gt;Now, let’s wrap that C function in a safe Rust wrapper:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;extern&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt; &amp;quot;C&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    fn&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; create_user&lt;&#x2F;span&gt;&lt;span&gt;(status&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; u8&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; -&amp;gt; *mut&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; User&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;pub fn&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; create_user_wrapper&lt;&#x2F;span&gt;&lt;span&gt;(status&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; UserStatus&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; -&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Result&lt;&#x2F;span&gt;&lt;span&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;User&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; &amp;amp;&lt;&#x2F;span&gt;&lt;span&gt;&amp;#39;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;static str&lt;&#x2F;span&gt;&lt;span&gt;&amp;gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    let&lt;&#x2F;span&gt;&lt;span&gt; user&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; = unsafe&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; create_user&lt;&#x2F;span&gt;&lt;span&gt;(status&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; as&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; u8&lt;&#x2F;span&gt;&lt;span&gt;) };&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    if&lt;&#x2F;span&gt;&lt;span&gt; user&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;is_null&lt;&#x2F;span&gt;&lt;span&gt;() {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;        Err&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt;&amp;quot;Failed to create user&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    }&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; else&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;        Ok&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;unsafe&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; *&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;Box&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;from_raw&lt;&#x2F;span&gt;&lt;span&gt;(user) })&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;The Rust code now communicates with the C code using a rich enum type, which is both expressive and type-safe.&lt;&#x2F;p&gt;
&lt;p&gt;If you want, you can play around with the code on the &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;play.rust-lang.org&#x2F;?version=stable&amp;amp;mode=debug&amp;amp;edition=2021&amp;amp;gist=8973e5e655c92c725f0b2b00f7830385&quot;&gt;Rust
playground&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;To make these conversions easier, there are crates like
&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;crates.io&#x2F;crates&#x2F;num_enum&quot;&gt;&lt;code&gt;num_enum&lt;&#x2F;code&gt;&lt;&#x2F;a&gt;, which provides great ergonomics
to convert enums to and from primitive types.&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;use&lt;&#x2F;span&gt;&lt;span&gt; num_enum&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;IntoPrimitive&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;#[derive(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;IntoPrimitive&lt;&#x2F;span&gt;&lt;span&gt;)]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;#[repr(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;u8&lt;&#x2F;span&gt;&lt;span&gt;)]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;enum&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Number&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;    Zero&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;    One&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;fn&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; main&lt;&#x2F;span&gt;&lt;span&gt;() {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    let&lt;&#x2F;span&gt;&lt;span&gt; zero&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; u8&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Number&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;Zero&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;into&lt;&#x2F;span&gt;&lt;span&gt;();&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;    assert_eq!&lt;&#x2F;span&gt;&lt;span&gt;(zero,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt; 0&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;u8&lt;&#x2F;span&gt;&lt;span&gt;);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Here, the &lt;code&gt;IntoPrimitive&lt;&#x2F;code&gt; derive macro generates a &lt;code&gt;From&lt;&#x2F;code&gt; implementation for
&lt;code&gt;Number&lt;&#x2F;code&gt; to &lt;code&gt;u8&lt;&#x2F;code&gt;. This makes converting between the enum and the primitive type
as simple as calling &lt;code&gt;into()&lt;&#x2F;code&gt;.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;the-typestate-pattern&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#the-typestate-pattern&quot; aria-label=&quot;Anchor link for: the-typestate-pattern&quot;&gt;The Typestate Pattern&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;p&gt;At this point, many experienced Rust developers would mention another way to safely handle state transitions: the typestate pattern. The idea is pretty neat – encode the state of an object in its type as a generic parameter.
The current state becomes &lt;em&gt;part&lt;&#x2F;em&gt; of your type.&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;&#x2F;&#x2F;&#x2F; Our trait for user states&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;trait&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; UserState&lt;&#x2F;span&gt;&lt;span&gt; {}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;&#x2F;&#x2F;&#x2F; Each state is a separate struct&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;struct&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Active&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;struct&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Inactive&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;struct&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Suspended&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;struct&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Deleted&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;&#x2F;&#x2F;&#x2F; Implement the trait for each state&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;impl&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; UserState&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; for&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Active&lt;&#x2F;span&gt;&lt;span&gt; {}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;impl&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; UserState&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; for&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Inactive&lt;&#x2F;span&gt;&lt;span&gt; {}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;impl&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; UserState&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; for&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Suspended&lt;&#x2F;span&gt;&lt;span&gt; {}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;impl&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; UserState&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; for&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Deleted&lt;&#x2F;span&gt;&lt;span&gt; {}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;&#x2F;&#x2F;&#x2F; The User struct is generic over the state&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;struct&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; User&lt;&#x2F;span&gt;&lt;span&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;S&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; UserState&lt;&#x2F;span&gt;&lt;span&gt;&amp;gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;    &#x2F;&#x2F; Generic over the state&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    id&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; u64&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    name&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; String&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;    &#x2F;&#x2F; The state is encoded in the type&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    state&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; S&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;&#x2F;&#x2F;&#x2F; Implement methods for each state separately&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;&#x2F;&#x2F;&#x2F; Note how the return type changes based on the state.&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;&#x2F;&#x2F;&#x2F; That&amp;#39;s the trick!&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;impl&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; User&lt;&#x2F;span&gt;&lt;span&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;Active&lt;&#x2F;span&gt;&lt;span&gt;&amp;gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    fn&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; suspend&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;font-style: italic;&quot;&gt;self&lt;&#x2F;span&gt;&lt;span&gt;, until&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; DateTime&lt;&#x2F;span&gt;&lt;span&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;Utc&lt;&#x2F;span&gt;&lt;span&gt;&amp;gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; -&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; User&lt;&#x2F;span&gt;&lt;span&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;Suspended&lt;&#x2F;span&gt;&lt;span&gt;&amp;gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;        User&lt;&#x2F;span&gt;&lt;span&gt; { id&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;font-style: italic;&quot;&gt; self&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span&gt;id, name&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;font-style: italic;&quot;&gt; self&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span&gt;name, state&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Suspended&lt;&#x2F;span&gt;&lt;span&gt; }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    fn&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; deactivate&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;font-style: italic;&quot;&gt;self&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; -&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; User&lt;&#x2F;span&gt;&lt;span&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;Inactive&lt;&#x2F;span&gt;&lt;span&gt;&amp;gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;        User&lt;&#x2F;span&gt;&lt;span&gt; { id&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;font-style: italic;&quot;&gt; self&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span&gt;id, name&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;font-style: italic;&quot;&gt; self&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span&gt;name, state&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Inactive&lt;&#x2F;span&gt;&lt;span&gt; }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;impl&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; User&lt;&#x2F;span&gt;&lt;span&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;Inactive&lt;&#x2F;span&gt;&lt;span&gt;&amp;gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    fn&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; activate&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;font-style: italic;&quot;&gt;self&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; -&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; User&lt;&#x2F;span&gt;&lt;span&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;Active&lt;&#x2F;span&gt;&lt;span&gt;&amp;gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;        User&lt;&#x2F;span&gt;&lt;span&gt; { id&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;font-style: italic;&quot;&gt; self&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span&gt;id, name&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;font-style: italic;&quot;&gt; self&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span&gt;name, state&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Active&lt;&#x2F;span&gt;&lt;span&gt; }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;impl&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; User&lt;&#x2F;span&gt;&lt;span&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;Suspended&lt;&#x2F;span&gt;&lt;span&gt;&amp;gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    fn&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; activate&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;font-style: italic;&quot;&gt;self&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; -&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; User&lt;&#x2F;span&gt;&lt;span&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;Active&lt;&#x2F;span&gt;&lt;span&gt;&amp;gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;        User&lt;&#x2F;span&gt;&lt;span&gt; { id&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;font-style: italic;&quot;&gt; self&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span&gt;id, name&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;font-style: italic;&quot;&gt; self&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span&gt;name, state&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Active&lt;&#x2F;span&gt;&lt;span&gt; }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;&#x2F;&#x2F;&#x2F; Deleted users can&amp;#39;t be reactivated or suspended&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;&#x2F;&#x2F;&#x2F; Once we reach this state, the user is gone for good.&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;impl&lt;&#x2F;span&gt;&lt;span&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;S&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; UserState&lt;&#x2F;span&gt;&lt;span&gt;&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; User&lt;&#x2F;span&gt;&lt;span&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;S&lt;&#x2F;span&gt;&lt;span&gt;&amp;gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    fn&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; delete&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;font-style: italic;&quot;&gt;self&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; -&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; User&lt;&#x2F;span&gt;&lt;span&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;Deleted&lt;&#x2F;span&gt;&lt;span&gt;&amp;gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;        User&lt;&#x2F;span&gt;&lt;span&gt; { id&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;font-style: italic;&quot;&gt; self&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span&gt;id, name&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;font-style: italic;&quot;&gt; self&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span&gt;name, state&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Deleted&lt;&#x2F;span&gt;&lt;span&gt; }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;This pattern provides even stronger guarantees than enums, as it makes illegal state transitions impossible at compile-time. For instance, you can’t deactivate a suspended user or reactivate a deleted user even if you wanted to:
there simply isn’t a method for that.&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;fn&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; main&lt;&#x2F;span&gt;&lt;span&gt;() {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    let&lt;&#x2F;span&gt;&lt;span&gt; user&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; User&lt;&#x2F;span&gt;&lt;span&gt; { id&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt; 1&lt;&#x2F;span&gt;&lt;span&gt;, name&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt; &amp;quot;Alice&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;to_string&lt;&#x2F;span&gt;&lt;span&gt;(), state&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Active&lt;&#x2F;span&gt;&lt;span&gt; };&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    let&lt;&#x2F;span&gt;&lt;span&gt; user&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; user&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;suspend&lt;&#x2F;span&gt;&lt;span&gt;(Utc&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;now&lt;&#x2F;span&gt;&lt;span&gt;()&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; +&lt;&#x2F;span&gt;&lt;span&gt; Duration&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;days&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt;1&lt;&#x2F;span&gt;&lt;span&gt;));&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;    &#x2F;&#x2F; Error: no method named `deactivate` found for type `User&amp;lt;Suspended&amp;gt;`&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    user&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;deactivate&lt;&#x2F;span&gt;&lt;span&gt;(); &lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;(You can play around with this code on the &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;play.rust-lang.org&#x2F;?version=stable&amp;amp;mode=debug&amp;amp;edition=2021&amp;amp;gist=ded18a44c5f32d488eb5ea387ddd1eb8&quot;&gt;Rust playground&lt;&#x2F;a&gt;)&lt;&#x2F;p&gt;
&lt;p&gt;However, it’s worth noting that there’s some pushback against overusing the typestate pattern.&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;The additional generic parameter can make the code more complex and harder to understand, especially for developers who aren’t familiar with the pattern.&lt;&#x2F;li&gt;
&lt;li&gt;The documentation and error messages can also be less clear, as the compiler will often mention the generic type parameter and that can distract from the main logic.&lt;&#x2F;li&gt;
&lt;li&gt;When you need to work with collections of items that could be in different states, the typestate pattern could be harder to work with.&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;The last point is often overlooked, so let’s dive into it a bit more.
Say you have a list of users, each in a different state, then you’d need to use a trait object to store them:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;let&lt;&#x2F;span&gt;&lt;span&gt; users&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Vec&lt;&#x2F;span&gt;&lt;span&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;Box&lt;&#x2F;span&gt;&lt;span&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;dyn&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; UserState&lt;&#x2F;span&gt;&lt;span&gt;&amp;gt;&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; vec!&lt;&#x2F;span&gt;&lt;span&gt;[&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;    Box&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;new&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;User&lt;&#x2F;span&gt;&lt;span&gt; { id&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt; 1&lt;&#x2F;span&gt;&lt;span&gt;, name&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt; &amp;quot;Alice&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;to_string&lt;&#x2F;span&gt;&lt;span&gt;(), state&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Active&lt;&#x2F;span&gt;&lt;span&gt; }),&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;    Box&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;new&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;User&lt;&#x2F;span&gt;&lt;span&gt; { id&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt; 2&lt;&#x2F;span&gt;&lt;span&gt;, name&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt; &amp;quot;Bob&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;to_string&lt;&#x2F;span&gt;&lt;span&gt;(), state&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Inactive&lt;&#x2F;span&gt;&lt;span&gt; }),&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;    Box&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;new&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;User&lt;&#x2F;span&gt;&lt;span&gt; { id&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt; 3&lt;&#x2F;span&gt;&lt;span&gt;, name&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt; &amp;quot;Charlie&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;to_string&lt;&#x2F;span&gt;&lt;span&gt;(), state&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Suspended&lt;&#x2F;span&gt;&lt;span&gt; }),&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;];&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;This triggers a heap allocation and dynamic dispatch (the correct method to call is determined at runtime), which is less efficient than the same code using enums, but more importantly, by using trait objects, you’re losing the ability to statically know which specific state each user is in. This means you can’t directly call state-specific methods on the users in the collection without first downcasting again or by using dynamic dispatch.&lt;&#x2F;p&gt;
&lt;p&gt;It can be tempting to verify everything at compile-time, but sometimes the trade-offs aren’t worth it.
I’d recommend using the typestate pattern only when you need the strongest possible compile-time guarantees at the cost of worse developer experience.
For simpler scenarios, enums get you 80% of the way at very little cost.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;conclusion&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#conclusion&quot; aria-label=&quot;Anchor link for: conclusion&quot;&gt;Conclusion&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;p&gt;State management in Rust is more nuanced than in most other languages.&lt;&#x2F;p&gt;
&lt;p&gt;Here’s a quick summary of the different state management approaches in Rust:&lt;&#x2F;p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Simple bool&#x2F;integer&lt;&#x2F;strong&gt;: Easy to understand but prone to errors and not self-documenting.&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Enums&lt;&#x2F;strong&gt;: Provide type-safety and self-documentation, suitable for most cases. They even work well with C code.&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Typestate Pattern&lt;&#x2F;strong&gt;: Offers the strongest compile-time guarantees, ideal for critical systems but can be more verbose.&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;p&gt;Remember, the goal is to write code that is not only correct but also maintainable and understandable by your team.&lt;&#x2F;p&gt;
&lt;p&gt;My recommendation is to use enums whenever you need to represent a set of possible values, like when representing the state of an object. For even stronger guarantees, consider the typestate pattern, especially in safety-critical applications.&lt;&#x2F;p&gt;
&lt;section class=&quot;footnotes&quot;&gt;
&lt;ol class=&quot;footnotes-list&quot;&gt;
&lt;li id=&quot;fn-1&quot;&gt;
&lt;p&gt;In our case, this means that the &lt;code&gt;UserStatus&lt;&#x2F;code&gt; enum is as large as a &lt;code&gt;DateTime&amp;lt;Utc&amp;gt;&lt;&#x2F;code&gt;. &lt;a href=&quot;#fr-1-1&quot;&gt;↩&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;&#x2F;section&gt;
</description>
      </item>
      <item>
          <title>Make Illegal States Unrepresentable</title>
          <pubDate>Sun, 06 Aug 2023 00:00:00 +0000</pubDate>
          <author>Matthias Endler</author>
          <link>https://corrode.dev/blog/illegal-state/</link>
          <guid>https://corrode.dev/blog/illegal-state/</guid>
          <description xml:base="https://corrode.dev/blog/illegal-state/">&lt;p&gt;If you’ve worked with Rust for a while, you’ve probably heard the phrase “making
illegal states unrepresentable”. It’s a phrase that’s often used when people
praise Rust’s type system. But what exactly does it mean? And how can you apply
it to your own code?&lt;&#x2F;p&gt;
&lt;h2 id=&quot;what-is-illegal-state&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#what-is-illegal-state&quot; aria-label=&quot;Anchor link for: what-is-illegal-state&quot;&gt;What is illegal state?&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;p&gt;Imagine we’re writing an application that manages a list of users.&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;struct&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; User&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    username&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; String&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    birthdate&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span&gt; chrono&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;NaiveDate&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Looks simple enough, but is it correct?&lt;&#x2F;p&gt;
&lt;p&gt;What happens if we create a user with an empty username?&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;let&lt;&#x2F;span&gt;&lt;span&gt; user&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; User&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    username&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; String&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;new&lt;&#x2F;span&gt;&lt;span&gt;(),&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    birthdate&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span&gt; chrono&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;NaiveDate&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;from_ymd&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt;1990&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt; 1&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt; 1&lt;&#x2F;span&gt;&lt;span&gt;),&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;};&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Intuitively, we know that this is &lt;strong&gt;not&lt;&#x2F;strong&gt; what we want, but the compiler can’t help us.
We did not give it enough information about usernames.
Already, with this simple example, we managed to introduce illegal state.&lt;&#x2F;p&gt;
&lt;p&gt;Now, how can we fix this?&lt;&#x2F;p&gt;
&lt;h2 id=&quot;the-type-system-is-your-friend&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#the-type-system-is-your-friend&quot; aria-label=&quot;Anchor link for: the-type-system-is-your-friend&quot;&gt;The Type System Is Your Friend&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;p&gt;Consider the &lt;code&gt;String&lt;&#x2F;code&gt; type. It’s a type that represents
an arbitrary sequence of unicode characters. In our case, we need much stricter
constraints. For a start, we want to make sure that the username is &lt;em&gt;not
empty&lt;&#x2F;em&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;One powerful way to model these constraints is through &lt;a href=&quot;&#x2F;blog&#x2F;enums&#x2F;&quot;&gt;enums&lt;&#x2F;a&gt;, which allow you to represent a set of possible values in a type-safe way.&lt;&#x2F;p&gt;
&lt;p&gt;Whenever you’re uncertain how to model something in Rust,
start by defining your basic types — your domain.
That takes some practice, but your code will be much better for it.&lt;&#x2F;p&gt;
&lt;p&gt;In our case, we want to define a type that represents a username.&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;struct&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Username&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;String&lt;&#x2F;span&gt;&lt;span&gt;);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;impl&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Username&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    fn&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; new&lt;&#x2F;span&gt;&lt;span&gt;(username&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; String&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; -&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Result&lt;&#x2F;span&gt;&lt;span&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;font-style: italic;&quot;&gt;Self&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; &amp;amp;&lt;&#x2F;span&gt;&lt;span&gt;&amp;#39;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;static str&lt;&#x2F;span&gt;&lt;span&gt;&amp;gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;        if&lt;&#x2F;span&gt;&lt;span&gt; username&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;is_empty&lt;&#x2F;span&gt;&lt;span&gt;() {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;            return&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Err&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt;&amp;quot;Username cannot be empty&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;        Ok&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;font-style: italic;&quot;&gt;Self&lt;&#x2F;span&gt;&lt;span&gt;(username))&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Note how the constructor now returns a &lt;code&gt;Result&lt;&#x2F;code&gt;.&lt;br &#x2F;&gt;
Also note, that wrapping the &lt;code&gt;String&lt;&#x2F;code&gt; in a struct is a zero-cost abstraction.
The compiler will optimize it away, so there’s no performance penalty!&lt;&#x2F;p&gt;
&lt;p&gt;We can now use this type in our &lt;code&gt;User&lt;&#x2F;code&gt; struct.&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;struct&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; User&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    username&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Username&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    birthdate&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span&gt; chrono&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;NaiveDate&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;See how the compiler now guides us towards idiomatic Rust code?
It’s subtle, but &lt;code&gt;username&lt;&#x2F;code&gt; is now of type &lt;code&gt;Username&lt;&#x2F;code&gt; instead of &lt;code&gt;String&lt;&#x2F;code&gt;.
This means we have much stronger guarantees around our own type as we can’t accidentally create a user with an empty username.
The username has to be constructed before:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;let&lt;&#x2F;span&gt;&lt;span&gt; username&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Username&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;new&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt;&amp;quot;johndoe&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;to_string&lt;&#x2F;span&gt;&lt;span&gt;())&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;?&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;let&lt;&#x2F;span&gt;&lt;span&gt; birthdate&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; NaiveDate&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;from_ymd&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt;1990&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt; 1&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt; 1&lt;&#x2F;span&gt;&lt;span&gt;);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;let&lt;&#x2F;span&gt;&lt;span&gt; user&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; User&lt;&#x2F;span&gt;&lt;span&gt; { username, birthdate };&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;&lt;h2 id=&quot;side-note-how-do-we-get-rid-of-username-new&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#side-note-how-do-we-get-rid-of-username-new&quot; aria-label=&quot;Anchor link for: side-note-how-do-we-get-rid-of-username-new&quot;&gt;Side Note: How do we get rid of &lt;code&gt;Username::new&lt;&#x2F;code&gt;?&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;p&gt;You could implement &lt;code&gt;TryFrom&lt;&#x2F;code&gt;:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;use&lt;&#x2F;span&gt;&lt;span&gt; std&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span&gt;convert&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;TryFrom&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;impl&lt;&#x2F;span&gt;&lt;span&gt;&amp;lt;&amp;#39;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;a&lt;&#x2F;span&gt;&lt;span&gt;&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; TryFrom&lt;&#x2F;span&gt;&lt;span&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;&amp;amp;&lt;&#x2F;span&gt;&lt;span&gt;&amp;#39;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;a str&lt;&#x2F;span&gt;&lt;span&gt;&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; for&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Username&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    type&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Error&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; = &amp;amp;&lt;&#x2F;span&gt;&lt;span&gt;&amp;#39;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;static str&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    fn&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; try_from&lt;&#x2F;span&gt;&lt;span&gt;(value&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;: &amp;amp;&lt;&#x2F;span&gt;&lt;span&gt;&amp;#39;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;a str&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; -&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Result&lt;&#x2F;span&gt;&lt;span&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;font-style: italic;&quot;&gt;Self&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;font-style: italic;&quot;&gt; Self&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;Error&lt;&#x2F;span&gt;&lt;span&gt;&amp;gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #BD93F9;font-style: italic;&quot;&gt;        Self&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;new&lt;&#x2F;span&gt;&lt;span&gt;(value&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;into&lt;&#x2F;span&gt;&lt;span&gt;())&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;let&lt;&#x2F;span&gt;&lt;span&gt; user&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;  User&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    username&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt; &amp;quot;johndoe123&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;try_into&lt;&#x2F;span&gt;&lt;span&gt;()&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;?&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    birthdate&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; NaiveDate&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;from_ymd&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt;1990&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt; 1&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt; 1&lt;&#x2F;span&gt;&lt;span&gt;),&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;};&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;&lt;h2 id=&quot;what-about-the-birthdate&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#what-about-the-birthdate&quot; aria-label=&quot;Anchor link for: what-about-the-birthdate&quot;&gt;What About the Birthdate?&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;p&gt;A new user that is 1000 years old is probably not a valid user.
Let’s add some constraints.&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;use&lt;&#x2F;span&gt;&lt;span&gt; chrono&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;Datelike&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;struct&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Birthdate&lt;&#x2F;span&gt;&lt;span&gt;(chrono&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;NaiveDate&lt;&#x2F;span&gt;&lt;span&gt;);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;impl&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Birthdate&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    fn&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; new&lt;&#x2F;span&gt;&lt;span&gt;(birthdate&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span&gt; chrono&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;NaiveDate&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; -&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Result&lt;&#x2F;span&gt;&lt;span&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;font-style: italic;&quot;&gt;Self&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; &amp;amp;&lt;&#x2F;span&gt;&lt;span&gt;&amp;#39;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;static str&lt;&#x2F;span&gt;&lt;span&gt;&amp;gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;        let&lt;&#x2F;span&gt;&lt;span&gt; today&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; chrono&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;Utc&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;today&lt;&#x2F;span&gt;&lt;span&gt;()&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;naive_utc&lt;&#x2F;span&gt;&lt;span&gt;();&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;        if&lt;&#x2F;span&gt;&lt;span&gt; birthdate&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; &amp;gt;&lt;&#x2F;span&gt;&lt;span&gt; today {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;            return&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Err&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt;&amp;quot;Birthdate cannot be in the future&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;        &#x2F;&#x2F; Note, this age calculation is not 100% accurate, but you get the&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;        &#x2F;&#x2F; idea. Here&amp;#39;s a more robust implementation:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;        &#x2F;&#x2F; https:&#x2F;&#x2F;gist.github.com&#x2F;mre&#x2F;ee7a59491e2aee46d767bd3b5372c5c2&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;        let&lt;&#x2F;span&gt;&lt;span&gt; age&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; today&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;year&lt;&#x2F;span&gt;&lt;span&gt;()&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; -&lt;&#x2F;span&gt;&lt;span&gt; birthdate&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;year&lt;&#x2F;span&gt;&lt;span&gt;();&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;        if&lt;&#x2F;span&gt;&lt;span&gt; age&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; &amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt; 12&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;            return&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Err&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt;&amp;quot;Not old enough to register&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;        if&lt;&#x2F;span&gt;&lt;span&gt; age&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; &amp;gt;=&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt; 150&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;            return&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Err&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt;&amp;quot;How are you not dead yet?&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;        Ok&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;font-style: italic;&quot;&gt;Self&lt;&#x2F;span&gt;&lt;span&gt;(birthdate))&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;#[cfg(test)]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;mod&lt;&#x2F;span&gt;&lt;span&gt; tests {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    use&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;font-style: italic;&quot;&gt; super&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::*&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    use&lt;&#x2F;span&gt;&lt;span&gt; chrono&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;Duration&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    #[test]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    fn&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; test_birthdate&lt;&#x2F;span&gt;&lt;span&gt;() {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;        let&lt;&#x2F;span&gt;&lt;span&gt; today&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; chrono&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;Utc&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;today&lt;&#x2F;span&gt;&lt;span&gt;()&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;naive_utc&lt;&#x2F;span&gt;&lt;span&gt;();&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;        &#x2F;&#x2F; Birthdate cannot be in the future&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;        assert!&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;Birthdate&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;new&lt;&#x2F;span&gt;&lt;span&gt;(today&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; +&lt;&#x2F;span&gt;&lt;span&gt; Duration&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;days&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt;1&lt;&#x2F;span&gt;&lt;span&gt;))&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;is_err&lt;&#x2F;span&gt;&lt;span&gt;());&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;        &#x2F;&#x2F; Excuse me, how old are you?&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;        assert!&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;Birthdate&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;new&lt;&#x2F;span&gt;&lt;span&gt;(today&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; -&lt;&#x2F;span&gt;&lt;span&gt; Duration&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;days&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt;365&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; *&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt; 150&lt;&#x2F;span&gt;&lt;span&gt;))&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;is_err&lt;&#x2F;span&gt;&lt;span&gt;());&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;        &#x2F;&#x2F; Not old enough&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;        assert!&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;Birthdate&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;new&lt;&#x2F;span&gt;&lt;span&gt;(today&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; -&lt;&#x2F;span&gt;&lt;span&gt; Duration&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;days&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt;365&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; *&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt; 11&lt;&#x2F;span&gt;&lt;span&gt;))&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;is_err&lt;&#x2F;span&gt;&lt;span&gt;());&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;        &#x2F;&#x2F; Ok&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;        assert!&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;Birthdate&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;new&lt;&#x2F;span&gt;&lt;span&gt;(today&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; -&lt;&#x2F;span&gt;&lt;span&gt; Duration&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;days&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt;365&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; *&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt; 15&lt;&#x2F;span&gt;&lt;span&gt;))&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;is_ok&lt;&#x2F;span&gt;&lt;span&gt;());&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;No mocking, no complicated setup, testing becomes a breeze.&lt;&#x2F;p&gt;
&lt;p&gt;Our &lt;code&gt;User&lt;&#x2F;code&gt; struct now looks like this:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;struct&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; User&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    username&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Username&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    birthdate&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Birthdate&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;&lt;h2 id=&quot;adding-more-constraints&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#adding-more-constraints&quot; aria-label=&quot;Anchor link for: adding-more-constraints&quot;&gt;Adding More Constraints&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;p&gt;It might sound simple, trivial even, but this is a very powerful technique.
What’s important is that you’re handling errors at the lowest possible level. In
this case, when you create the &lt;code&gt;Username&lt;&#x2F;code&gt; object — and not when you insert it into your database for example.&lt;&#x2F;p&gt;
&lt;p&gt;This will make your code much more robust and easier to reason about, and it’s
quick to add more constraints as you go along. For example, we might want to
make sure that the username is not shorter than 3 characters, not longer than
256 characters, and that it contains only alphanumeric characters or dashes and
underscores:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;struct&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Username&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;String&lt;&#x2F;span&gt;&lt;span&gt;);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;impl&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Username&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;    &#x2F;&#x2F;&#x2F; Represents a user&amp;#39;s login name.&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;    &#x2F;&#x2F;&#x2F;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;    &#x2F;&#x2F;&#x2F; # Errors&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;    &#x2F;&#x2F;&#x2F;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;    &#x2F;&#x2F;&#x2F; Returns an error if&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;    &#x2F;&#x2F;&#x2F; - the username is shorter than 3 characters&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;    &#x2F;&#x2F;&#x2F; - the username is longer than 256 characters&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;    &#x2F;&#x2F;&#x2F; - the username contains characters other than &lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;    &#x2F;&#x2F;&#x2F;   alphanumeric characters, dashes, or underscores&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;    &#x2F;&#x2F;&#x2F;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;    &#x2F;&#x2F;&#x2F; # Examples&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;    &#x2F;&#x2F;&#x2F;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;    &#x2F;&#x2F;&#x2F; ```rust&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;    &#x2F;&#x2F;&#x2F; # use yourcrate::username::Username;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;    &#x2F;&#x2F;&#x2F; assert!(Username::new(&amp;quot;1&amp;quot;.into()).is_err());&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;    &#x2F;&#x2F;&#x2F; assert!(Username::new(&amp;quot;&amp;quot;.into()).is_err());&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;    &#x2F;&#x2F;&#x2F; assert!(Username::new(&amp;quot;user_name-123&amp;quot;.into()).is_ok());&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;    &#x2F;&#x2F;&#x2F; ```&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    fn&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; new&lt;&#x2F;span&gt;&lt;span&gt;(username&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; String&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; -&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Result&lt;&#x2F;span&gt;&lt;span&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;font-style: italic;&quot;&gt;Self&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; &amp;amp;&lt;&#x2F;span&gt;&lt;span&gt;&amp;#39;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;static str&lt;&#x2F;span&gt;&lt;span&gt;&amp;gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;        if&lt;&#x2F;span&gt;&lt;span&gt; username&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;len&lt;&#x2F;span&gt;&lt;span&gt;() &amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt; 3&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;            return&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Err&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt;&amp;quot;username must be at least 3 characters long&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;        if&lt;&#x2F;span&gt;&lt;span&gt; username&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;len&lt;&#x2F;span&gt;&lt;span&gt;() &amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt; 256&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;            return&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Err&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt;&amp;quot;username must not be longer than 256 characters&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;        &#x2F;&#x2F; Note: we use `is_ascii_alphanumeric` instead of `is_alphanumeric`&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;        &#x2F;&#x2F; because we want to restrict usernames to ASCII characters only&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;        &#x2F;&#x2F; and exclude e.g. Chinese ideograms and Arabic-Indic digits.&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;        &#x2F;&#x2F; See https:&#x2F;&#x2F;doc.rust-lang.org&#x2F;std&#x2F;primitive.char.html#method.is_alphanumeric&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;        if&lt;&#x2F;span&gt;&lt;span&gt; username&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;chars&lt;&#x2F;span&gt;&lt;span&gt;()&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;any&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;|&lt;&#x2F;span&gt;&lt;span&gt;c&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;| !&lt;&#x2F;span&gt;&lt;span&gt;c&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;is_ascii_alphanumeric&lt;&#x2F;span&gt;&lt;span&gt;()&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; &amp;amp;&amp;amp;&lt;&#x2F;span&gt;&lt;span&gt; c&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; !=&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt; &amp;#39;-&amp;#39;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; &amp;amp;&amp;amp;&lt;&#x2F;span&gt;&lt;span&gt; c&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; !=&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt; &amp;#39;_&amp;#39;&lt;&#x2F;span&gt;&lt;span&gt;) {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;            return&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Err&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt;&amp;quot;username must only contain alphanumeric characters, dashes, and underscores&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;        Ok&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;font-style: italic;&quot;&gt;Self&lt;&#x2F;span&gt;&lt;span&gt;(username))&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;I’ve added some usage examples, which will be shown in the
documentation of the &lt;code&gt;Username&lt;&#x2F;code&gt; struct. This is a great way to document your
constraints and to show how to use your types! As an added bonus, you can run
these examples as tests with &lt;code&gt;cargo test --doc&lt;&#x2F;code&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;Here’s a link to the code on the &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;play.rust-lang.org&#x2F;?version=stable&amp;amp;mode=debug&amp;amp;edition=2021&amp;amp;gist=2a896bbfa9a25e76ceed2e15159643a8&quot;&gt;Rust Playground&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;does-this-really-prevent-illegal-states&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#does-this-really-prevent-illegal-states&quot; aria-label=&quot;Anchor link for: does-this-really-prevent-illegal-states&quot;&gt;Does This Really Prevent Illegal States?&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;p&gt;The keen reader might have noticed that we could still create invalid objects
manually:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;let&lt;&#x2F;span&gt;&lt;span&gt; username&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; Username&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt;&amp;quot;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;to_string&lt;&#x2F;span&gt;&lt;span&gt;());&lt;&#x2F;span&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt; &#x2F;&#x2F; uh oh&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;In any real-world scenario, we would probably encapsulate our logic in a module
and only expose a constructor function to the outside world:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;mod&lt;&#x2F;span&gt;&lt;span&gt; user {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    pub struct&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Username&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;String&lt;&#x2F;span&gt;&lt;span&gt;);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;    impl&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Username&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;        pub fn&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt; new&lt;&#x2F;span&gt;&lt;span&gt;(username&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; String&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; -&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Result&lt;&#x2F;span&gt;&lt;span&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;font-style: italic;&quot;&gt;Self&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; &amp;amp;&lt;&#x2F;span&gt;&lt;span&gt;&amp;#39;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;static str&lt;&#x2F;span&gt;&lt;span&gt;&amp;gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;            &#x2F;&#x2F; ...&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;If we now tried to create a &lt;code&gt;Username&lt;&#x2F;code&gt; object from the outside, we’d get a
compiler error:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;let&lt;&#x2F;span&gt;&lt;span&gt; username&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; user&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;Username&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt;&amp;quot;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;to_string&lt;&#x2F;span&gt;&lt;span&gt;());&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;error[&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;E0603&lt;&#x2F;span&gt;&lt;span&gt;]&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span&gt; tuple&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; struct&lt;&#x2F;span&gt;&lt;span&gt; constructor `&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;Username&lt;&#x2F;span&gt;&lt;span&gt;` is private&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;  --&amp;gt;&lt;&#x2F;span&gt;&lt;span&gt; src&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;&#x2F;&lt;&#x2F;span&gt;&lt;span&gt;main&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span&gt;rs&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt;45&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt;26&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;   |&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt;2&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;  |     pub struct&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Username&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;String&lt;&#x2F;span&gt;&lt;span&gt;);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;   |                         ------&lt;&#x2F;span&gt;&lt;span&gt; a constructor is private&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; if&lt;&#x2F;span&gt;&lt;span&gt; any of the fields is private&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;With that, the only way to create a &lt;code&gt;Username&lt;&#x2F;code&gt; object is by using our &lt;code&gt;new&lt;&#x2F;code&gt; function:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;let&lt;&#x2F;span&gt;&lt;span&gt; username&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; user&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;Username&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;new&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F1FA8C;&quot;&gt;&amp;quot;mre&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #50FA7B;&quot;&gt;to_string&lt;&#x2F;span&gt;&lt;span&gt;())&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;?&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;&lt;strong&gt;This means, illegal states are avoided for users of our module.&lt;br &#x2F;&gt;
In a way, we only made them “unconstructable”, though.&lt;&#x2F;strong&gt;&lt;&#x2F;p&gt;
&lt;p&gt;If we really wanted, we could model our struct to avoid illegal states at
compile time, but it would be rather tedious to work with.&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #282A36;&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;struct&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; Username&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6272A4;&quot;&gt;    &#x2F;&#x2F; At least 3 characters required&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    prefix&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span&gt; [&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt;char&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BD93F9;&quot;&gt; 3&lt;&#x2F;span&gt;&lt;span&gt;]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    rest&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FF79C6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #8BE9FD;font-style: italic;&quot;&gt; String&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;We get the benefit of compile-time safety, but at the cost of ergonomics.
However, this pattern can be useful in other cases, as we will see in an
&lt;a href=&quot;&#x2F;blog&#x2F;compile-time-invariants&#x2F;&quot;&gt;article about compile-time invariants&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;library-support&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#library-support&quot; aria-label=&quot;Anchor link for: library-support&quot;&gt;Library Support&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;p&gt;I personally prefer to write validation functions as shown above,
but you could consider using a validation library like
&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;crates.io&#x2F;crates&#x2F;validator&quot;&gt;validator&lt;&#x2F;a&gt; instead.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;conclusion&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#conclusion&quot; aria-label=&quot;Anchor link for: conclusion&quot;&gt;Conclusion&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;p&gt;If possible, use self-contained, custom types to model your domain.
It will improve your system design, making it easier to test and reason
about. Handle errors at the lowest possible level (as early as possible).&lt;&#x2F;p&gt;
</description>
      </item>
      <item>
          <title>Why Rust in Production?</title>
          <pubDate>Tue, 01 Aug 2023 00:00:00 +0000</pubDate>
          <author>Matthias Endler</author>
          <link>https://corrode.dev/blog/why-rust/</link>
          <guid>https://corrode.dev/blog/why-rust/</guid>
          <description xml:base="https://corrode.dev/blog/why-rust/">&lt;p&gt;Interest in Rust has surged in recent years, with tech leaders such as
Microsoft, Google, and Amazon coming forward to share their experiences of
leveraging Rust for critical systems.&lt;&#x2F;p&gt;
&lt;p&gt;Much of the dialogue about Rust, however, is still driven by those who have not
leveraged Rust in a significant production capacity or have only done so for
non-critical systems. This results in a skewed understanding of Rust’s
application in production settings, especially for small and medium-sized
businesses, where discussions tend to highlight performance benefits and gloss
over other crucial aspects.&lt;&#x2F;p&gt;
&lt;p&gt;In my role as a Rust consultant, &lt;a href=&quot;&#x2F;podcast&quot;&gt;I have had the opportunity to engage with many
companies, large and small&lt;&#x2F;a&gt;. I found that companies value Rust’s
stability, and long-term maintainability on par with its performance benefits.&lt;&#x2F;p&gt;
&lt;p&gt;This overview distills key insights, offering a resource for businesses to
assess whether Rust is the right tool for their use-case or not.&lt;&#x2F;p&gt;
&lt;p&gt;The intent is to provide an honest look at Rust’s practicality for production
to help decision-makers understand its benefits and challenges.&lt;&#x2F;p&gt;
&lt;div class=&quot;info&quot;&gt;
  
  &lt;div class=&quot;info-header&quot;&gt;
    
      &lt;span class=&quot;icon icon-radio&quot;&gt;&lt;&#x2F;span&gt;
    
    &lt;h4&gt;&lt;p&gt;Streamline Your Decision-Making with Our Compact Audio Guide on Rust&lt;&#x2F;p&gt;
&lt;&#x2F;h4&gt;
  &lt;&#x2F;div&gt;
  
  &lt;p&gt;Considering Rust for your production needs?&lt;br &#x2F;&gt;
You might also want to listen to &lt;a href=&quot;&#x2F;podcast&#x2F;s01e07-season-finale&#x2F;&quot;&gt;this podcast episode of Rust in Production&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;Key Highlights:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;Insights into &lt;a href=&quot;&#x2F;blog&#x2F;hiring-rust-engineers&#x2F;&quot;&gt;hiring Rust engineers&lt;&#x2F;a&gt;.&lt;&#x2F;li&gt;
&lt;li&gt;Tips to &lt;a href=&quot;&#x2F;blog&#x2F;flattening-rusts-learning-curve&#x2F;&quot;&gt;flatten the learning curve&lt;&#x2F;a&gt;.&lt;&#x2F;li&gt;
&lt;li&gt;Effective strategies for &lt;a href=&quot;&#x2F;blog&#x2F;successful-rust-business-adoption-checklist&#x2F;&quot;&gt;Rust adoption&lt;&#x2F;a&gt;.&lt;&#x2F;li&gt;
&lt;li&gt;The significant impact of Rust’s performance on user experience.&lt;&#x2F;li&gt;
&lt;li&gt;And much more.&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;This episode offers a balanced perspective on the advantages and challenges of implementing Rust, supported by real-life experiences and insights from CTOs and lead engineers who have navigated this transition.&lt;&#x2F;p&gt;

&lt;&#x2F;div&gt;
&lt;h2&gt;Table of Contents&lt;&#x2F;h2&gt;
&lt;details class=&quot;toc&quot;&gt;
&lt;summary&gt;
Click here to expand the table of contents.
&lt;&#x2F;summary&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;https:&#x2F;&#x2F;corrode.dev&#x2F;blog&#x2F;why-rust&#x2F;#reasons-for-using-rust-in-production&quot;&gt;Reasons For Using Rust In Production&lt;&#x2F;a&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;https:&#x2F;&#x2F;corrode.dev&#x2F;blog&#x2F;why-rust&#x2F;#reliability-and-stability&quot;&gt;Reliability and Stability&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a href=&quot;https:&#x2F;&#x2F;corrode.dev&#x2F;blog&#x2F;why-rust&#x2F;#maintainability&quot;&gt;Maintainability&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a href=&quot;https:&#x2F;&#x2F;corrode.dev&#x2F;blog&#x2F;why-rust&#x2F;#predictable-runtime-behavior&quot;&gt;Predictable Runtime Behavior&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a href=&quot;https:&#x2F;&#x2F;corrode.dev&#x2F;blog&#x2F;why-rust&#x2F;#cost-savings&quot;&gt;Cost Savings&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a href=&quot;https:&#x2F;&#x2F;corrode.dev&#x2F;blog&#x2F;why-rust&#x2F;#ergonomics&quot;&gt;Ergonomics&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a href=&quot;https:&#x2F;&#x2F;corrode.dev&#x2F;blog&#x2F;why-rust&#x2F;#focus-on-long-term-sustainability&quot;&gt;Focus on Long-Term Sustainability&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a href=&quot;https:&#x2F;&#x2F;corrode.dev&#x2F;blog&#x2F;why-rust&#x2F;#productivity-and-developer-happiness&quot;&gt;Productivity And Developer Happiness&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a href=&quot;https:&#x2F;&#x2F;corrode.dev&#x2F;blog&#x2F;why-rust&#x2F;#performance-and-energy-efficiency&quot;&gt;Performance And Energy Efficiency&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a href=&quot;https:&#x2F;&#x2F;corrode.dev&#x2F;blog&#x2F;why-rust&#x2F;#gradual-adoption-and-ffi&quot;&gt;Gradual Adoption and FFI&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a href=&quot;https:&#x2F;&#x2F;corrode.dev&#x2F;blog&#x2F;why-rust&#x2F;#support-for-a-wide-range-of-environments&quot;&gt;Support for a Wide Range of Environments&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a href=&quot;https:&#x2F;&#x2F;corrode.dev&#x2F;blog&#x2F;why-rust&#x2F;#reasons-against-using-rust-in-production&quot;&gt;Reasons Against Using Rust In Production&lt;&#x2F;a&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;https:&#x2F;&#x2F;corrode.dev&#x2F;blog&#x2F;why-rust&#x2F;#immature-ecosystem&quot;&gt;Immature ecosystem&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a href=&quot;https:&#x2F;&#x2F;corrode.dev&#x2F;blog&#x2F;why-rust&#x2F;#lack-of-developers&quot;&gt;Lack Of Developers&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a href=&quot;https:&#x2F;&#x2F;corrode.dev&#x2F;blog&#x2F;why-rust&#x2F;#tooling&quot;&gt;Tooling&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a href=&quot;https:&#x2F;&#x2F;corrode.dev&#x2F;blog&#x2F;why-rust&#x2F;#learning-curve&quot;&gt;Learning Curve&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a href=&quot;https:&#x2F;&#x2F;corrode.dev&#x2F;blog&#x2F;why-rust&#x2F;#compile-times&quot;&gt;Compile Times&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a href=&quot;https:&#x2F;&#x2F;corrode.dev&#x2F;blog&#x2F;why-rust&#x2F;#conclusion&quot;&gt;Conclusion&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a href=&quot;https:&#x2F;&#x2F;corrode.dev&#x2F;blog&#x2F;why-rust&#x2F;#talks&quot;&gt;Talks&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a href=&quot;https:&#x2F;&#x2F;corrode.dev&#x2F;blog&#x2F;why-rust&#x2F;#next-steps&quot;&gt;Next Steps&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;details&gt;
&lt;h2 id=&quot;reasons-for-using-rust-in-production&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#reasons-for-using-rust-in-production&quot; aria-label=&quot;Anchor link for: reasons-for-using-rust-in-production&quot;&gt;Reasons For Using Rust In Production&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;h3 id=&quot;reliability-and-stability&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#reliability-and-stability&quot; aria-label=&quot;Anchor link for: reliability-and-stability&quot;&gt;Reliability and Stability&lt;&#x2F;a&gt;&lt;&#x2F;h3&gt;
&lt;p&gt;From experience, the majority of companies care less about uncompromising
performance and more about &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;talks.osfc.io&#x2F;osfc2021&#x2F;talk&#x2F;JTWYEH&#x2F;&quot;&gt;reliability and
stability&lt;&#x2F;a&gt; of their services.&lt;&#x2F;p&gt;
&lt;p&gt;This is backed by the &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;cloud.google.com&#x2F;devops&#x2F;state-of-devops&#x2F;&quot;&gt;&lt;em&gt;State of DevOps Report 2023&lt;&#x2F;em&gt;&lt;&#x2F;a&gt;
by Google Cloud, which states:&lt;&#x2F;p&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Reliability unlocks performance.&lt;&#x2F;strong&gt; […]
Strong reliability practices predict better operational performance, team
performance, and organizational performance. […]
Being able to operate the machine effectively allows teams to achieve more,
which allows organizations to thrive. - &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;cloud.google.com&#x2F;devops&#x2F;state-of-devops&#x2F;&quot;&gt;&lt;em&gt;State of DevOps Report 2023&lt;&#x2F;em&gt;&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
&lt;p&gt;More predictable and stable services are easier to maintain and cheaper to
operate. Less time is spent on debugging and on-call, and more time on building
new features. Scaling services is also easier when you know how systems behave
under load.&lt;&#x2F;p&gt;
&lt;blockquote&gt;
&lt;p&gt;Given our small team size, infrastructure reliability is crucial, otherwise,
maintenance starves innovation. Rust provides us with confidence that any code
modification or refactor is likely to produce working programs that will run for
months with minimal supervision. - &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;x.ai&#x2F;&quot;&gt;xAI (formerly Twitter)&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
&lt;p&gt;As another example, the npm registry migrated to Rust in 2019. (See their whitepaper
&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.rust-lang.org&#x2F;static&#x2F;pdfs&#x2F;Rust-npm-Whitepaper.pdf&quot;&gt;here&lt;&#x2F;a&gt;.) As the
largest software registry in the world, it sees upwards of 1.3 billion package
downloads… &lt;em&gt;per day&lt;&#x2F;em&gt;. Npm is critical infrastructure for the JavaScript
ecosystem, and the stability of its services is paramount. This focus on
stability directly impacts the effectiveness and reliability of the entire
JavaScript ecosystem.&lt;&#x2F;p&gt;
&lt;blockquote&gt;
&lt;p&gt;My biggest compliment to Rust is that it’s boring, and this is an amazing compliment.
&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.linkedin.com&#x2F;in&#x2F;christophersdickinson&#x2F;&quot;&gt;Chris Dickinson&lt;&#x2F;a&gt;, former Engineer at &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.npmjs.com&#x2F;about&quot;&gt;npm, Inc&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
&lt;p&gt;&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;deepsource.com&#x2F;blog&#x2F;exponential-cost-of-fixing-bugs&quot;&gt;Bugs cost more to fix the later they are found.&lt;&#x2F;a&gt;
Below is the relative cost of fixing bugs at various stages of the development lifecycle.
Bugs found in production are significantly more expensive to fix than bugs found
during development. (Source: NIST &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.nist.gov&#x2F;system&#x2F;files&#x2F;documents&#x2F;director&#x2F;planning&#x2F;report02-3.pdf&quot;&gt;Costs of Software Defects&lt;&#x2F;a&gt;)&lt;&#x2F;p&gt;
&lt;img src=&quot;bug-costs.svg&quot; class=&quot;invert&quot; alt=&quot;Cost of fixing bugs over time&quot;&gt;
&lt;p&gt;In a survey, &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;msrc.microsoft.com&#x2F;blog&#x2F;2019&#x2F;07&#x2F;a-proactive-approach-to-more-secure-code&#x2F;&quot;&gt;Microsoft found that 70% of their bugs are due to memory safety
issues&lt;&#x2F;a&gt;.
In 2018, the number of CVEs (Common Vulnerabilities and Exposures) at Microsoft
was 468. Each CVE costs an average of $150,000 to fix, which, as Microsoft
points out, is a very conservative estimate. (Source: &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.youtube.com&#x2F;watch?v=NQBVUjdkLAA&amp;amp;t=1s&quot;&gt;Ryan Levick - Rust at
Microsoft&lt;&#x2F;a&gt;).
Rust couldn’t have prevented all of these bugs, but it would have drastically
reduced the total amount.&lt;&#x2F;p&gt;
&lt;p&gt;Rust’s strong type system and its borrow checker allow you to &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;kerkour.com&#x2F;bugs-rust-compiler-helps-prevent&quot;&gt;catch bugs
earlier in the development lifecycle, typically at compile-time&lt;&#x2F;a&gt; (instead of
runtime as in languages with less stringent type systems or static analysis
capabilities). This results in real cost savings for companies.&lt;&#x2F;p&gt;
&lt;blockquote&gt;
&lt;p&gt;We always talk about the performance gains […] when using Rust but honestly I
much more look for the stability gains. - &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.youtube.com&#x2F;watch?v=KTJIsicwW5s&quot;&gt;Stefan Baumgartner, Senior Product Architect at Dynatrace&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
&lt;p&gt;As requirements grow, Rust is a great language for building larger applications
that are maintained by a bigger team over a long period of time. This is due to
its strong type system, its focus on memory safety, its powerful tooling (cargo,
rustfmt, clippy, etc.) and its stability guarantees (backwards compatibility)
due to its edition system. All of that makes large-scale refactoring easier.&lt;&#x2F;p&gt;
&lt;blockquote&gt;
&lt;p&gt;What I usually hear is that [efficiency is] what people are first excited about
but the reason that they keep using [Rust] is because actually it’s better for
building more reliable systems. - &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.youtube.com&#x2F;watch?v=oGN62EEHyn8&quot;&gt;Nicholas Matsakis, Senior Principal Engineer at AWS and lead of the Rust language design team.&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
&lt;p&gt;In a &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;opensource.googleblog.com&#x2F;2023&#x2F;06&#x2F;rust-fact-vs-fiction-5-insights-from-googles-rust-journey-2022.html&quot;&gt;Google survey&lt;&#x2F;a&gt;,
developers were asked about their confidence in Rust code compared to other
languages. The results were overwhelmingly positive:
&lt;strong&gt;85% of respondents were more confident in their team’s Rust code in comparison
to other languages.&lt;&#x2F;strong&gt;&lt;&#x2F;p&gt;
&lt;img src=&quot;rust_code_confidence.svg&quot; class=&quot;invert&quot; alt=&quot;Google Survey: confidence in Rust code is very high compared to other languages&quot;&gt;
&lt;h3 id=&quot;maintainability&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#maintainability&quot; aria-label=&quot;Anchor link for: maintainability&quot;&gt;Maintainability&lt;&#x2F;a&gt;&lt;&#x2F;h3&gt;
&lt;p&gt;Rust’s design principles significantly contribute to software maintainability.&lt;&#x2F;p&gt;
&lt;blockquote&gt;
&lt;p&gt;We find that when we build things in Rust, they are pretty easy to maintain.
They just don’t break. Our requirements can change; we may need to modify
them, but it’s pretty reliable - &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.youtube.com&#x2F;watch?v=1faOd6KH-w4&amp;amp;t=740s&quot;&gt;Edward Wright, Staff Engineer at Vortexa&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
&lt;p&gt;This ease of maintainability means that Rust applications require less effort to
adapt and evolve over time, reducing overall technical debt and freeing up
developer resources for new features rather than maintenance.&lt;&#x2F;p&gt;
&lt;p&gt;Emphasizing Rust’s impact on development efficiency and time-to-market, Wright continues&lt;&#x2F;p&gt;
&lt;blockquote&gt;
&lt;p&gt;We’re probably spending our time more focused on actually adding value for our
customers and changing things when the requirements change — work that we
should be doing rather than busy work. - &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.youtube.com&#x2F;watch?v=1faOd6KH-w4&amp;amp;t=761s&quot;&gt;Edward Wright, Staff Engineer at Vortexa&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
&lt;h3 id=&quot;predictable-runtime-behavior&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#predictable-runtime-behavior&quot; aria-label=&quot;Anchor link for: predictable-runtime-behavior&quot;&gt;Predictable Runtime Behavior&lt;&#x2F;a&gt;&lt;&#x2F;h3&gt;
&lt;p&gt;Predictable runtime behavior is closely related to reliability and stability.
It means that services run smoothly without any hiccups. This is especially
important for latency-sensitive services like games, chat applications, or
services that need to act on real-time data.&lt;&#x2F;p&gt;
&lt;p&gt;Smooth operation is of uppermost importance for organizations as it is a
significant cost factor and can impact customer satisfaction. According to a
&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.techrepublic.com&#x2F;article&#x2F;on-call-cloud-operations-cost-organizations-an-average-of-2-5-million-per-year&#x2F;&quot;&gt;recent
study&lt;&#x2F;a&gt;,
organizations are spending an average of $2.5 million per year on on-call
operations. &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;blog.pragmaticengineer.com&#x2F;oncall-compensation&#x2F;&quot;&gt;Compensation for on-call
engineers&lt;&#x2F;a&gt; is a big
part of that cost.&lt;&#x2F;p&gt;
&lt;blockquote&gt;
&lt;p&gt;People just didn’t like getting paged in the middle of the night, and Rust was
helping avoid that - &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.youtube.com&#x2F;watch?v=oGN62EEHyn8&quot;&gt;Nicholas Matsakis&lt;&#x2F;a&gt;
(in the context of npm migrating to Rust)&lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
&lt;p&gt;Discord has a &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;discord.com&#x2F;blog&#x2F;why-discord-is-switching-from-go-to-rust&quot;&gt;great
article&lt;&#x2F;a&gt;
about why they switched from Go to Rust. They mention that Go’s garbage
collector was a source of unpredictable latency spikes. After switching to Rust,
they were able to fully get rid of garbage collection and have a more
predictable runtime behavior.&lt;&#x2F;p&gt;
&lt;blockquote&gt;
&lt;p&gt;When we started load testing, we were instantly pleased with the results. The
latency of the Rust version was just as good as Go’s and had no latency spikes!&lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
&lt;p&gt;Here is a diagram from the above article by Discord.
Notice how the latency spikes in the Go version (purple) are gone in the Rust
version (blue) and how that impacts the 95th percentile response time, making it
much more predictable and smooth.&lt;&#x2F;p&gt;
&lt;img src=&quot;discord.png&quot; alt=&quot;Discord Go (purple) vs Rust (blue)&quot;&gt;
&lt;p&gt;Another example is
&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;blog.cloudflare.com&#x2F;big-pineapple-intro&#x2F;&quot;&gt;Cloudflare&lt;&#x2F;a&gt;,
which uses Rust to power their DNS service, &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;1.1.1.1&#x2F;&quot;&gt;1.1.1.1&lt;&#x2F;a&gt;. They
mention that Rust’s predictable runtime behavior is a big reason for using it:&lt;&#x2F;p&gt;
&lt;blockquote&gt;
&lt;p&gt;One of the things we’ve learned with the previous implementations is that, for
a service open to the public, a peak performance of the I&#x2F;O matters less than
the ability to pace clients fairly.&lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
&lt;p&gt;Furthermore, Rust shows excellent runtime behavior when handling network requests.
In a &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;medium.com&#x2F;star-gazers&#x2F;benchmarking-low-level-i-o-c-c-rust-golang-java-python-9a0d505f85f7&quot;&gt;benchmark by Eugene Retunsky&lt;&#x2F;a&gt;, Rust had the lowest tail latency and maximum throughput next to C and C++.&lt;&#x2F;p&gt;
&lt;p&gt;Here is the diagram from the benchmark, showing the p99.9 latency for each
language under test. As the requests per second increase, the latency for Rust
stays low and stable. Go and Java on the other hand have a higher baseline
latency while Python shows latency spikes at a certain point.&lt;&#x2F;p&gt;
&lt;img src=&quot;runtime.png&quot; alt=&quot;Rust Runtime behavior&quot;&gt;
&lt;p&gt;The author concludes:&lt;&#x2F;p&gt;
&lt;blockquote&gt;
&lt;p&gt;In conclusion, Rust has a much lower latency variance than Golang, Python, and especially Java.
[…] Rust might be a better alternative to Golang, Java, or Python if predictable performance is crucial for your service. Also, before starting to write a new service in C or C++, it’s worth considering Rust. - &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;medium.com&#x2F;star-gazers&#x2F;benchmarking-low-level-i-o-c-c-rust-golang-java-python-9a0d505f85f7&quot;&gt;Eugene Retunsky&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
&lt;h3 id=&quot;cost-savings&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#cost-savings&quot; aria-label=&quot;Anchor link for: cost-savings&quot;&gt;Cost Savings&lt;&#x2F;a&gt;&lt;&#x2F;h3&gt;
&lt;p&gt;We touched on cost savings already, but its significance warrants a dedicated
section.&lt;&#x2F;p&gt;
&lt;p&gt;Rust has a low runtime overhead. This is especially important for services that
need to scale to handle a large number of requests.
It can save a lot of money on cloud infrastructure costs if the same workload
can be handled with fewer resources.&lt;&#x2F;p&gt;
&lt;p&gt;For example, AWS has a service called
&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;aws.amazon.com&#x2F;blogs&#x2F;aws&#x2F;firecracker-lightweight-virtualization-for-serverless-computing&#x2F;&quot;&gt;Firecracker&lt;&#x2F;a&gt;,
which runs virtual machines with very low overhead. It powers AWS Lambda functions and AWS Fargate containers.&lt;&#x2F;p&gt;
&lt;blockquote&gt;
&lt;p&gt;Firecracker consumes about 5 MiB of memory per microVM. You can run thousands
of secure VMs with widely varying vCPU and memory configurations on the same
instance.&lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
&lt;p&gt;The better hardware utilization translates to lower costs for companies.&lt;&#x2F;p&gt;
&lt;p&gt;Firecracker allowed AWS to improve the efficiency of Fargate, which passed on
cost savings to customers. As a result, they were able to reduce the price of Fargate by
up to 50%.
(&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;shahbhargav.medium.com&#x2F;firecracker-secure-and-fast-microvms-628e6043b572&quot;&gt;Image source&lt;&#x2F;a&gt; and
&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;aws.amazon.com&#x2F;blogs&#x2F;compute&#x2F;aws-fargate-price-reduction-up-to-50&#x2F;&quot;&gt;AWS announcement&lt;&#x2F;a&gt;)&lt;&#x2F;p&gt;
&lt;img src=&quot;fargate.png&quot; alt=&quot;Firecracker&quot; &#x2F;&gt;
&lt;h3 id=&quot;ergonomics&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#ergonomics&quot; aria-label=&quot;Anchor link for: ergonomics&quot;&gt;Ergonomics&lt;&#x2F;a&gt;&lt;&#x2F;h3&gt;
&lt;p&gt;Rust has great developer ergonomics. Its expressive type system allows
developers to model their domain in a way that lets the compiler help with
writing correct code.&lt;&#x2F;p&gt;
&lt;p&gt;Furthermore, functional concepts like pattern matching, &lt;a href=&quot;&#x2F;blog&#x2F;enums&#x2F;&quot;&gt;enums&lt;&#x2F;a&gt;, &lt;code&gt;Result&lt;&#x2F;code&gt; and &lt;a href=&quot;&#x2F;blog&#x2F;rust-option-handling-best-practices&#x2F;&quot;&gt;&lt;code&gt;Option&lt;&#x2F;code&gt; types&lt;&#x2F;a&gt;
allow for concise and expressive code.&lt;&#x2F;p&gt;
&lt;p&gt;Rust’s robust error handling story, which requires the programmer to explicitly handle
errors, is a big reason for its reliability.&lt;&#x2F;p&gt;
&lt;p&gt;All these features make it easier to write correct code, reduce the cognitive
load on developers and catch bugs at compile-time instead of runtime.&lt;&#x2F;p&gt;
&lt;blockquote&gt;
&lt;p&gt;More than its memory safety and thread safety guarantees, the language exposes
facilities to library designers for building abstractions that resist misuse.
The emergent safe library ecosystem enables “if it compiles, then it’s correct”
programming unmatched by other mainstream languages, even garbage collected
ones. - &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;docs.rs&#x2F;dtolnay&#x2F;0.0.11&#x2F;dtolnay&#x2F;macro._03__soundness_bugs.html&quot;&gt;David Tolnay, author of serde&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
&lt;p&gt;Rust’s static analysis &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Shift-left_testing&quot;&gt;shifts the quality assurance of code to the
left&lt;&#x2F;a&gt;:&lt;&#x2F;p&gt;
&lt;img src=&quot;robustness.svg&quot; class=&quot;invert&quot; alt=&quot;Bug detection over time&quot;&gt;
&lt;blockquote&gt;
&lt;p&gt;Rust has been a force multiplier for our team, and betting on Rust was one of
the best decisions we made. More than performance, its ergonomics and focus on
correctness has helped us tame sync’s complexity. We can encode complex
invariants about our system in the type system and have the compiler check them
for us. - &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;dropbox.tech&#x2F;infrastructure&#x2F;rewriting-the-heart-of-our-sync-engine&quot;&gt;Dropbox&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
&lt;p&gt;An often mentioned benefit of Rust is the possibility to refactor code without
fear. This should not be underestimated as it allows you to improve your
codebase over time and make it more robust. Especially for applications that use
multi-threading, this is a big advantage as &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;blog.rust-lang.org&#x2F;2015&#x2F;04&#x2F;10&#x2F;Fearless-Concurrency.html&quot;&gt;typical error scenarios of
concurrent programming are detected by the
compiler&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;focus-on-long-term-sustainability&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#focus-on-long-term-sustainability&quot; aria-label=&quot;Anchor link for: focus-on-long-term-sustainability&quot;&gt;Focus on Long-Term Sustainability&lt;&#x2F;a&gt;&lt;&#x2F;h3&gt;
&lt;p&gt;Companies rarely rewrite their services in another language. It incurs a lot of costs
and risks. Only if a rewrite promises a &lt;em&gt;significant&lt;&#x2F;em&gt; upside, companies will
consider it.&lt;&#x2F;p&gt;
&lt;p&gt;One well-known company that started to heavily invest in Rust is Microsoft.&lt;&#x2F;p&gt;
&lt;blockquote&gt;
&lt;p&gt;Microsoft is going big on Rust and spending $10 million to make it 1st class
language in our engineering systems + $1 million @rustlang foundation. - &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;twitter.com&#x2F;dwizzzleMSFT&#x2F;status&#x2F;1720134540822520268&quot;&gt;David Weston, Vice President of OS Security and Enterprise at Microsoft&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
&lt;p&gt;Microsoft even &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;twitter.com&#x2F;markrussinovich&#x2F;status&#x2F;1656416376125538304&quot;&gt;integrated Rust into the Windows kernel&lt;&#x2F;a&gt;.
The fact that they take big bets on Rust shows that they are in it
for the long run. This is a good sign for the Rust ecosystem, as the backing of
a large company can help Rust to become more mainstream and ensure
long-term sustainability.&lt;&#x2F;p&gt;
&lt;p&gt;Similarly, &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.kernel.org&#x2F;doc&#x2F;html&#x2F;next&#x2F;rust&#x2F;index.html&quot;&gt;the Linux kernel now supports Rust&lt;&#x2F;a&gt;
as well.
The Kernel incorporating Rust is a major endorsement of the language. Notably,
the Linux Kernel maintainers have previously &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;http:&#x2F;&#x2F;harmful.cat-v.org&#x2F;software&#x2F;c++&#x2F;linus&quot;&gt;refused to integrate C++ in the Kernel&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;In a landmark development for Rust, the open source &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;ferrous-systems.com&#x2F;blog&#x2F;officially-qualified-ferrocene&#x2F;&quot;&gt;Ferrocene
toolchain&lt;&#x2F;a&gt; has
achieved a significant milestone: Ferrocene, based on Rust 1.68, is now ISO
26262 and IEC 61508 qualified. This certification means that the Rust compiler
meets rigorous safety standards, making it fully usable in safety-critical
environments like automotive or avionics. Few other languages have
achieved this level of certification. It is another strong signal that Rust is
here to stay.&lt;&#x2F;p&gt;
&lt;p&gt;For another take on this, watch &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.youtube.com&#x2F;watch?v=WnIWRks35Fk&quot;&gt;“In It for the Long
Haul”&lt;&#x2F;a&gt; by &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;twitter.com&#x2F;carols10cents&quot;&gt;Carol
Nichols&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;productivity-and-developer-happiness&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#productivity-and-developer-happiness&quot; aria-label=&quot;Anchor link for: productivity-and-developer-happiness&quot;&gt;Productivity And Developer Happiness&lt;&#x2F;a&gt;&lt;&#x2F;h3&gt;
&lt;p&gt;As mentioned in the &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.jetbrains.com&#x2F;lp&#x2F;devecosystem-2021&#x2F;rust&#x2F;#:~:text=Rust%20developers%20are%20generally%20more,senior%20positions%20than%20other%20developers&quot;&gt;2021 JetBrains Developer Ecosystem
Report&lt;&#x2F;a&gt;,
Rust developers are typically more proficient compared to developers in other
languages, as many have more experience and often occupy senior roles.&lt;&#x2F;p&gt;
&lt;p&gt;Many developers enjoy working with Rust. It has consistently been the most admired language
according to the &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;survey.stackoverflow.co&#x2F;2023&#x2F;#section-admired-and-desired-programming-scripting-and-markup-languages&quot;&gt;StackOverflow Developer Survey&lt;&#x2F;a&gt;.
More than 80% of developers that use it want to use it again next year.&lt;&#x2F;p&gt;
&lt;p&gt;For teams that are looking to hire and retain talent, Rust can be a great choice
because &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.microsoft.com&#x2F;en-us&#x2F;research&#x2F;publication&#x2F;towards-a-theory-of-software-developer-job-satisfaction-and-perceived-productivity&#x2F;&quot;&gt;developer happiness is a big factor in job satisfaction and has a positive
impact on productivity&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;performance-and-energy-efficiency&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#performance-and-energy-efficiency&quot; aria-label=&quot;Anchor link for: performance-and-energy-efficiency&quot;&gt;Performance And Energy Efficiency&lt;&#x2F;a&gt;&lt;&#x2F;h3&gt;
&lt;p&gt;As stated earlier, performance often gets mentioned as a main reason for using Rust.
On top of that, Rust has great support for multi-threaded workloads. Libraries like
&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;rayon-rs&#x2F;rayon&quot;&gt;rayon&lt;&#x2F;a&gt; and &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;tokio.rs&#x2F;&quot;&gt;Tokio&lt;&#x2F;a&gt; are considered
best-in-class for writing high-performance applications.&lt;&#x2F;p&gt;
&lt;p&gt;Making efficient use of compute resources has much deeper implications for
companies than just raw execution speed.&lt;&#x2F;p&gt;
&lt;p&gt;One important aspect is scalability: companies can defer costly performance optimizations
and scaling efforts by choosing a language that is efficient by default. This way, they
can focus on building features and growing their business before they need to worry about
performance bottlenecks.&lt;&#x2F;p&gt;
&lt;p&gt;In his talk at FrOSCon 2024, &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;kerkmann&quot;&gt;Daniél Kerkmann&lt;&#x2F;a&gt;, software engineer at
&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;opentalk.eu&quot;&gt;OpenTalk&lt;&#x2F;a&gt; – a secure video conferencing platform written in Rust – shared that
sentiment:&lt;&#x2F;p&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;The performance of Rust kept us afloat for a long time.&lt;&#x2F;strong&gt;&lt;&#x2F;p&gt;
&lt;p&gt;Up to a point of 10.000 video participants we didn’t have to refactor thanks to Rust’s performance.
We could focus on features instead without worrying about bottlenecks.&lt;br &#x2F;&gt;
— Source: &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;media.ccc.de&#x2F;v&#x2F;froscon2024-3105-in_rust_radikal_refactorn#t=1198&quot;&gt;FrOSCon 2024 talk by Daniél Kerkmann (German)&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
&lt;p&gt;Another aspect of performance is energy efficiency.&lt;&#x2F;p&gt;
&lt;p&gt;In the below benchmark, taken from &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;greenlab.di.uminho.pt&#x2F;wp-content&#x2F;uploads&#x2F;2017&#x2F;10&#x2F;sleFinal.pdf&quot;&gt;“Energy Efficiency across Programming Languages”&lt;&#x2F;a&gt;
by Pereira et al., Rust has superior runtime performance on par with C and C++
and faster than Go by a factor of 2-3x as well as Python by a factor of 70x.&lt;&#x2F;p&gt;
&lt;table&gt;&lt;thead&gt;&lt;tr&gt;&lt;th&gt;Lang&lt;&#x2F;th&gt;&lt;th&gt;Time (Normalized)&lt;&#x2F;th&gt;&lt;&#x2F;tr&gt;&lt;&#x2F;thead&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;C&lt;&#x2F;td&gt;&lt;td&gt;1.00&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;Rust&lt;&#x2F;td&gt;&lt;td&gt;1.04&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;C++&lt;&#x2F;td&gt;&lt;td&gt;1.56&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;Java&lt;&#x2F;td&gt;&lt;td&gt;1.89&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;Go&lt;&#x2F;td&gt;&lt;td&gt;2.83&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;JavaScript&lt;&#x2F;td&gt;&lt;td&gt;6.52&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;PHP&lt;&#x2F;td&gt;&lt;td&gt;27.64&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;Ruby&lt;&#x2F;td&gt;&lt;td&gt;59.34&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;Python&lt;&#x2F;td&gt;&lt;td&gt;71.90&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;&#x2F;tbody&gt;&lt;&#x2F;table&gt;
&lt;p&gt;This translates to lower energy consumption as well.
Energy is another important cost factor for companies at scale.&lt;&#x2F;p&gt;
&lt;img src=&quot;energy-consumption.svg&quot; class=&quot;invert&quot; alt=&quot;Energy Efficiency across Programming Languages&quot; &#x2F;&gt;
&lt;h3 id=&quot;gradual-adoption-and-ffi&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#gradual-adoption-and-ffi&quot; aria-label=&quot;Anchor link for: gradual-adoption-and-ffi&quot;&gt;Gradual Adoption and FFI&lt;&#x2F;a&gt;&lt;&#x2F;h3&gt;
&lt;p&gt;One often overlooked aspect of Rust is that it can be incrementally integrated
into existing codebases. Interoperability is a key concern of Rust, allowing it
to &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;users.rust-lang.org&#x2F;t&#x2F;tips-and-experiences-integrating-rust-into-other-projects&#x2F;12091&#x2F;12&quot;&gt;natively interface with other languages like C, C++, or Python&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;This makes it possible for Rust to take on a supporting role in existing
codebases, where it can be used for security- or performance-critical parts
while the rest of the codebase remains in the original language. &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.youtube.com&#x2F;watch?v=l--5nx_q0_Y&quot;&gt;This greatly
reduces risks as big rewrites are avoided.&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;p&gt;In a data science environment dominated by Python, integrating Rust offers
significant performance enhancements.
By using Rust to process data originally managed with Python libraries such as
Pandas and NumPy, data can be strategically copied from Python into Rust
structures, and leveraging Rust’s powerful concurrency tools like Rayon for
parallel processing.&lt;&#x2F;p&gt;
&lt;p&gt;As a case-study, this approach, &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;youtu.be&#x2F;1faOd6KH-w4?si=pdd04RikPpsohiza&amp;amp;t=1111&quot;&gt;significantly accelerated a critical data
processing task at
Vortexa&lt;&#x2F;a&gt;, which wrote a
Python extension in Rust to optimize the performance of a hot path in their data
processing pipeline. The result was a reduction from 24 hours to 1 hour with 400
lines of Rust code. The rest of the codebase remained intact.&lt;&#x2F;p&gt;
&lt;p&gt;It shows Rust’s potential to serve as a &lt;em&gt;surgical tool&lt;&#x2F;em&gt; within other ecosystems,
dramatically optimizing performance with minimal intrusion.&lt;&#x2F;p&gt;
&lt;p&gt;On top of that, the Rust library code could be reused across projects from
embedded programs to cloud services, which streamlines the development process
and further reduces maintenance costs.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;support-for-a-wide-range-of-environments&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#support-for-a-wide-range-of-environments&quot; aria-label=&quot;Anchor link for: support-for-a-wide-range-of-environments&quot;&gt;Support for a Wide Range of Environments&lt;&#x2F;a&gt;&lt;&#x2F;h3&gt;
&lt;p&gt;Rust is a versatile language, which can be used in a wide range of applications, from embedded systems to
high-performance web services.&lt;&#x2F;p&gt;
&lt;table&gt;&lt;thead&gt;&lt;tr&gt;&lt;th&gt;Environment&lt;&#x2F;th&gt;&lt;th&gt;Rust&lt;&#x2F;th&gt;&lt;th&gt;Kotlin&lt;&#x2F;th&gt;&lt;th&gt;Go&lt;&#x2F;th&gt;&lt;th&gt;C++&lt;&#x2F;th&gt;&lt;th&gt;TypeScript&lt;&#x2F;th&gt;&lt;th&gt;Python&lt;&#x2F;th&gt;&lt;&#x2F;tr&gt;&lt;&#x2F;thead&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;Frontend Development&lt;&#x2F;td&gt;&lt;td&gt;Yes (via WASM)&lt;&#x2F;td&gt;&lt;td&gt;Partial (via Kotlin&#x2F;JS)&lt;&#x2F;td&gt;&lt;td&gt;No&lt;&#x2F;td&gt;&lt;td&gt;No&lt;&#x2F;td&gt;&lt;td&gt;Yes&lt;&#x2F;td&gt;&lt;td&gt;Partial (via frameworks like PyScript)&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;Backend Development&lt;&#x2F;td&gt;&lt;td&gt;Yes&lt;&#x2F;td&gt;&lt;td&gt;Yes&lt;&#x2F;td&gt;&lt;td&gt;Yes&lt;&#x2F;td&gt;&lt;td&gt;Yes&lt;&#x2F;td&gt;&lt;td&gt;Yes&lt;&#x2F;td&gt;&lt;td&gt;Yes&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;Mobile Development&lt;&#x2F;td&gt;&lt;td&gt;Yes&lt;&#x2F;td&gt;&lt;td&gt;Yes (Android)&lt;&#x2F;td&gt;&lt;td&gt;No&lt;&#x2F;td&gt;&lt;td&gt;Partial&lt;&#x2F;td&gt;&lt;td&gt;No&lt;&#x2F;td&gt;&lt;td&gt;Partial (Kivy, BeeWare)&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;Data Science&lt;&#x2F;td&gt;&lt;td&gt;Yes&lt;&#x2F;td&gt;&lt;td&gt;Yes&lt;&#x2F;td&gt;&lt;td&gt;Partial&lt;&#x2F;td&gt;&lt;td&gt;Partial&lt;&#x2F;td&gt;&lt;td&gt;No&lt;&#x2F;td&gt;&lt;td&gt;Yes&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;Game Development&lt;&#x2F;td&gt;&lt;td&gt;Yes&lt;&#x2F;td&gt;&lt;td&gt;Partial&lt;&#x2F;td&gt;&lt;td&gt;Partial&lt;&#x2F;td&gt;&lt;td&gt;Yes&lt;&#x2F;td&gt;&lt;td&gt;Partial&lt;&#x2F;td&gt;&lt;td&gt;Partial&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;DevOps&lt;&#x2F;td&gt;&lt;td&gt;Yes&lt;&#x2F;td&gt;&lt;td&gt;Partial&lt;&#x2F;td&gt;&lt;td&gt;Yes&lt;&#x2F;td&gt;&lt;td&gt;Yes&lt;&#x2F;td&gt;&lt;td&gt;Partial&lt;&#x2F;td&gt;&lt;td&gt;Yes&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;Systems Programming&lt;&#x2F;td&gt;&lt;td&gt;Yes&lt;&#x2F;td&gt;&lt;td&gt;No&lt;&#x2F;td&gt;&lt;td&gt;Partial&lt;&#x2F;td&gt;&lt;td&gt;Yes&lt;&#x2F;td&gt;&lt;td&gt;No&lt;&#x2F;td&gt;&lt;td&gt;Partial&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;Embedded Systems&lt;&#x2F;td&gt;&lt;td&gt;Yes&lt;&#x2F;td&gt;&lt;td&gt;Partial&lt;&#x2F;td&gt;&lt;td&gt;Partial&lt;&#x2F;td&gt;&lt;td&gt;Yes&lt;&#x2F;td&gt;&lt;td&gt;No&lt;&#x2F;td&gt;&lt;td&gt;Partial (MicroPython)&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;&#x2F;tbody&gt;&lt;&#x2F;table&gt;
&lt;p&gt;For companies with diverse product portfolios,
it can be beneficial to have a single language that can be used across the
entire stack. Clients often mention that the same crates can be used in
different contexts, reducing boundaries between teams and making it easier to
share code.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;reasons-against-using-rust-in-production&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#reasons-against-using-rust-in-production&quot; aria-label=&quot;Anchor link for: reasons-against-using-rust-in-production&quot;&gt;Reasons Against Using Rust In Production&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;p&gt;Every technology comes with its own set of challenges, and Rust is no exception.
The following points highlight some common concerns about using Rust in
production. You need to weigh them against the benefits discussed earlier to
make an informed decision for your team.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;immature-ecosystem&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#immature-ecosystem&quot; aria-label=&quot;Anchor link for: immature-ecosystem&quot;&gt;Immature ecosystem&lt;&#x2F;a&gt;&lt;&#x2F;h3&gt;
&lt;p&gt;Rust is a relatively young language. Version 1.0 was first released in 2015.
This means that the ecosystem is still maturing. Many important libraries &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.reddit.com&#x2F;r&#x2F;rust&#x2F;comments&#x2F;11byl6u&#x2F;why_is_every_crate_pre10&#x2F;&quot;&gt;did not see their 1.0 release yet&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;This phenomenon has been &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.reddit.com&#x2F;r&#x2F;rust&#x2F;comments&#x2F;11byl6u&#x2F;why_is_every_crate_pre10&#x2F;ja3auop&#x2F;&quot;&gt;brought up as a reason to be cautious when using Rust in production&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;In practice, it might be hard to find production-grade libraries for specific
needs. Your team might be required to write custom crates or improve existing
ones. Furthermore, &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;sponsors&#x2F;explore?ecosystem=RUST&quot;&gt;sponsoring open source maintainers&lt;&#x2F;a&gt; to work on critical
dependencies is a good way to ensure that the long-term sustainability of the
ecosystem.&lt;&#x2F;p&gt;
&lt;p&gt;That said, libraries for common tasks like JSON parsing or network handling are
very robust and stable and considered best-in-class. Breaking changes are rare
and important crates like &lt;code&gt;serde&lt;&#x2F;code&gt; or &lt;code&gt;tokio&lt;&#x2F;code&gt; are already past their 1.0 release.&lt;&#x2F;p&gt;
&lt;p&gt;A relatively recent addition to the Rust ecosystem is async&#x2F;await support, a
feature designed to streamline the writing of concurrent applications. This support
represents a significant evolution in Rust’s capabilities, but it is still
in its early stages.
If you’re planning to write network applications in Rust, there is a high chance
that you will need to use async&#x2F;await. As such it’s important to stay on top of
its ongoing development and limitations. For a detailed exploration of where
async&#x2F;await in Rust stands today, including its practical implications, we
invite you to read our comprehensive post detailing the current &lt;a href=&quot;&#x2F;blog&#x2F;async&#x2F;&quot;&gt;state of
async&#x2F;await in Rust&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;lack-of-developers&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#lack-of-developers&quot; aria-label=&quot;Anchor link for: lack-of-developers&quot;&gt;Lack Of Developers&lt;&#x2F;a&gt;&lt;&#x2F;h3&gt;
&lt;p&gt;Related to the previous point, the Rust community is still relatively small.
It is hard to find developers with professional Rust experience.&lt;&#x2F;p&gt;
&lt;p&gt;From talking to companies that use Rust in production, I found that they are
mostly training their developers on the job.
Moreover, Rust is noted for enabling a smooth onboarding process for engineers
already proficient in languages like C++ or Java.&lt;&#x2F;p&gt;
&lt;p&gt;On the other hand, Rust developers are generally very passionate about their
craft and are actively seeking out jobs that allow them to use Rust,
so the market for Rust developers is growing. (Also see
the previous section about developer happiness.)&lt;&#x2F;p&gt;
&lt;p&gt;For more insights on finding and hiring Rust talent, see our dedicated guide on &lt;a href=&quot;&#x2F;blog&#x2F;hiring-rust-engineers&#x2F;&quot;&gt;how to hire Rust engineers&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;blockquote&gt;
&lt;p&gt;Rust has more than tripled the size of its community over the past two years
and currently has 3.7M users, of which 0.6M joined in the last six months
alone.[…] Furthermore, Rust has built a loyal community of developers who care
about memory safety and security. - &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.developernation.net&#x2F;resources&#x2F;reports&#x2F;state-of-the-developer-nation-24th-edition-q1-2023&quot;&gt;State of the Developer Nation 24th Edition - Q1 2023 report&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
&lt;a href=&quot;https:&#x2F;&#x2F;www.developernation.net&#x2F;resources&#x2F;reports&#x2F;state-of-the-developer-nation-24th-edition-q1-2023&quot; target=&quot;_blank&quot;&gt;
&lt;img src=&quot;communities.svg&quot; class=&quot;invert&quot; alt=&quot;Programming Language Communities Size&quot;&gt;
&lt;&#x2F;a&gt;
&lt;h3 id=&quot;tooling&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#tooling&quot; aria-label=&quot;Anchor link for: tooling&quot;&gt;Tooling&lt;&#x2F;a&gt;&lt;&#x2F;h3&gt;
&lt;p&gt;Cargo, rustfmt, clippy, and rust-analyzer
are all great tools that make Rust development a joy.
Debugging support is still lacking, but it is &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;rustc-dev-guide.rust-lang.org&#x2F;debugging-support-in-rustc.html&quot;&gt;steadily improving&lt;&#x2F;a&gt;.
&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.jetbrains.com&#x2F;lp&#x2F;devecosystem-2021&#x2F;rust&#x2F;#Rust_what-profiling-tools-do-you-use-for-rust&quot;&gt;The story for profiling support is similar.&lt;&#x2F;a&gt;
It should be noted, that Rust integrates well with existing tools like &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;blog.logrocket.com&#x2F;debugging-rust-apps-with-gdb&#x2F;&quot;&gt;GDB&lt;&#x2F;a&gt; or
perf, although &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;rust-lang&#x2F;rustup&#x2F;issues&#x2F;2838&quot;&gt;the experience is not seamless on all platforms yet&lt;&#x2F;a&gt;.
For an up-to-date overview, see this list of &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;nnethercote.github.io&#x2F;perf-book&#x2F;profiling.html&quot;&gt;Rust profiling tools&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;Recently, &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.jetbrains.com&#x2F;rust&#x2F;&quot;&gt;JetBrains announced RustRover&lt;&#x2F;a&gt;,
a new IDE for Rust which is based on IntelliJ.
This is a strong signal that JetBrains sees it as a good investment to build
tooling for Rust developers and that they expect Rust to become more mainstream.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;learning-curve&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#learning-curve&quot; aria-label=&quot;Anchor link for: learning-curve&quot;&gt;Learning Curve&lt;&#x2F;a&gt;&lt;&#x2F;h3&gt;
&lt;p&gt;Rust has a &lt;a href=&quot;&#x2F;blog&#x2F;flattening-rusts-learning-curve&#x2F;&quot;&gt;famously steep learning curve&lt;&#x2F;a&gt;. It is a complex language with many
advanced features.&lt;&#x2F;p&gt;
&lt;p&gt;When asked why they don’t use Rust, participants of the &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;blog.rust-lang.org&#x2F;2023&#x2F;08&#x2F;07&#x2F;Rust-Survey-2023-Results.html#rust-usage&quot;&gt;2022 Annual Rust Survey&lt;&#x2F;a&gt;
mentioned the learning curve as the main reason:&lt;&#x2F;p&gt;
&lt;img src=&quot;why-not-rust.svg&quot; class=&quot;invert&quot; alt=&quot;Why not Rust?&quot;&gt;
&lt;p&gt;In the &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;blog.rust-lang.org&#x2F;2020&#x2F;12&#x2F;16&#x2F;rust-survey-2020.html#improved-learnability&quot;&gt;Rust 2020
survey&lt;&#x2F;a&gt;,
participants were asked to rate the difficulty of various Rust concepts. Here
are the results:&lt;&#x2F;p&gt;
&lt;img src=&quot;topic-difficulty-ratings.svg&quot; class=&quot;invert&quot; alt=&quot;Difficulty by topic&quot;&gt;
&lt;p&gt;Lifetime annotations, ownership, and borrowing were mentioned as the most
difficult topics to grasp. In real-world applications, lifetimes
are less of an issue, however, as the compiler can often infer them through
&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;doc.rust-lang.org&#x2F;reference&#x2F;lifetime-elision.html&quot;&gt;lifetime elision&lt;&#x2F;a&gt;.
Ownership and borrowing however are crucial concepts in Rust that need to be
understood to become proficient.&lt;&#x2F;p&gt;
&lt;p&gt;It is important to set clear expectations for your team when adopting Rust: Rust
is not a language that you can learn in a few days. It requires practice to internalize
the concepts around ownership and borrowing to become productive with it.&lt;&#x2F;p&gt;
&lt;p&gt;There is an upfront cost of learning the language and training your team with
the expectation that it will pay off in the long run.&lt;&#x2F;p&gt;
&lt;p&gt;The time to become productive with Rust varies. Google’s experience suggests:&lt;&#x2F;p&gt;
&lt;blockquote&gt;
&lt;p&gt;Based on our studies, more than 2&#x2F;3 of respondents are confident in
contributing to a Rust codebase within two months or less when learning Rust.
Further, a third of respondents become as productive using Rust as other
languages in two months or less. &lt;strong&gt;Within four months, that number increased to
over 50%.&lt;&#x2F;strong&gt; - &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;opensource.googleblog.com&#x2F;2023&#x2F;06&#x2F;rust-fact-vs-fiction-5-insights-from-googles-rust-journey-2022.html&quot;&gt;Google&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
&lt;p&gt;Microsoft also shared a &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;msrc.microsoft.com&#x2F;blog&#x2F;2020&#x2F;04&#x2F;the-safety-boat-kubernetes-and-rust&#x2F;&quot;&gt;similar experience&lt;&#x2F;a&gt;:&lt;&#x2F;p&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;It takes several weeks of hard effort&lt;&#x2F;strong&gt; learning how to code properly in Rust
before the learning curve levels out. However, that hard effort up front pays
off in dividends due to the aforementioned safety features. We also noticed that
once developers are over that initial curve, they are able to contribute to code
just as easily as with any other language. Just be aware that there will be some
initial pain.&lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
&lt;p&gt;Depending on your immediate needs, this might be a deal-breaker for your team.
Other languages like Go or Python have a much lower learning curve and are
a better fit for rapid prototyping.
&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;mdwdotla.medium.com&#x2F;using-rust-at-a-startup-a-cautionary-tale-42ab823d9454&quot;&gt;Think twice before adopting it in a fast-paced startup
environment&lt;&#x2F;a&gt;
, particularly if your team doesn’t include seasoned Rust developers.&lt;&#x2F;p&gt;
&lt;blockquote&gt;
&lt;p&gt;Assuming you’re building a product in the right domain for Rust […], even
then the answer is not clear-cut. […] Development velocity and being able to
make rapid iterations is so important for an early stage startup that it
outweighs a lot of the benefits that Rust brings to the table. -
&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.shuttle.rs&#x2F;blog&#x2F;2021&#x2F;10&#x2F;08&#x2F;building-a-startup-with-rust&quot;&gt;Christos Hadjiaslanis - Founder of Shuttle&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
&lt;h3 id=&quot;compile-times&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#compile-times&quot; aria-label=&quot;Anchor link for: compile-times&quot;&gt;Compile Times&lt;&#x2F;a&gt;&lt;&#x2F;h3&gt;
&lt;p&gt;Rust has a reputation for having long compile times. This is especially true for
large projects with many dependencies.&lt;&#x2F;p&gt;
&lt;blockquote&gt;
&lt;p&gt;Slow build speeds were by far the #1 reported challenge that developers have
when using Rust, with only a little more than 40% of respondents finding the
speed acceptable. - &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;opensource.googleblog.com&#x2F;2023&#x2F;06&#x2F;rust-fact-vs-fiction-5-insights-from-googles-rust-journey-2022.html&quot;&gt;Google&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
&lt;p&gt;Rapid iteration is important for developers. Long compile times can be a
productivity killer. This is most noticeable for developers that are used to
languages like Go or Python, where the feedback loop is much faster.&lt;&#x2F;p&gt;
&lt;p&gt;Compile times are a known issue and the Rust team is &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;nnethercote.github.io&#x2F;2023&#x2F;03&#x2F;24&#x2F;how-to-speed-up-the-rust-compiler-in-march-2023.html&quot;&gt;continously working on improving them&lt;&#x2F;a&gt;.
And these incremental improvements are paying off. The Rust compiler is getting
faster over time. For example, the Rust compiler is twice as fast than it was in
2018 for &lt;code&gt;cargo check&lt;&#x2F;code&gt; (which is the most common command to quickly check
for errors):&lt;&#x2F;p&gt;
&lt;img src=&quot;compile-times.svg&quot; class=&quot;invert&quot; alt=&quot;Rust Compile Times Over Time&quot;&gt;
&lt;p&gt;Very recently, the Rust compiler frontend also gained support for &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;blog.rust-lang.org&#x2F;2023&#x2F;11&#x2F;09&#x2F;parallel-rustc.html&quot;&gt;parallel
compilation&lt;&#x2F;a&gt;, which
could drastically reduce compile times for large projects. The feature is
currently in &lt;em&gt;nightly&lt;&#x2F;em&gt; only and highly experimental, but it promises speedups
of up to 50%. Details on how to test it can be found in the announcement
&lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;blog.rust-lang.org&#x2F;2023&#x2F;11&#x2F;09&#x2F;parallel-rustc.html&quot;&gt;blog post&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;For more advice on how to improve compile times, see &lt;a href=&quot;&#x2F;blog&#x2F;tips-for-faster-rust-compile-times&#x2F;&quot;&gt;my article on this
topic&lt;&#x2F;a&gt; with many practical tips.
For medium-sized projects, compile times are less of an issue. &lt;a class=&quot;external-link&quot; rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.reddit.com&#x2F;r&#x2F;rust&#x2F;comments&#x2F;qgi421&#x2F;doing_m1_macbook_pro_m1_max_64gb_compile&#x2F;&quot;&gt;Modern hardware
can also mitigate the issue to some
extent.&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;h2 id=&quot;conclusion&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#conclusion&quot; aria-label=&quot;Anchor link for: conclusion&quot;&gt;Conclusion&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;p&gt;Rust is a great language for building large-scale, reliable, and stable
applications. It is a good fit for companies that value productivity and
developer happiness and see it as a long-term investment.&lt;&#x2F;p&gt;
&lt;p&gt;On the other side, Rust is still a young language and the ecosystem is still
maturing. It has a steep learning curve and long compile times.&lt;&#x2F;p&gt;
&lt;p&gt;These challenges are not insurmountable, however. They require a commitment to
Rust and a willingness to invest in training and tooling.&lt;&#x2F;p&gt;
&lt;p&gt;Navigating the decision to integrate Rust into your technology stack is pivotal
and requires thoughtful consideration. Should you find yourself weighing its
benefits against your specific requirements, professional guidance can prove
invaluable. Equally, if you are ready to embrace Rust and are seeking expertise
in training or consulting to ensure a smooth transition, specialized support is
essential.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;a href=&quot;&#x2F;services&#x2F;&quot;&gt;Get in touch&lt;&#x2F;a&gt; to explore if Rust is the right choice for your
organization and how it can contribute to your long-term success.&lt;&#x2F;p&gt;
&lt;div class=&quot;info&quot;&gt;
  
  &lt;div class=&quot;info-header&quot;&gt;
    
      &lt;span class=&quot;icon icon-radio&quot;&gt;&lt;&#x2F;span&gt;
    
    &lt;h4&gt;&lt;p&gt;Rust in Production Podcast&lt;&#x2F;p&gt;
&lt;&#x2F;h4&gt;
  &lt;&#x2F;div&gt;
  
  &lt;p&gt;Real-world experiences are the best way to learn about the benefits and
challenges of a technology. That’s why we started &lt;a href=&quot;&#x2F;podcast&quot;&gt;Rust in Production&lt;&#x2F;a&gt;, a
podcast about companies that bet big on Rust.&lt;&#x2F;p&gt;
&lt;p&gt;Listen to the first-hand accounts from decision-makers about why they chose Rust and how it
impacted their business.
Each episode is a deep dive into the motivations, challenges, and lessons learned
from adopting Rust in production by companies that shape the future of infrastructure.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;a href=&quot;&#x2F;podcast&quot;&gt;More information here&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;

&lt;&#x2F;div&gt;
&lt;h2 id=&quot;talks&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#talks&quot; aria-label=&quot;Anchor link for: talks&quot;&gt;Talks&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;https:&#x2F;&#x2F;www.youtube.com&#x2F;watch?v=DnT-LUQgc7s&quot; target=&quot;_blank&quot;&gt;Considering Rust — Jon Gjengset, 2020&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a href=&quot;https:&#x2F;&#x2F;www.youtube.com&#x2F;watch?v=GCsxYAxw3JQ&quot; target=&quot;_blank&quot;&gt;How I Convinced the World’s Largest Package Manager to Use Rust, and So Can You! — Ashley Williams, 2017&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a href=&quot;https:&#x2F;&#x2F;www.youtube.com&#x2F;watch?v=QrrH2lcl9ew&quot; target=&quot;_blank&quot;&gt;Beyond Safety and Speed: How Rust Fuels Team Productivity — Lars Bergstrom, 2024&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h2 id=&quot;next-steps&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#next-steps&quot; aria-label=&quot;Anchor link for: next-steps&quot;&gt;Next Steps&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;&#x2F;services&#x2F;&quot;&gt;Reach Out for Rust Training and Consulting&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
</description>
      </item>
    </channel>
</rss>
