<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/">
  <channel>
    <title>Rust on BadproG</title>
    <link>https://www.badprog.com/rust/</link>
    <description>Recent content in Rust on BadproG</description>
    <generator>Hugo</generator>
    <language>en-us</language>
    <lastBuildDate>Wed, 08 Jul 2026 00:00:00 +0000</lastBuildDate>
    <atom:link href="https://www.badprog.com/rust/index.xml" rel="self" type="application/rss+xml" />
    <item>
      <title>Rust - Multithreading - ABBA deadlock with Arc, Mutex and OS Thread</title>
      <link>https://www.badprog.com/rust-multithreading-abba-deadlock-with-arc-mutex-and-os-thread/</link>
      <pubDate>Wed, 08 Jul 2026 00:00:00 +0000</pubDate>
      <guid>https://www.badprog.com/rust-multithreading-abba-deadlock-with-arc-mutex-and-os-thread/</guid>
      <description>&lt;p&gt;Your program compiles, runs, prints nothing, and simply sits there forever.&lt;/p&gt;
&lt;p&gt;Welcome to the &lt;code&gt;deadlock&lt;/code&gt; club, the most silent bug family in concurrent programming.&lt;/p&gt;
&lt;p&gt;In this tutorial we build the most classic deadlock of all, the lock ordering deadlock, also known as the &lt;code&gt;ABBA&lt;/code&gt; deadlock.&lt;/p&gt;
&lt;p&gt;Our playground: two embedded bus devices, &lt;code&gt;SPI&lt;/code&gt; and &lt;code&gt;I2C&lt;/code&gt;, each protected by its own &lt;code&gt;Mutex&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Two threads transfer data between the buses in opposite directions, each locking its source first.&lt;/p&gt;</description>
    </item>
    <item>
      <title>Rust - CLI - Validate program arguments and handle errors with an enum and test suite</title>
      <link>https://www.badprog.com/rust-cli-validate-program-arguments-and-handle-errors-with-an-enum-and-test-suite/</link>
      <pubDate>Sun, 28 Jun 2026 00:00:00 +0000</pubDate>
      <guid>https://www.badprog.com/rust-cli-validate-program-arguments-and-handle-errors-with-an-enum-and-test-suite/</guid>
      <description>&lt;p&gt;A command line program always starts with the same question: what did the user actually pass in, and can I work with that?&lt;/p&gt;
&lt;p&gt;In this tutorial we&amp;rsquo;re going to see how to handle user arguments and how to test them through unit tests and integration tests.&lt;/p&gt;
&lt;h2 id=&#34;what-we-need&#34;&gt;What we need&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;GitHub for this tutorial:
&lt;ul&gt;
&lt;li&gt;&lt;a href=&#34;https://github.com/badprog/badprog-rust-cli-validate-program-arguments-and-handle-errors-with-an-enum-and-test-suite/tree/v1&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;https://github.com/badprog/badprog-rust-cli-validate-program-arguments-and-handle-errors-with-an-enum-and-test-suite/tree/v1&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;rustc 1.96.0 (ac68faa20 2026-05-25)&lt;/li&gt;
&lt;li&gt;Docker&lt;/li&gt;
&lt;li&gt;VSCode with the Dev Containers extension&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&#34;project-structure&#34;&gt;Project structure&lt;/h2&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;&#34;&gt;&lt;code class=&#34;language-text&#34; data-lang=&#34;text&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;.
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;|-- Cargo.lock
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;|-- Cargo.toml
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;|-- src
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;|   |-- core
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;|   |   `-- arg_analyzer.rs
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;|   |-- core.rs
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;|   |-- file
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;|   |   `-- bp.txt
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;|   |-- main.rs
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;|   |-- utils
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;|   |   `-- errors.rs
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;|   `-- utils.rs
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;`-- tests
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    `-- integration.rs
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h2 id=&#34;mainrs&#34;&gt;main.rs&lt;/h2&gt;
&lt;h3 id=&#34;main&#34;&gt;main()&lt;/h3&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;&#34;&gt;&lt;code class=&#34;language-rust&#34; data-lang=&#34;rust&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#66d9ef&#34;&gt;fn&lt;/span&gt; &lt;span style=&#34;color:#a6e22e&#34;&gt;main&lt;/span&gt;() -&amp;gt; &lt;span style=&#34;color:#a6e22e&#34;&gt;ExitCode&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;&lt;code&gt;main.rs&lt;/code&gt; is kept separate from the rest of the project on purpose.&lt;/p&gt;</description>
    </item>
    <item>
      <title>Rust - Crate - Grcov demo</title>
      <link>https://www.badprog.com/rust-crate-grcov-demo/</link>
      <pubDate>Sun, 23 Nov 2025 00:00:00 +0000</pubDate>
      <guid>https://www.badprog.com/rust-crate-grcov-demo/</guid>
      <description>&lt;p&gt;When your projects grow complex, ensuring that every single line of code is covered by your tests becomes critical.&lt;/p&gt;
&lt;p&gt;But how do you verify such a thing efficiently?&lt;/p&gt;
&lt;p&gt;Fortunately, the Rust ecosystem offers powerful crates for this purpose.&lt;/p&gt;
&lt;p&gt;This tutorial will guide you through setting up grcov for reliable code coverage.&lt;/p&gt;
&lt;h2 id=&#34;first-of-all&#34;&gt;First of all&lt;/h2&gt;
&lt;p&gt;The complete source code for this tutorial is available on GitHub:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&#34;https://github.com/badprog/badprog-grcov-demo&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;https://github.com/badprog/badprog-grcov-demo&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;All required software will be installed within our Docker environment (Dockerfile).&lt;/p&gt;</description>
    </item>
    <item>
      <title>Rust - Python binding - Setting up PyO3 crate with Maturin</title>
      <link>https://www.badprog.com/rust-python-binding-setting-up-pyo3-crate-with-maturin/</link>
      <pubDate>Sun, 02 Nov 2025 00:00:00 +0000</pubDate>
      <guid>https://www.badprog.com/rust-python-binding-setting-up-pyo3-crate-with-maturin/</guid>
      <description>&lt;p&gt;When you want to make large computations, using &lt;strong&gt;Python&lt;/strong&gt; may not be the best solution.&lt;/p&gt;
&lt;p&gt;By building a Python module from &lt;strong&gt;Rust&lt;/strong&gt;, we get the best of both worlds: Python productivity and Rust speed.&lt;/p&gt;
&lt;p&gt;In this tutorial we&amp;rsquo;ll cover the basic integration process using &lt;strong&gt;PyO3&lt;/strong&gt;, a Rust crate, for the bindings and &lt;strong&gt;Maturin&lt;/strong&gt;, a Python tool,for managing the dynamic library.&lt;/p&gt;
&lt;h2 id=&#34;first-of-all&#34;&gt;First of all&lt;/h2&gt;
&lt;p&gt;Github of this tutorial: &lt;a href=&#34;https://github.com/badprog/badprog-rust-binding-python-with-pyo3&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;https://github.com/badprog/badprog-rust-binding-python-with-pyo3&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;And versions used:&lt;/p&gt;</description>
    </item>
    <item>
      <title>Rust - Exploration - Adding memory and performance mode to the Vec struct</title>
      <link>https://www.badprog.com/rust-exploration-adding-memory-and-performance-mode-to-the-vec-struct/</link>
      <pubDate>Sun, 14 Sep 2025 00:00:00 +0000</pubDate>
      <guid>https://www.badprog.com/rust-exploration-adding-memory-and-performance-mode-to-the-vec-struct/</guid>
      <description>&lt;p&gt;The original Rust &lt;strong&gt;Vec&lt;/strong&gt; struct is already a fantastic growable array, easy to use.&lt;/p&gt;
&lt;p&gt;But what about adding a mode enabling to choose between memory and performance?&lt;/p&gt;
&lt;p&gt;Furthermore it&amp;rsquo;s a good way to understand why &lt;strong&gt;capacity&lt;/strong&gt; and &lt;strong&gt;len&lt;/strong&gt; aren&amp;rsquo;t the same thing.&lt;/p&gt;
&lt;p&gt;Let&amp;rsquo;s see that in this tutorial.&lt;/p&gt;
&lt;h2 id=&#34;first-of-all&#34;&gt;First of all&lt;/h2&gt;
&lt;p&gt;You can find the source code on my Github:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&#34;https://github.com/badprog/badprog_vec_plus&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;https://github.com/badprog/badprog_vec_plus&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&#34;memory-vs-performance&#34;&gt;Memory vs performance&lt;/h2&gt;
&lt;p&gt;Sometimes you have to make a choice: memory or performance.&lt;/p&gt;</description>
    </item>
  </channel>
</rss>
