<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
    <title>Bishonen&#x27;s Blog - Rust</title>
    <subtitle>Yet another software developemnt blog.</subtitle>
    <link rel="self" type="application/atom+xml" href="https://bshn.rs/tags/rust/atom.xml"/>
    <link rel="alternate" type="text/html" href="https://bshn.rs"/>
    <generator uri="https://www.getzola.org/">Zola</generator>
    <updated>2026-04-01T00:00:00+00:00</updated>
    <id>https://bshn.rs/tags/rust/atom.xml</id>
    <entry xml:lang="en">
        <title>Cancellation Safety in different Rust AsyncRuntimes</title>
        <published>2026-04-01T00:00:00+00:00</published>
        <updated>2026-04-01T00:00:00+00:00</updated>
        
        <author>
          <name>
            Nikita Bishonen
          </name>
        </author>
        
        <link rel="alternate" type="text/html" href="https://bshn.rs/blog/2026-04-01-cancellation-safety-in-async-rust-runtimes/"/>
        <id>https://bshn.rs/blog/2026-04-01-cancellation-safety-in-async-rust-runtimes/</id>
        
        <content type="html" xml:base="https://bshn.rs/blog/2026-04-01-cancellation-safety-in-async-rust-runtimes/">&lt;p&gt;To get more context I recommend my dear friends to read or watch a great &lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;sunshowers.io&#x2F;posts&#x2F;cancelling-async-rust&#x2F;&quot;&gt;talk&lt;&#x2F;a&gt; made by Rain,
where they&#x2F;she described her attitude to “cancellation safety” in async Rust.&lt;&#x2F;p&gt;
&lt;p&gt;TL;DR for those who prefer to hack and not to read:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;git clone https:&#x2F;&#x2F;gitlab.com&#x2F;blogging1&#x2F;cancellation-safety&lt;&#x2F;code&gt;;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;code&gt;cargo test --no-fail-fast --workspace&lt;&#x2F;code&gt; (or your runtime of choice by &lt;code&gt;-p cancel_%RUNTIME%&lt;&#x2F;code&gt; intsead of &lt;code&gt;--workspace&lt;&#x2F;code&gt;);&lt;&#x2F;li&gt;
&lt;li&gt;Read errors and tests;&lt;&#x2F;li&gt;
&lt;li&gt;Read &lt;code&gt;lib.rs&lt;&#x2F;code&gt; for runtimes you are interested in;&lt;&#x2F;li&gt;
&lt;li&gt;Play with the code to fix all the tests;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h1 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;&lt;i class=&quot;icon&quot;&gt;&lt;&#x2F;i&gt;&lt;&#x2F;a&gt;
The Problem&lt;&#x2F;h1&gt;
&lt;p&gt;“Cancellation Safety” usually means absence of unexpected “effects” when sequence of asynchronous operations has been stopped
before it reaches the final state.
I can think of a &lt;code&gt;panic!&lt;&#x2F;code&gt; in the middle of a synchronous sequence of operations as an analogy.&lt;&#x2F;p&gt;
&lt;p&gt;The fundamental principles of it tied to the &lt;code&gt;Future&lt;&#x2F;code&gt; trait and to the implementation details of the Asynchrnous Runtime.
Here, I will like to experiment in an attempt to find common patterns and differences in how Tokio, smol and glommio handle cancellations.&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;Future::poll&lt;&#x2F;code&gt; is a key aspect here, as at compile-time every &lt;code&gt;Future&lt;&#x2F;code&gt; implementation is a state-machine, that represents a sequence of operations,
“cancellation” means that &lt;strong&gt;Runtime&lt;&#x2F;strong&gt; (Reactor, Event Loop or Scheduler) will stop polling this state-machine and (hopefully) destroy it’s state;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;code&gt;Pin&lt;&#x2F;code&gt; and &lt;code&gt;Unpin&lt;&#x2F;code&gt; have their own places, as &lt;code&gt;!Unpin&lt;&#x2F;code&gt; types have to keep additional guarantees to be considered “safe” (mitigate “effects”);&lt;&#x2F;li&gt;
&lt;li&gt;&lt;code&gt;Waker&lt;&#x2F;code&gt; implementation may play a big role in handling “cancellation” requests;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h1 id=&quot;the-example&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#the-example&quot; aria-label=&quot;Anchor link for: the-example&quot;&gt;&lt;i class=&quot;icon&quot;&gt;&lt;&#x2F;i&gt;&lt;&#x2F;a&gt;
The Example&lt;&#x2F;h1&gt;
&lt;p&gt;In our adventure we will go join our strong and proud friends who lives in Moria:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color-scheme: light dark; color: light-dark(#C6D0F5, #565869); background-color: light-dark(#303446, #FAFBFC);&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#CA9EE6, #F767BB);&quot;&gt;pub&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#CA9EE6, #F767BB);&quot;&gt; async&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#CA9EE6, #F767BB);&quot;&gt; fn&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#8CAAEE, #09A1ED);font-style: italic;&quot;&gt; mine_with_tool&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#99D1DB, #ADB1C2);&quot;&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#E5C890, #13BBB7);font-style: italic;&quot;&gt;F&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#EF9F76, #2DAE58);&quot;&gt; FT&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#99D1DB, #ADB1C2);&quot;&gt;&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#EA999C, #565869);&quot;&gt;dwarf&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt; &amp;amp;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#CA9EE6, #F767BB);&quot;&gt;mut&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#E5C890, #13BBB7);font-style: italic;&quot;&gt; Dwarf&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#CA9EE6, #F767BB);&quot;&gt; mut&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#EA999C, #565869);&quot;&gt; pickaxe&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#E5C890, #13BBB7);font-style: italic;&quot;&gt; F&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt; ...&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#CA9EE6, #F767BB);&quot;&gt;    let&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#CA9EE6, #F767BB);&quot;&gt; mut&lt;&#x2F;span&gt;&lt;span&gt; bag&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#E5C890, #13BBB7);font-style: italic;&quot;&gt; Bag&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#E5C890, #13BBB7);font-style: italic;&quot;&gt; Vec&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#8CAAEE, #09A1ED);font-style: italic;&quot;&gt;new&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#CA9EE6, #F767BB);&quot;&gt;    for&lt;&#x2F;span&gt;&lt;span&gt; i&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#CA9EE6, #F767BB);&quot;&gt; in&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#EF9F76, #FF5C57);&quot;&gt; 0&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt;..&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#EF9F76, #2DAE58);&quot;&gt;MAX_ALLOWED_SHIFTS&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8CAAEE, #09A1ED);font-style: italic;&quot;&gt;        pickaxe&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#CA9EE6, #F767BB);&quot;&gt;await&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt;        ...&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8CAAEE, #09A1ED);font-style: italic;&quot;&gt;        println!&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#A6D189, #ADB1C2);&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#A6D189, #CF9C00);&quot;&gt;Here at the Gates the king AWAITS&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#A6D189, #ADB1C2);&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt;        ...&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        bag&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#8CAAEE, #09A1ED);font-style: italic;&quot;&gt;push&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#E5C890, #565869);&quot;&gt;Ferrum&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#E5C890, #13BBB7);font-style: italic;&quot;&gt;Dirty&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;    }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    dwarf&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt;.&lt;&#x2F;span&gt;&lt;span&gt;bag &lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt;=&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#E5C890, #565869);font-style: italic;&quot;&gt; Some&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;(&lt;&#x2F;span&gt;&lt;span&gt;bag&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;so our asynchronous process will imitate dwarf working in mines. The &lt;code&gt;mine_with_tool&lt;&#x2F;code&gt; itself is a composite &lt;code&gt;trait Future&lt;&#x2F;code&gt; implementation,
that internally do &lt;code&gt;MAX_ALLOWED_SHIFTS&lt;&#x2F;code&gt; steps to reach it’s final (completed) state.
In simple terms, line 4: &lt;code&gt;pickaxe().await;&lt;&#x2F;code&gt; will be a point when state-machine polled and make progress. It means that this exact spot
may be used to “cancel” the execution.&lt;&#x2F;p&gt;
&lt;p&gt;How it loolks at high-level intermediate representation (code cleaned to make it less verbose, please run &lt;code&gt;cargo +nightly rustc -- -Z unpretty=hir&lt;&#x2F;code&gt;
inside &lt;code&gt;moria&lt;&#x2F;code&gt; folder to see the full output):&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color-scheme: light dark; color: light-dark(#C6D0F5, #565869); background-color: light-dark(#303446, #FAFBFC);&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#CA9EE6, #F767BB);&quot;&gt;async&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#CA9EE6, #F767BB);&quot;&gt; fn&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#8CAAEE, #09A1ED);font-style: italic;&quot;&gt; mine_with_tool&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#99D1DB, #ADB1C2);&quot;&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#E5C890, #13BBB7);font-style: italic;&quot;&gt;F&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#EF9F76, #2DAE58);&quot;&gt; FT&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#99D1DB, #ADB1C2);&quot;&gt;&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#EA999C, #565869);&quot;&gt;dwarf&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt; &amp;amp;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;&amp;#39;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#8CAAEE, #565869);font-style: italic;&quot;&gt;_&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#CA9EE6, #F767BB);&quot;&gt; mut&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#E5C890, #13BBB7);font-style: italic;&quot;&gt; Dwarf&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#EA999C, #565869);&quot;&gt; pickaxe&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#E5C890, #13BBB7);font-style: italic;&quot;&gt; F&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt; -&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);font-style: italic;&quot;&gt; &#x2F;*&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);font-style: italic;&quot;&gt;impl Trait&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);font-style: italic;&quot;&gt;*&#x2F;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#CA9EE6, #F767BB);&quot;&gt;    where&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#E5C890, #13BBB7);font-style: italic;&quot;&gt; F&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#8CAAEE, #09A1ED);font-style: italic;&quot;&gt; FnMut&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt; -&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#EF9F76, #2DAE58);&quot;&gt; FT&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#EF9F76, #2DAE58);&quot;&gt; FT&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#E5C890, #565869);&quot;&gt; std&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#E5C890, #565869);&quot;&gt;future&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#E5C890, #13BBB7);font-style: italic;&quot;&gt;Future&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt; |&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#CA9EE6, #F767BB);&quot;&gt;mut&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#EA999C, #565869);&quot;&gt; _task_context&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#E5C890, #13BBB7);font-style: italic;&quot;&gt; ResumeTy&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt;|&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;{&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt;    ...&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#CA9EE6, #F767BB);&quot;&gt;    let&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#CA9EE6, #F767BB);&quot;&gt; mut&lt;&#x2F;span&gt;&lt;span&gt; bag&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#E5C890, #13BBB7);font-style: italic;&quot;&gt; Bag&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#E5C890, #13BBB7);font-style: italic;&quot;&gt; Vec&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#8CAAEE, #09A1ED);font-style: italic;&quot;&gt;new&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;    {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt;        ...&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#CA9EE6, #F767BB);&quot;&gt;        loop&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#CA9EE6, #F767BB);&quot;&gt;            match&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#8CAAEE, #09A1ED);font-style: italic;&quot;&gt; next&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt;&amp;amp;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#CA9EE6, #F767BB);&quot;&gt;mut&lt;&#x2F;span&gt;&lt;span&gt; iter&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#E5C890, #565869);font-style: italic;&quot;&gt;                None&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt; {&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;}&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt; =&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#CA9EE6, #F767BB);&quot;&gt; break&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#E5C890, #565869);font-style: italic;&quot;&gt;                Some&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt; {&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#EF9F76, #FF5C57);&quot;&gt;  0&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt;:&lt;&#x2F;span&gt;&lt;span&gt; i&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt; }&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt; =&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#CA9EE6, #F767BB);&quot;&gt;                    match&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#8CAAEE, #09A1ED);font-style: italic;&quot;&gt; into_future&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#8CAAEE, #09A1ED);font-style: italic;&quot;&gt;pickaxe&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#CA9EE6, #F767BB);&quot;&gt;                        mut&lt;&#x2F;span&gt;&lt;span&gt; __awaitee&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt; =&amp;gt;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#CA9EE6, #F767BB);&quot;&gt;                            loop&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#CA9EE6, #F767BB);&quot;&gt;                                match&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#CA9EE6, #F767BB);&quot;&gt; unsafe&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8CAAEE, #09A1ED);font-style: italic;&quot;&gt;                                        poll&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#8CAAEE, #09A1ED);font-style: italic;&quot;&gt;new_unchecked&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt;&amp;amp;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#CA9EE6, #F767BB);&quot;&gt;mut&lt;&#x2F;span&gt;&lt;span&gt; __awaitee&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8CAAEE, #09A1ED);font-style: italic;&quot;&gt;                                            get_context&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;(&lt;&#x2F;span&gt;&lt;span&gt;_task_context&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;                                    }&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#E5C890, #13BBB7);font-style: italic;&quot;&gt;                                    Ready&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt; {&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#EF9F76, #FF5C57);&quot;&gt;  0&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt;:&lt;&#x2F;span&gt;&lt;span&gt; result&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt; }&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt; =&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#CA9EE6, #F767BB);&quot;&gt; break&lt;&#x2F;span&gt;&lt;span&gt; result&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#E5C890, #13BBB7);font-style: italic;&quot;&gt;                                    Pending&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt; {&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;}&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt; =&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt; {&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt; }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;                                }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                                _task_context&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt; (&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#CA9EE6, #F767BB);&quot;&gt;yield&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt; (&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;                            }&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;                    }&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt;                    ...&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                    bag&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#8CAAEE, #09A1ED);font-style: italic;&quot;&gt;push&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#E5C890, #565869);&quot;&gt;Ferrum&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#E5C890, #13BBB7);font-style: italic;&quot;&gt;Dirty&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;                }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;            }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;        }&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt;        ...&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    dwarf&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt;.&lt;&#x2F;span&gt;&lt;span&gt;bag &lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt;=&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#E5C890, #565869);font-style: italic;&quot;&gt; Some&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;(&lt;&#x2F;span&gt;&lt;span&gt;bag&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt;    ...&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;alomost no “async” magic anymore, we have a &lt;code&gt;loop&lt;&#x2F;code&gt;, an &lt;code&gt;unsafe&lt;&#x2F;code&gt; and a &lt;code&gt;yield ()&lt;&#x2F;code&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;Let’s jump to a “safety” aspect. In my humble opinion, if there is no &lt;code&gt;unsafe&lt;&#x2F;code&gt; code and Rust compiler is pleased, the operation is safe.
Yet, it doesn’t mean that the program behaves the way programmers may expect it to behave.&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color-scheme: light dark; color: light-dark(#C6D0F5, #565869); background-color: light-dark(#303446, #FAFBFC);&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt;...&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#CA9EE6, #F767BB);&quot;&gt; fn&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#8CAAEE, #09A1ED);font-style: italic;&quot;&gt; mine_with_tool&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#99D1DB, #ADB1C2);&quot;&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt;...&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#99D1DB, #ADB1C2);&quot;&gt;&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#EA999C, #565869);&quot;&gt;dwarf&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt; &amp;amp;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#CA9EE6, #F767BB);&quot;&gt;mut&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#E5C890, #13BBB7);font-style: italic;&quot;&gt; Dwarf&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt; ...&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#CA9EE6, #F767BB);&quot;&gt;    let&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#CA9EE6, #F767BB);&quot;&gt; mut&lt;&#x2F;span&gt;&lt;span&gt; bag&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#E5C890, #13BBB7);font-style: italic;&quot;&gt; Bag&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#E5C890, #13BBB7);font-style: italic;&quot;&gt; Vec&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#8CAAEE, #09A1ED);font-style: italic;&quot;&gt;new&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt;        ...&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        bag&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#8CAAEE, #09A1ED);font-style: italic;&quot;&gt;push&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#E5C890, #565869);&quot;&gt;Ferrum&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#E5C890, #13BBB7);font-style: italic;&quot;&gt;Dirty&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt;        ...&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    dwarf&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt;.&lt;&#x2F;span&gt;&lt;span&gt;bag &lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt;=&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#E5C890, #565869);font-style: italic;&quot;&gt; Some&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;(&lt;&#x2F;span&gt;&lt;span&gt;bag&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;try to spot yourself what makes this &lt;code&gt;trait Future&lt;&#x2F;code&gt; implementation be named “cancellation not-safe” (I prefer not-safe here, as &lt;strong&gt;unsafe&lt;&#x2F;strong&gt; is important
but unrelated Rust term).&lt;&#x2F;p&gt;
&lt;p&gt;The answer lies in how this asynchronous operation stores it’s state and tracks the own progress. Both things happen internally, while holding a mutable
reference to the state given by the caller side &lt;code&gt;dwarf: &amp;amp;mut Dwarf&lt;&#x2F;code&gt;. Let’s see two examples of this feature usage inside &lt;code&gt;smol&lt;&#x2F;code&gt; runtime to see why
such implementation can give a surprises to caller if cancelled.&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color-scheme: light dark; color: light-dark(#C6D0F5, #565869); background-color: light-dark(#303446, #FAFBFC);&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#CA9EE6, #F767BB);&quot;&gt;pub&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#CA9EE6, #F767BB);&quot;&gt; async&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#CA9EE6, #F767BB);&quot;&gt; fn&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#8CAAEE, #09A1ED);font-style: italic;&quot;&gt; work&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#EA999C, #565869);&quot;&gt;dwarf&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt; &amp;amp;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#CA9EE6, #F767BB);&quot;&gt;mut&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#E5C890, #13BBB7);font-style: italic;&quot;&gt; Dwarf&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#CA9EE6, #F767BB);&quot;&gt;    super&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#8CAAEE, #09A1ED);font-style: italic;&quot;&gt;mine&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;(&lt;&#x2F;span&gt;&lt;span&gt;dwarf&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt;        .&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#8CAAEE, #09A1ED);font-style: italic;&quot;&gt;or&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#CA9EE6, #F767BB);&quot;&gt;async&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#E5C890, #565869);&quot;&gt;            Timer&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#8CAAEE, #09A1ED);font-style: italic;&quot;&gt;after&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#EF9F76, #2DAE58);&quot;&gt;HALF_SHIFT&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#CA9EE6, #F767BB);&quot;&gt;await&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;        }&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt;        .&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#CA9EE6, #F767BB);&quot;&gt;await&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Dwarf works here half of the shift time and made some progress.
But when we go to see run the test:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color-scheme: light dark; color: light-dark(#C6D0F5, #565869); background-color: light-dark(#303446, #FAFBFC);&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#CA9EE6, #F767BB);&quot;&gt;let&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#CA9EE6, #F767BB);&quot;&gt; mut&lt;&#x2F;span&gt;&lt;span&gt; dwallin&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#E5C890, #13BBB7);font-style: italic;&quot;&gt; Dwarf&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#8CAAEE, #09A1ED);font-style: italic;&quot;&gt;new&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#E5C890, #565869);&quot;&gt;Name&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#E5C890, #13BBB7);font-style: italic;&quot;&gt;Dwalin&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#E5C890, #565869);&quot;&gt;timeout&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#8CAAEE, #09A1ED);font-style: italic;&quot;&gt;work&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt;&amp;amp;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#CA9EE6, #F767BB);&quot;&gt;mut&lt;&#x2F;span&gt;&lt;span&gt; dwallin&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#CA9EE6, #F767BB);&quot;&gt;await&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);font-style: italic;&quot;&gt;&#x2F;&#x2F;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);font-style: italic;&quot;&gt; Bag is empty, but I heard the song!&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8CAAEE, #09A1ED);font-style: italic;&quot;&gt;assert!&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;(&lt;&#x2F;span&gt;&lt;span&gt;dwallin&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt;.&lt;&#x2F;span&gt;&lt;span&gt;bag&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#8CAAEE, #09A1ED);font-style: italic;&quot;&gt;is_some&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;we see it’s assertation that some work has been done fails. The reason is that the timeout happened before Dwallin was able to finish
his work and all what he put into the “bag” in internal state of the state-machine has been dropped once we cancel the operation at the
first poll after timeout. (Try to change &lt;code&gt;Timer::after(HALF_SHIFT)&lt;&#x2F;code&gt; to use &lt;code&gt;FULL_SHIFT&lt;&#x2F;code&gt; and see if it will help 😉).
So this is what we may say a cancellation not-safe (or incorrect as Rain proposed) implementation of asynchronous operation that leads to
a behaviour that we would not expect.&lt;&#x2F;p&gt;
&lt;p&gt;More interesting (and closer to real-world) can happen if we make our &lt;code&gt;Future&lt;&#x2F;code&gt; implementation more complex and “dirty”:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color-scheme: light dark; color: light-dark(#C6D0F5, #565869); background-color: light-dark(#303446, #FAFBFC);&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#CA9EE6, #F767BB);&quot;&gt;pub&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#CA9EE6, #F767BB);&quot;&gt; async&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#CA9EE6, #F767BB);&quot;&gt; fn&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#8CAAEE, #09A1ED);font-style: italic;&quot;&gt; work&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#EA999C, #565869);&quot;&gt;dwarf&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt; &amp;amp;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#E5C890, #13BBB7);font-style: italic;&quot;&gt;Mutex&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#99D1DB, #ADB1C2);&quot;&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#E5C890, #13BBB7);font-style: italic;&quot;&gt;Dwarf&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#99D1DB, #ADB1C2);&quot;&gt;&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#CA9EE6, #F767BB);&quot;&gt;    let&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#CA9EE6, #F767BB);&quot;&gt; mut&lt;&#x2F;span&gt;&lt;span&gt; dwarf_guard&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; dwarf&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#8CAAEE, #09A1ED);font-style: italic;&quot;&gt;lock&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#CA9EE6, #F767BB);&quot;&gt;await&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#CA9EE6, #F767BB);&quot;&gt;    let&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#CA9EE6, #F767BB);&quot;&gt; mut&lt;&#x2F;span&gt;&lt;span&gt; old_bag&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; dwarf_guard&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt;.&lt;&#x2F;span&gt;&lt;span&gt;bag&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#8CAAEE, #09A1ED);font-style: italic;&quot;&gt;take&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#8CAAEE, #09A1ED);font-style: italic;&quot;&gt;unwrap&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8CAAEE, #09A1ED);font-style: italic;&quot;&gt;    timeout&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#EF9F76, #2DAE58);&quot;&gt;HALF_SHIFT&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#CA9EE6, #F767BB);&quot;&gt; super&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#8CAAEE, #09A1ED);font-style: italic;&quot;&gt;mine&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt;&amp;amp;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#CA9EE6, #F767BB);&quot;&gt;mut&lt;&#x2F;span&gt;&lt;span&gt; dwarf_guard&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt;        .&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#CA9EE6, #F767BB);&quot;&gt;await&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt;        .&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#8CAAEE, #09A1ED);font-style: italic;&quot;&gt;err&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt;        .&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#8CAAEE, #09A1ED);font-style: italic;&quot;&gt;unwrap&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#CA9EE6, #F767BB);&quot;&gt;    if&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#CA9EE6, #F767BB);&quot;&gt; let&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#E5C890, #565869);font-style: italic;&quot;&gt; Some&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;(&lt;&#x2F;span&gt;&lt;span&gt;new_bag&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; dwarf_guard&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt;.&lt;&#x2F;span&gt;&lt;span&gt;bag&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#8CAAEE, #09A1ED);font-style: italic;&quot;&gt;as_mut&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        new_bag&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#8CAAEE, #09A1ED);font-style: italic;&quot;&gt;append&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt;&amp;amp;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#CA9EE6, #F767BB);&quot;&gt;mut&lt;&#x2F;span&gt;&lt;span&gt; old_bag&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;    }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;I know, Dwarfs are not good at asynchronous programming, but it illustrates the problem really good.
Our operation takes state out of input, holds it internally, than accumulates with own computation results and give it back.&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color-scheme: light dark; color: light-dark(#C6D0F5, #565869); background-color: light-dark(#303446, #FAFBFC);&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;│  ┌────────────┐    ┌──────────────┐    ┌───────┐    ┌─────────────┐    ┌──────────────┐│&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;│  │ Lock Mutex │ -&amp;gt; │ Take Old Bag │ -&amp;gt; │ Mine  │ -&amp;gt; │Take New Bag │ -&amp;gt; │  Merge Bags  ││&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;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;│-&amp;gt;│Release Lock│ -&amp;gt; │    End       │                                                    │&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;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 issue is that operation is “safe” from the mutex point of view, as we know noone else will change the state of the &lt;code&gt;dwarf&lt;&#x2F;code&gt;.
Yet it is not “correct” if we cancel &lt;code&gt;super::mine&lt;&#x2F;code&gt; before it fully completes. &lt;code&gt;old_bag&lt;&#x2F;code&gt; will be dropped as &lt;code&gt;new_bag&lt;&#x2F;code&gt; will not
be a thing (&lt;code&gt;dwarf_guard.bag.as_mut()&lt;&#x2F;code&gt; is &lt;code&gt;None&lt;&#x2F;code&gt;). As &lt;code&gt;work&lt;&#x2F;code&gt; future implementation is a composition of itself with
&lt;code&gt;super::mine&lt;&#x2F;code&gt; future implementation and &lt;code&gt;timeout&lt;&#x2F;code&gt; future implementation, our logic becomes broken, because both futures
have incorrect behavior from the system perspective (while it is totally expected, valid and &lt;strong&gt;safe&lt;&#x2F;strong&gt; Rust code imho).&lt;&#x2F;p&gt;
&lt;h1 id=&quot;the-comparison&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#the-comparison&quot; aria-label=&quot;Anchor link for: the-comparison&quot;&gt;&lt;i class=&quot;icon&quot;&gt;&lt;&#x2F;i&gt;&lt;&#x2F;a&gt;
The Comparison&lt;&#x2F;h1&gt;
&lt;h2 id=&quot;runtime-architecture-overview&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#runtime-architecture-overview&quot; aria-label=&quot;Anchor link for: runtime-architecture-overview&quot;&gt;&lt;i class=&quot;icon&quot;&gt;&lt;&#x2F;i&gt;&lt;&#x2F;a&gt;
Runtime Architecture Overview&lt;&#x2F;h2&gt;
&lt;h3 id=&quot;tokio-the-industry-standard&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#tokio-the-industry-standard&quot; aria-label=&quot;Anchor link for: tokio-the-industry-standard&quot;&gt;&lt;i class=&quot;icon&quot;&gt;&lt;&#x2F;i&gt;&lt;&#x2F;a&gt;
Tokio: The Industry Standard&lt;&#x2F;h3&gt;
&lt;p&gt;Tokio represents the most widely used async runtime in the Rust ecosystem. It’s architecture focuses on:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Multi-threaded thread pool executor&lt;&#x2F;strong&gt; for CPU-bound work;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Completer-based I&#x2F;O model&lt;&#x2F;strong&gt; for non-blocking operations;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Robust task cancellation&lt;&#x2F;strong&gt; with explicit abort capabilities;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Comprehensive ecosystem&lt;&#x2F;strong&gt; of supporting libraries;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;Key characteristics:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;Built-in cancellation tokens via &lt;code&gt;tokio_util::sync::CancellationToken&lt;&#x2F;code&gt;;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;code&gt;tokio::spawn()&lt;&#x2F;code&gt; for creating tasks;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;code&gt;tokio::select!&lt;&#x2F;code&gt; for concurrent operations;&lt;&#x2F;li&gt;
&lt;li&gt;Built-in timeout utilities;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h3 id=&quot;smol-the-minimal-approach&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#smol-the-minimal-approach&quot; aria-label=&quot;Anchor link for: smol-the-minimal-approach&quot;&gt;&lt;i class=&quot;icon&quot;&gt;&lt;&#x2F;i&gt;&lt;&#x2F;a&gt;
smol: The Minimal Approach&lt;&#x2F;h3&gt;
&lt;p&gt;smol takes a radically different approach with:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Single-threaded executor&lt;&#x2F;strong&gt; by default;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Simplified API&lt;&#x2F;strong&gt; focusing on essential async operations;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;No own runtime&lt;&#x2F;strong&gt; - it brings to you existing executors;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Lightweight dependencies&lt;&#x2F;strong&gt; and minimal overhead;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;Key characteristics:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;smol::spawn()&lt;&#x2F;code&gt; for task creation;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;code&gt;smol::Timer&lt;&#x2F;code&gt; for async delays;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;code&gt;smol::channel&lt;&#x2F;code&gt; for message passing;&lt;&#x2F;li&gt;
&lt;li&gt;No explicit cancellation tokens in core API;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h3 id=&quot;glommio-i-o-performance-focus&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#glommio-i-o-performance-focus&quot; aria-label=&quot;Anchor link for: glommio-i-o-performance-focus&quot;&gt;&lt;i class=&quot;icon&quot;&gt;&lt;&#x2F;i&gt;&lt;&#x2F;a&gt;
Glommio: I&#x2F;O Performance Focus&lt;&#x2F;h3&gt;
&lt;p&gt;Glommio represents a specialized runtime designed for high-performance I&#x2F;O workloads:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Local executor model&lt;&#x2F;strong&gt; with share-nothing-first approach;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;I&#x2F;O-optimized&lt;&#x2F;strong&gt; with dedicated thread-per-core architecture;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;No shared memory&lt;&#x2F;strong&gt; between threads by default;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Local-only futures&lt;&#x2F;strong&gt; for better cache locality;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;Key characteristics:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;glommio::LocalExecutor&lt;&#x2F;code&gt; for single-threaded execution;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;code&gt;glommio::spawn_local()&lt;&#x2F;code&gt; for tasks;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;code&gt;glommio::timer&lt;&#x2F;code&gt; for delays;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;code&gt;glommio::channels::local_channel&lt;&#x2F;code&gt; for local-only communication;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h2 id=&quot;cancellation-scenarios-analysis&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#cancellation-scenarios-analysis&quot; aria-label=&quot;Anchor link for: cancellation-scenarios-analysis&quot;&gt;&lt;i class=&quot;icon&quot;&gt;&lt;&#x2F;i&gt;&lt;&#x2F;a&gt;
Cancellation Scenarios Analysis&lt;&#x2F;h2&gt;
&lt;p&gt;Most of the scenarios are work similar across runtimes:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;Simple Drop Cancellation: Use explicit drop mechanisms for futures and all runtimes show partial work loss when futures are dropped unexpectedly;&lt;&#x2F;li&gt;
&lt;li&gt;Timeout Cancellation: All provide explicit timeout handling and tests show that timeout doesn’t preserve partial results;&lt;&#x2F;li&gt;
&lt;li&gt;Mutex-Protected Operations: &lt;code&gt;tokio::sync::Mutex&lt;&#x2F;code&gt;, &lt;code&gt;smol::lock::Mutex&lt;&#x2F;code&gt;, &lt;code&gt;glommio::sync::RwLock&lt;&#x2F;code&gt; all share similar semantics,
while tests demonstrate lock holding patterns and cleanup works the way they should, while we still loss our progress;&lt;&#x2F;li&gt;
&lt;li&gt;Channel-Based Communication: very similar, only with locality nuances;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;But some of them have nuances:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;Macroses like &lt;code&gt;select!&lt;&#x2F;code&gt; and Concurrent Operations with Cancellation Tokens are specific to &lt;code&gt;Tokio&lt;&#x2F;code&gt; runtime ecosystem, which seems to be not a good
or bad things. As Rain described in her talk and what I heard from other developers, such macroses sometimes are totally banned in projects due to
their non-explicit nature (and for example replaced with &lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;docs.rs&#x2F;futures-concurrency&#x2F;latest&#x2F;futures_concurrency&#x2F;&quot;&gt;futures_concurrency&lt;&#x2F;a&gt;);&lt;&#x2F;li&gt;
&lt;li&gt;“Explicit” Cancel:
&lt;ul&gt;
&lt;li&gt;in &lt;code&gt;Tokio&lt;&#x2F;code&gt; is done via &lt;code&gt;JoinHandle::abort&lt;&#x2F;code&gt; and dropping handle will not cause a cancellation, &lt;code&gt;nahdle.await&lt;&#x2F;code&gt; will return an error &lt;code&gt;JoinError&lt;&#x2F;code&gt;
if future implementation was cancelled (or normal result if it finished), also worth noting that &lt;code&gt;spawn_blocking&lt;&#x2F;code&gt; tasks are not “cancellable” because they are not asynchronous (but it will prevent the task from starting if it wasn’t yet!);&lt;&#x2F;li&gt;
&lt;li&gt;in &lt;code&gt;smol&lt;&#x2F;code&gt; you can call &lt;code&gt;Task::cancel&lt;&#x2F;code&gt; and wait for the cancellation (which may return &lt;code&gt;Some&lt;&#x2F;code&gt; if it finished), it is similar to dropping the future implementation;&lt;&#x2F;li&gt;
&lt;li&gt;in &lt;code&gt;glommio&lt;&#x2F;code&gt; approach is also identical to &lt;code&gt;smol&lt;&#x2F;code&gt; with &lt;code&gt;Option&lt;&#x2F;code&gt; being returned on awaiting of the cancellateion;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;From the documentation side this topic is only covered in &lt;code&gt;Tokio&lt;&#x2F;code&gt; API docs, &lt;code&gt;smol&lt;&#x2F;code&gt; has one small (ha-ha) note on this matter:&lt;strong&gt;Note that canceling a task actually wakes it and reschedules one last time. Then, the executor can destroy the task by simply dropping its Runnable or by invoking run().&lt;&#x2F;strong&gt;, while in &lt;code&gt;glommio&lt;&#x2F;code&gt; I was unable to find mentioning cancellation safety or correctness. I think there are two factors why it is, what it is:&lt;&#x2F;p&gt;
&lt;ol&gt;
&lt;li&gt;Tokio has much bigger popularity and usage, though have more resources to add documentation;&lt;&#x2F;li&gt;
&lt;li&gt;Tokio has much “dangerous” API and internal executor model that makes it easier to run into cancellation safety issues using it;&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;p&gt;I hope you found something new in this blog post, write your thoughts in the comments and check additional resources if you want to.&lt;&#x2F;p&gt;
&lt;h1 id=&quot;additional-resources-and-sources-of-inspiration&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#additional-resources-and-sources-of-inspiration&quot; aria-label=&quot;Anchor link for: additional-resources-and-sources-of-inspiration&quot;&gt;&lt;i class=&quot;icon&quot;&gt;&lt;&#x2F;i&gt;&lt;&#x2F;a&gt;
Additional Resources and Sources of inspiration&lt;&#x2F;h1&gt;
&lt;ul&gt;
&lt;li&gt;Great Rain’s &lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;sunshowers.io&#x2F;posts&#x2F;cancelling-async-rust&#x2F;&quot;&gt;talk&lt;&#x2F;a&gt;;&lt;&#x2F;li&gt;
&lt;li&gt;Current comment on &lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;rust-lang&#x2F;async-book&#x2F;issues&#x2F;227#issuecomment-2496234560&quot;&gt;state of the book section&lt;&#x2F;a&gt; about cancellation safety;&lt;&#x2F;li&gt;
&lt;li&gt;Tokio Docs on &lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;docs.rs&#x2F;tokio&#x2F;latest&#x2F;tokio&#x2F;sync&#x2F;mpsc&#x2F;struct.Sender.html#cancel-safety&quot;&gt;that matter&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;docs.rs&#x2F;futures-concurrency&#x2F;latest&#x2F;futures_concurrency&#x2F;&quot;&gt;Sructured Concurrency lib&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>Rust Types - Taxonomy</title>
        <published>2025-02-19T00:00:00+00:00</published>
        <updated>2025-02-19T00:00:00+00:00</updated>
        
        <author>
          <name>
            Nikita Bishonen
          </name>
        </author>
        
        <link rel="alternate" type="text/html" href="https://bshn.rs/blog/2025-02-19-rust-types-taxonomy/"/>
        <id>https://bshn.rs/blog/2025-02-19-rust-types-taxonomy/</id>
        
        <content type="html" xml:base="https://bshn.rs/blog/2025-02-19-rust-types-taxonomy/">&lt;p&gt;Hello! Today I’m sharing my thoughts on type taxonomy in Rust. This is the first version of the taxonomy and post, and I’d be grateful for any ideas to improve it.&lt;&#x2F;p&gt;
&lt;h1 id=&quot;taxonomy&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#taxonomy&quot; aria-label=&quot;Anchor link for: taxonomy&quot;&gt;&lt;i class=&quot;icon&quot;&gt;&lt;&#x2F;i&gt;&lt;&#x2F;a&gt;
Taxonomy&lt;&#x2F;h1&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Taxonomy&lt;&#x2F;strong&gt; (from Ancient Greek τάξις — arrangement, order and νόμος — law) — the doctrine of principles and practice of classification and systematization of complex organized hierarchically related entities.&lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
&lt;p&gt;I wanted to decorate my study with a graphical illustration of the “taxonomy” of the data type system, similar to what Rust uses. Unfortunately, my searches didn’t yield the desired result, so I decided to create my own illustration and share it with you in this publication.&lt;&#x2F;p&gt;
&lt;h1 id=&quot;types&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#types&quot; aria-label=&quot;Anchor link for: types&quot;&gt;&lt;i class=&quot;icon&quot;&gt;&lt;&#x2F;i&gt;&lt;&#x2F;a&gt;
Types&lt;&#x2F;h1&gt;
&lt;h2 id=&quot;theories&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#theories&quot; aria-label=&quot;Anchor link for: theories&quot;&gt;&lt;i class=&quot;icon&quot;&gt;&lt;&#x2F;i&gt;&lt;&#x2F;a&gt;
Theories&lt;&#x2F;h2&gt;
&lt;p&gt;There are many theories, some of which are conditioned by the history of the development of computer science, others have real practical value and theoretical justification. I’ll provide links to two popular theories from both categories:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Intuitionistic_type_theory&quot;&gt;Intuitionistic type theory&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;ryansandford.github.io&#x2F;projects&#x2F;hott&#x2F;&quot;&gt;Homotopy Type Theory&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;But I won’t try to delve into details since I understand them with difficulty, let alone the ability to explain them.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;img src=&quot;&#x2F;images&#x2F;2025_02_19_tax_hott.png&quot; alt=&quot;HoTT&quot; loading=&quot;lazy&quot; decoding=&quot;async&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;h2 id=&quot;&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#&quot; aria-label=&quot;Anchor link for: &quot;&gt;&lt;i class=&quot;icon&quot;&gt;&lt;&#x2F;i&gt;&lt;&#x2F;a&gt;
Type Theory and Rust&lt;&#x2F;h2&gt;
&lt;p&gt;The main question I was looking for an answer to is the type theory behind Rust and its projection onto the types we use when writing Rust code.&lt;&#x2F;p&gt;
&lt;p&gt;I’m not the only one asking this question: https:&#x2F;&#x2F;users.rust-lang.org&#x2F;t&#x2F;practical-intro-to-type-theory&#x2F;18204&#x2F;5&lt;&#x2F;p&gt;
&lt;p&gt;There’s also a small presentation on this topic: https:&#x2F;&#x2F;av.tib.eu&#x2F;media&#x2F;52178&lt;&#x2F;p&gt;
&lt;p&gt;“Mental model”: https:&#x2F;&#x2F;ia0.github.io&#x2F;unsafe-mental-model&#x2F;type-theory.html&lt;&#x2F;p&gt;
&lt;p&gt;And an interesting post: https:&#x2F;&#x2F;www.kurtlawrence.info&#x2F;blog&#x2F;category-theory-with-rust-pt1&lt;&#x2F;p&gt;
&lt;p&gt;But they all have lots of text and don’t have a “comprehensive” chart that I could hang on my wall.&lt;&#x2F;p&gt;
&lt;h1 id=&quot;-1&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#-1&quot; aria-label=&quot;Anchor link for: -1&quot;&gt;&lt;i class=&quot;icon&quot;&gt;&lt;&#x2F;i&gt;&lt;&#x2F;a&gt;
Rust Types Taxonomy&lt;&#x2F;h1&gt;
&lt;p&gt;&lt;img src=&quot;&#x2F;images&#x2F;2025_02_19_tax_main.png&quot; alt=&quot;Taxonomy&quot; loading=&quot;lazy&quot; decoding=&quot;async&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;p&gt;Ultimately, based on my knowledge of theory, I created the first version of this taxonomy. I really love using trees (especially binary trees) to build hierarchies, as I find it easier to navigate and understand their essence. The visualization itself is, of course, the goal of this publication, but for interested and inexperienced readers, I provide some explanations and links below.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;-2&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#-2&quot; aria-label=&quot;Anchor link for: -2&quot;&gt;&lt;i class=&quot;icon&quot;&gt;&lt;&#x2F;i&gt;&lt;&#x2F;a&gt;
P-type&lt;&#x2F;h2&gt;
&lt;p&gt;&lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;ru.wikipedia.org&#x2F;wiki&#x2F;%D0%A2%D0%B8%D0%BF-%D0%BF%D1%80%D0%BE%D0%B8%D0%B7%D0%B2%D0%B5%D0%B4%D0%B5%D0%BD%D0%B8%D0%B5&quot;&gt;Product type&lt;&#x2F;a&gt; - no, that’s not it. We combine several types into one, obtaining the product of possible values of these types as a new set of values. Which types in Rust implement it?&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;Tuple: &lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;doc.rust-lang.org&#x2F;stable&#x2F;book&#x2F;ch03-02-data-types.html#the-tuple-type&quot;&gt;Tuple&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;Struct: &lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;doc.rust-lang.org&#x2F;stable&#x2F;book&#x2F;ch05-00-structs.html&quot;&gt;Struct&lt;&#x2F;a&gt;
&lt;ul&gt;
&lt;li&gt;Tuple Struct: &lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;doc.rust-lang.org&#x2F;stable&#x2F;book&#x2F;ch05-01-defining-structs.html#using-tuple-structs-without-named-fields-to-create-different-types&quot;&gt;Tuple Struct&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;Unit-Like Struct: &lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;doc.rust-lang.org&#x2F;stable&#x2F;book&#x2F;ch05-01-defining-structs.html#unit-like-structs-without-any-fields&quot;&gt;Unit-Like Struct&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;Array: &lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;doc.rust-lang.org&#x2F;stable&#x2F;book&#x2F;ch03-02-data-types.html#the-array-type&quot;&gt;Array&lt;&#x2F;a&gt;
&lt;ul&gt;
&lt;li&gt;Slice: &lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;doc.rust-lang.org&#x2F;stable&#x2F;book&#x2F;ch04-03-slices.html&quot;&gt;Slice&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h2 id=&quot;-3&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#-3&quot; aria-label=&quot;Anchor link for: -3&quot;&gt;&lt;i class=&quot;icon&quot;&gt;&lt;&#x2F;i&gt;&lt;&#x2F;a&gt;
Σ-type&lt;&#x2F;h2&gt;
&lt;p&gt;&lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;ru.wikipedia.org&#x2F;wiki&#x2F;%D0%A2%D0%B8%D0%BF-%D1%81%D1%83%D0%BC%D0%BC%D0%B0&quot;&gt;Sum type&lt;&#x2F;a&gt; unlike the P-type, a sum type provides stricter control over possible values of used types.&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;Enum: &lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;doc.rust-lang.org&#x2F;stable&#x2F;book&#x2F;ch06-00-enums.html&quot;&gt;Tagged Union&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;Option: &lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;doc.rust-lang.org&#x2F;stable&#x2F;book&#x2F;ch06-01-defining-an-enum.html#the-option-enum-and-its-advantages-over-null-values&quot;&gt;Option&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;Result: &lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;doc.rust-lang.org&#x2F;stable&#x2F;book&#x2F;ch09-02-recoverable-errors-with-result.html&quot;&gt;Result&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h2 id=&quot;-4&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#-4&quot; aria-label=&quot;Anchor link for: -4&quot;&gt;&lt;i class=&quot;icon&quot;&gt;&lt;&#x2F;i&gt;&lt;&#x2F;a&gt;
Pointer types&lt;&#x2F;h2&gt;
&lt;p&gt;Rust has capabilities for working with memory, so the language contains both references and pointers. What interests us are only the “high-level” concepts.&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;References: &lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;doc.rust-lang.org&#x2F;stable&#x2F;book&#x2F;ch04-02-references-and-borrowing.html&quot;&gt;References&lt;&#x2F;a&gt;
&lt;img src=&quot;https:&#x2F;&#x2F;doc.rust-lang.org&#x2F;stable&#x2F;book&#x2F;img&#x2F;trpl04-06.svg&quot; alt=&quot;Three tables: the table for s contains only a pointer to the table for s1. The table for s1 contains the stack data for s1 and points to the string data on the heap.&quot; loading=&quot;lazy&quot; decoding=&quot;async&quot; &#x2F;&gt;&lt;&#x2F;li&gt;
&lt;li&gt;Smart pointers
&lt;ul&gt;
&lt;li&gt;Box: Allocates a value in the heap. &lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;doc.rust-lang.org&#x2F;stable&#x2F;book&#x2F;ch15-01-box.html#using-boxt-to-point-to-data-on-the-heap&quot;&gt;Box&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;Rc&#x2F;Arc: Reference counters. &lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;doc.rust-lang.org&#x2F;stable&#x2F;book&#x2F;ch15-04-rc.html#rct-the-reference-counted-smart-pointer&quot;&gt;Reference counters&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;Ref&#x2F;RefMut + RefCell: Borrowing at the program execution level. &lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;doc.rust-lang.org&#x2F;stable&#x2F;book&#x2F;ch15-05-interior-mutability.html&quot;&gt;Runtime borrowing&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h2 id=&quot;-5&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#-5&quot; aria-label=&quot;Anchor link for: -5&quot;&gt;&lt;i class=&quot;icon&quot;&gt;&lt;&#x2F;i&gt;&lt;&#x2F;a&gt;
Other types&lt;&#x2F;h2&gt;
&lt;ul&gt;
&lt;li&gt;Functions: Not included in the current version of the taxonomy, so they are mentioned only for reference.
&lt;ul&gt;
&lt;li&gt;Closures: &lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;doc.rust-lang.org&#x2F;stable&#x2F;book&#x2F;ch13-01-closures.html&quot;&gt;Closures&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;FnOnce: &lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;doc.rust-lang.org&#x2F;std&#x2F;ops&#x2F;trait.FnOnce.html&quot;&gt;Documentation&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;FnMut: &lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;doc.rust-lang.org&#x2F;std&#x2F;ops&#x2F;trait.FnMut.html&quot;&gt;Documentation&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;Fn: &lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;doc.rust-lang.org&#x2F;std&#x2F;ops&#x2F;trait.Fn.html&quot;&gt;Documentation&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;Trait objects: &lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;doc.rust-lang.org&#x2F;stable&#x2F;book&#x2F;ch17-02-trait-objects.html#using-trait-objects-that-allow-for-values-of-different-types&quot;&gt;Trait Objects&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;Phantom types: &lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;doc.rust-lang.org&#x2F;nomicon&#x2F;phantom-data.html&quot;&gt;Phantom Data&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>Okxlivro - Post Mortem</title>
        <published>2025-01-27T00:00:00+00:00</published>
        <updated>2025-01-27T00:00:00+00:00</updated>
        
        <author>
          <name>
            Nikita Bishonen
          </name>
        </author>
        
        <link rel="alternate" type="text/html" href="https://bshn.rs/blog/2025-01-03-okxlivro-post-mortem/"/>
        <id>https://bshn.rs/blog/2025-01-03-okxlivro-post-mortem/</id>
        
        <content type="html" xml:base="https://bshn.rs/blog/2025-01-03-okxlivro-post-mortem/">&lt;p&gt;Hello! Today I’m sharing my thoughts on writing convenient Rust libraries. This is the first post in the “Post Mortem” series, where I’ll be dissecting different projects.&lt;&#x2F;p&gt;
&lt;p&gt;Today on our table is a technical assignment I was given at one company after an interview. I don’t like wasting my personal time, so I usually refuse to go through this stage, but this project seemed interesting to me, so I completed it. I also received a rejection and feedback. Let’s try to fix what didn’t please the reviewer and discuss the changes along the way.&lt;&#x2F;p&gt;
&lt;p&gt;As with the previous one, I’ll start this post with a brief clarification of terminology. If you’re confident in your knowledge of exchange trading specifics, feel free to skip to &lt;a href=&quot;https:&#x2F;&#x2F;bshn.rs&#x2F;blog&#x2F;2025-01-03-okxlivro-post-mortem&#x2F;#core&quot;&gt;the core&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;portfolios-order-books-and-orders&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#portfolios-order-books-and-orders&quot; aria-label=&quot;Anchor link for: portfolios-order-books-and-orders&quot;&gt;&lt;i class=&quot;icon&quot;&gt;&lt;&#x2F;i&gt;&lt;&#x2F;a&gt;
Portfolios, order books, and orders&lt;&#x2F;h2&gt;
&lt;blockquote&gt;
&lt;p&gt;If you’re not familiar with trading, I recommend studying &lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;www.youtube.com&#x2F;watch?v=Kl4-VJ2K8Ik&quot;&gt;this short video&lt;&#x2F;a&gt; or &lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Order_book&quot;&gt;this Wikipedia article&lt;&#x2F;a&gt; before continuing reading. Below I’m presenting my understanding of the topic, which may be inaccurate or incomplete.&lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
&lt;p&gt;So, in Trading we have:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;Portfolio of orders
&lt;ul&gt;
&lt;li&gt;Sell orders (Ask side Order)
&lt;ul&gt;
&lt;li&gt;Trading pair identifier (what we’re exchanging for what), volume, and price&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;Buy orders (Bid side Order)&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;This results in an order book or book where we record all orders, and if they intersect (we have someone willing to sell one egg for a kilogram of potatoes, and another willing to buy one egg for a kilogram of potatoes), we can execute both orders.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;img src=&quot;https:&#x2F;&#x2F;upload.wikimedia.org&#x2F;wikipedia&#x2F;commons&#x2F;thumb&#x2F;1&#x2F;14&#x2F;Order_book_depth_chart.gif&#x2F;250px-Order_book_depth_chart.gif&quot; alt=&quot;Order book&quot; loading=&quot;lazy&quot; decoding=&quot;async&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;h2 id=&quot;core&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#core&quot; aria-label=&quot;Anchor link for: core&quot;&gt;&lt;i class=&quot;icon&quot;&gt;&lt;&#x2F;i&gt;&lt;&#x2F;a&gt;
Core&lt;&#x2F;h2&gt;
&lt;p&gt;We’re trying to apply the &lt;a href=&quot;&#x2F;blog&#x2F;2024-12-13-rust-micro-structure&quot;&gt;Module Visibility-Based Structure&lt;&#x2F;a&gt;. The idea and main goal is to write a library for working with the OKX exchange, the API should be convenient to use, and the implementation should be extensible and maintainable.&lt;&#x2F;p&gt;
&lt;blockquote&gt;
&lt;p&gt;I decided it’s worth trying to write idiomatic but modern Rust code - using an asynchronous model, strict typing, and implementation hiding.&lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
&lt;p&gt;Here everything is fine, no issues were identified.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#&quot; aria-label=&quot;Anchor link for: &quot;&gt;&lt;i class=&quot;icon&quot;&gt;&lt;&#x2F;i&gt;&lt;&#x2F;a&gt;
REST (in peace =)&lt;&#x2F;h3&gt;
&lt;p&gt;Initially I made a fairly simple implementation:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color-scheme: light dark; color: light-dark(#C6D0F5, #565869); background-color: light-dark(#303446, #FAFBFC);&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#CA9EE6, #F767BB);&quot;&gt;pub&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#CA9EE6, #F767BB);&quot;&gt; async&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#CA9EE6, #F767BB);&quot;&gt; fn&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#8CAAEE, #09A1ED);font-style: italic;&quot;&gt; orderbook_snapshot&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#EA999C, #565869);&quot;&gt;instrument_id&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt; &amp;amp;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#E5C890, #565869);font-style: italic;&quot;&gt;str&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt; -&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#E5C890, #13BBB7);font-style: italic;&quot;&gt; Result&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#99D1DB, #ADB1C2);&quot;&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#E5C890, #13BBB7);font-style: italic;&quot;&gt;Orderbook&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#E5C890, #13BBB7);font-style: italic;&quot;&gt; RestError&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#99D1DB, #ADB1C2);&quot;&gt;&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#CA9EE6, #F767BB);&quot;&gt;    let&lt;&#x2F;span&gt;&lt;span&gt; response&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#E5C890, #565869);&quot;&gt; serde_json&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#E5C890, #13BBB7);font-style: italic;&quot;&gt;Value&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#E5C890, #13BBB7);font-style: italic;&quot;&gt; Client&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#8CAAEE, #09A1ED);font-style: italic;&quot;&gt;new&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt;        .&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#8CAAEE, #09A1ED);font-style: italic;&quot;&gt;get&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#8CAAEE, #09A1ED);font-style: italic;&quot;&gt;format!&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#A6D189, #ADB1C2);&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;{&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#A6D189, #CF9C00);&quot;&gt;MARKET_BOOKS_REST_URL&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;}&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#A6D189, #CF9C00);&quot;&gt;?instId=&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;{&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#A6D189, #CF9C00);&quot;&gt;instrument_id&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;}&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#A6D189, #CF9C00);&quot;&gt;&amp;amp;sz=5&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#A6D189, #ADB1C2);&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt;        .&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#8CAAEE, #09A1ED);font-style: italic;&quot;&gt;send&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt;        .&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#CA9EE6, #F767BB);&quot;&gt;await&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt;?&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt;        .&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#8CAAEE, #09A1ED);font-style: italic;&quot;&gt;json&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt;        .&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#CA9EE6, #F767BB);&quot;&gt;await&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt;?&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#CA9EE6, #F767BB);&quot;&gt;    let&lt;&#x2F;span&gt;&lt;span&gt; asks&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; response&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;[&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#A6D189, #ADB1C2);&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#A6D189, #CF9C00);&quot;&gt;data&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#A6D189, #ADB1C2);&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;]&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;[&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#EF9F76, #FF5C57);&quot;&gt;0&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;]&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;[&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#A6D189, #ADB1C2);&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#A6D189, #CF9C00);&quot;&gt;asks&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#A6D189, #ADB1C2);&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt;        .&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#8CAAEE, #09A1ED);font-style: italic;&quot;&gt;as_array&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt;        .&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#8CAAEE, #09A1ED);font-style: italic;&quot;&gt;unwrap_or&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt;&amp;amp;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#8CAAEE, #09A1ED);font-style: italic;&quot;&gt;vec!&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;[&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;]&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt;        .&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#8CAAEE, #09A1ED);font-style: italic;&quot;&gt;iter&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt;        .&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#8CAAEE, #09A1ED);font-style: italic;&quot;&gt;map&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#E5C890, #565869);&quot;&gt;Order&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt;::&lt;&#x2F;span&gt;&lt;span&gt;try_from&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt;        .&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#8CAAEE, #09A1ED);font-style: italic;&quot;&gt;try_collect&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt;?&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#CA9EE6, #F767BB);&quot;&gt;    let&lt;&#x2F;span&gt;&lt;span&gt; bids&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; response&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;[&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#A6D189, #ADB1C2);&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#A6D189, #CF9C00);&quot;&gt;data&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#A6D189, #ADB1C2);&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;]&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;[&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#EF9F76, #FF5C57);&quot;&gt;0&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;]&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;[&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#A6D189, #ADB1C2);&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#A6D189, #CF9C00);&quot;&gt;bids&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#A6D189, #ADB1C2);&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt;        .&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#8CAAEE, #09A1ED);font-style: italic;&quot;&gt;as_array&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt;        .&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#8CAAEE, #09A1ED);font-style: italic;&quot;&gt;unwrap_or&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt;&amp;amp;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#8CAAEE, #09A1ED);font-style: italic;&quot;&gt;vec!&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;[&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;]&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt;        .&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#8CAAEE, #09A1ED);font-style: italic;&quot;&gt;iter&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt;        .&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#8CAAEE, #09A1ED);font-style: italic;&quot;&gt;map&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#E5C890, #565869);&quot;&gt;Order&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt;::&lt;&#x2F;span&gt;&lt;span&gt;try_from&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt;        .&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#8CAAEE, #09A1ED);font-style: italic;&quot;&gt;try_collect&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt;?&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#CA9EE6, #F767BB);&quot;&gt;    let&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#CA9EE6, #F767BB);&quot;&gt; mut&lt;&#x2F;span&gt;&lt;span&gt; orderbook&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#E5C890, #13BBB7);font-style: italic;&quot;&gt; Orderbook&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#8CAAEE, #09A1ED);font-style: italic;&quot;&gt;default&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    orderbook&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#8CAAEE, #09A1ED);font-style: italic;&quot;&gt;apply_snapshot&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#8CAAEE, #09A1ED);font-style: italic;&quot;&gt;SnapshotData&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;(&lt;&#x2F;span&gt;&lt;span&gt;asks&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;,&lt;&#x2F;span&gt;&lt;span&gt; bids&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#E5C890, #565869);font-style: italic;&quot;&gt;    Ok&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;(&lt;&#x2F;span&gt;&lt;span&gt;orderbook&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;And received a remark - that this is a brute force solution and data parsing goes simply through &lt;code&gt;Value&lt;&#x2F;code&gt;. Let’s rewrite this with strict types:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color-scheme: light dark; color: light-dark(#C6D0F5, #565869); background-color: light-dark(#303446, #FAFBFC);&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#CA9EE6, #F767BB);&quot;&gt;pub&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#CA9EE6, #F767BB);&quot;&gt; async&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#CA9EE6, #F767BB);&quot;&gt; fn&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#8CAAEE, #09A1ED);font-style: italic;&quot;&gt; orderbook_snapshot&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#EA999C, #565869);&quot;&gt;instrument_id&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt; &amp;amp;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#E5C890, #565869);font-style: italic;&quot;&gt;str&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#EA999C, #565869);&quot;&gt; client&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt; &amp;amp;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#E5C890, #13BBB7);font-style: italic;&quot;&gt;Client&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt; -&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#E5C890, #13BBB7);font-style: italic;&quot;&gt; Result&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#99D1DB, #ADB1C2);&quot;&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#E5C890, #13BBB7);font-style: italic;&quot;&gt;Orderbook&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#E5C890, #13BBB7);font-style: italic;&quot;&gt; RestError&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#99D1DB, #ADB1C2);&quot;&gt;&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#CA9EE6, #F767BB);&quot;&gt;    let&lt;&#x2F;span&gt;&lt;span&gt; response&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#E5C890, #565869);&quot;&gt; inner&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#E5C890, #13BBB7);font-style: italic;&quot;&gt;ApiResponse&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; client&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt;        .&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#8CAAEE, #09A1ED);font-style: italic;&quot;&gt;get&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#8CAAEE, #09A1ED);font-style: italic;&quot;&gt;format!&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#A6D189, #ADB1C2);&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;{&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#A6D189, #CF9C00);&quot;&gt;MARKET_BOOKS_REST_URL&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;}&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#A6D189, #CF9C00);&quot;&gt;?instId=&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;{&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#A6D189, #CF9C00);&quot;&gt;instrument_id&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;}&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#A6D189, #CF9C00);&quot;&gt;&amp;amp;sz=5&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#A6D189, #ADB1C2);&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt;        .&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#8CAAEE, #09A1ED);font-style: italic;&quot;&gt;send&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt;        .&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#CA9EE6, #F767BB);&quot;&gt;await&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt;?&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt;        .&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#8CAAEE, #09A1ED);font-style: italic;&quot;&gt;json&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt;        .&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#CA9EE6, #F767BB);&quot;&gt;await&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt;?&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#CA9EE6, #F767BB);&quot;&gt;    let&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt; [&lt;&#x2F;span&gt;&lt;span&gt;data&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;]&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; response&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt;.&lt;&#x2F;span&gt;&lt;span&gt;data&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#CA9EE6, #F767BB);&quot;&gt;    let&lt;&#x2F;span&gt;&lt;span&gt; asks&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; data&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt;.&lt;&#x2F;span&gt;&lt;span&gt;asks&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#8CAAEE, #09A1ED);font-style: italic;&quot;&gt;into_iter&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#8CAAEE, #09A1ED);font-style: italic;&quot;&gt;map&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#E5C890, #565869);&quot;&gt;Ask&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt;::&lt;&#x2F;span&gt;&lt;span&gt;from&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#8CAAEE, #09A1ED);font-style: italic;&quot;&gt;collect&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#CA9EE6, #F767BB);&quot;&gt;    let&lt;&#x2F;span&gt;&lt;span&gt; bids&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; data&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt;.&lt;&#x2F;span&gt;&lt;span&gt;bids&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#8CAAEE, #09A1ED);font-style: italic;&quot;&gt;into_iter&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#8CAAEE, #09A1ED);font-style: italic;&quot;&gt;map&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#E5C890, #565869);&quot;&gt;Bid&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt;::&lt;&#x2F;span&gt;&lt;span&gt;from&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#8CAAEE, #09A1ED);font-style: italic;&quot;&gt;collect&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#CA9EE6, #F767BB);&quot;&gt;    let&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#CA9EE6, #F767BB);&quot;&gt; mut&lt;&#x2F;span&gt;&lt;span&gt; orderbook&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#E5C890, #13BBB7);font-style: italic;&quot;&gt; Orderbook&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#8CAAEE, #09A1ED);font-style: italic;&quot;&gt;default&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    orderbook&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#8CAAEE, #09A1ED);font-style: italic;&quot;&gt;apply_snapshot&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#8CAAEE, #09A1ED);font-style: italic;&quot;&gt;SnapshotData&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;(&lt;&#x2F;span&gt;&lt;span&gt;asks&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;,&lt;&#x2F;span&gt;&lt;span&gt; bids&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#E5C890, #565869);font-style: italic;&quot;&gt;    Ok&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;(&lt;&#x2F;span&gt;&lt;span&gt;orderbook&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Details can be viewed in the &lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;gitlab.com&#x2F;personal1196&#x2F;trainings&#x2F;okxlivro&#x2F;-&#x2F;blob&#x2F;master&#x2F;src&#x2F;rest.rs&quot;&gt;git repository&lt;&#x2F;a&gt;, but the implementation itself is almost standard.&lt;&#x2F;p&gt;
&lt;p&gt;The difference is that I don’t do direct deserialization into public library types, but use &lt;code&gt;mod inner {...}&lt;&#x2F;code&gt;. This is done out of experience-based concerns that:&lt;&#x2F;p&gt;
&lt;ol&gt;
&lt;li&gt;The exchange has an unstable API, despite versioning, documentation description differs from reality, especially when there are no formal schemas;&lt;&#x2F;li&gt;
&lt;li&gt;The exchange representation is not optimal, for example, an array of data is returned, but the element is always one, or the actual bids and asks are an array of four elements, one of which: &lt;code&gt;&quot;0&quot; is part of a deprecated feature and it is always &quot;0&quot;&lt;&#x2F;code&gt;.&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;h3 id=&quot;-1&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#-1&quot; aria-label=&quot;Anchor link for: -1&quot;&gt;&lt;i class=&quot;icon&quot;&gt;&lt;&#x2F;i&gt;&lt;&#x2F;a&gt;
Asks &amp;amp; Bids&lt;&#x2F;h3&gt;
&lt;p&gt;Let’s start with the simple - we use all standard library capabilities. There’s a requirement for order lists, they should be sorted from best to worst.&lt;&#x2F;p&gt;
&lt;p&gt;But depending on the order side (buying&#x2F;selling), we need to sort either by ascending (better to buy cheaper) or descending (better to sell more expensive) price.&lt;&#x2F;p&gt;
&lt;p&gt;Initially I implemented them such that the price difference was in using the &lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;doc.rust-lang.org&#x2F;std&#x2F;cmp&#x2F;struct.Reverse.html&quot;&gt;Reverse&lt;&#x2F;a&gt; wrapper:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color-scheme: light dark; color: light-dark(#C6D0F5, #565869); background-color: light-dark(#303446, #FAFBFC);&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);font-style: italic;&quot;&gt;&#x2F;&#x2F;&#x2F;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);font-style: italic;&quot;&gt; Low to high price ordered Map ([`Price`], [`Amount`]) of Asks.&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#CA9EE6, #F767BB);&quot;&gt;pub&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#CA9EE6, #F767BB);&quot;&gt; struct&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#E5C890, #565869);font-style: italic;&quot;&gt; Asks&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#E5C890, #13BBB7);font-style: italic;&quot;&gt;BTreeMap&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#99D1DB, #ADB1C2);&quot;&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#E5C890, #13BBB7);font-style: italic;&quot;&gt;Price&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#E5C890, #13BBB7);font-style: italic;&quot;&gt; Amount&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#99D1DB, #ADB1C2);&quot;&gt;&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);font-style: italic;&quot;&gt;&#x2F;&#x2F;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);font-style: italic;&quot;&gt; High to low price ordered Map ([`Price`], [`Amount`]) of Bids.&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#CA9EE6, #F767BB);&quot;&gt;pub&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#CA9EE6, #F767BB);&quot;&gt; struct&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#E5C890, #565869);font-style: italic;&quot;&gt; Bids&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#E5C890, #13BBB7);font-style: italic;&quot;&gt;BTreeMap&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#99D1DB, #ADB1C2);&quot;&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#E5C890, #13BBB7);font-style: italic;&quot;&gt;Reverse&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#99D1DB, #ADB1C2);&quot;&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#E5C890, #13BBB7);font-style: italic;&quot;&gt;Price&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#99D1DB, #ADB1C2);&quot;&gt;&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#E5C890, #13BBB7);font-style: italic;&quot;&gt; Amount&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#99D1DB, #ADB1C2);&quot;&gt;&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;The remark indicated that extending and maintaining would be inconvenient due to logic duplication when there’s no difference (only &lt;code&gt;Reverse&lt;&#x2F;code&gt;) between bids and asks.&lt;&#x2F;p&gt;
&lt;p&gt;I think the reviewer wanted something else, but I decided to go all in and sometimes duplicate logic, but further separate bids and asks:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color-scheme: light dark; color: light-dark(#C6D0F5, #565869); background-color: light-dark(#303446, #FAFBFC);&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#CA9EE6, #F767BB);&quot;&gt;pub&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#CA9EE6, #F767BB);&quot;&gt; struct&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#E5C890, #565869);font-style: italic;&quot;&gt; AskPrice&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#E5C890, #13BBB7);font-style: italic;&quot;&gt;Price&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#CA9EE6, #F767BB);&quot;&gt;pub&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#CA9EE6, #F767BB);&quot;&gt; struct&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#E5C890, #565869);font-style: italic;&quot;&gt; BidPrice&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#E5C890, #13BBB7);font-style: italic;&quot;&gt;Reverse&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#99D1DB, #ADB1C2);&quot;&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#E5C890, #13BBB7);font-style: italic;&quot;&gt;Price&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#99D1DB, #ADB1C2);&quot;&gt;&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Let’s make different prices, as well as structures for single bids and asks that we use in the &lt;code&gt;realtime&lt;&#x2F;code&gt; module:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color-scheme: light dark; color: light-dark(#C6D0F5, #565869); background-color: light-dark(#303446, #FAFBFC);&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);font-style: italic;&quot;&gt;&#x2F;&#x2F;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);font-style: italic;&quot;&gt; lib.rs&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#CA9EE6, #F767BB);&quot;&gt;pub&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#CA9EE6, #F767BB);&quot;&gt; struct&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#E5C890, #565869);font-style: italic;&quot;&gt; Ask&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#CA9EE6, #F767BB);&quot;&gt;    pub&lt;&#x2F;span&gt;&lt;span&gt; price&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#E5C890, #13BBB7);font-style: italic;&quot;&gt; AskPrice&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#CA9EE6, #F767BB);&quot;&gt;    pub&lt;&#x2F;span&gt;&lt;span&gt; amount&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#E5C890, #13BBB7);font-style: italic;&quot;&gt; Amount&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#CA9EE6, #F767BB);&quot;&gt;pub&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#CA9EE6, #F767BB);&quot;&gt; struct&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#E5C890, #565869);font-style: italic;&quot;&gt; Bid&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#CA9EE6, #F767BB);&quot;&gt;    pub&lt;&#x2F;span&gt;&lt;span&gt; price&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#E5C890, #13BBB7);font-style: italic;&quot;&gt; BidPrice&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#CA9EE6, #F767BB);&quot;&gt;    pub&lt;&#x2F;span&gt;&lt;span&gt; amount&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#E5C890, #13BBB7);font-style: italic;&quot;&gt; Amount&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&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: light-dark(#949CBB, #ADB1C2);font-style: italic;&quot;&gt;&#x2F;&#x2F;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);font-style: italic;&quot;&gt; realtime.rs&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#CA9EE6, #F767BB);&quot;&gt;pub&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#CA9EE6, #F767BB);&quot;&gt; struct&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#E5C890, #565869);font-style: italic;&quot;&gt; SnapshotData&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#CA9EE6, #F767BB);&quot;&gt;pub&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt; (&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#E5C890, #13BBB7);font-style: italic;&quot;&gt;Vec&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#99D1DB, #ADB1C2);&quot;&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#E5C890, #13BBB7);font-style: italic;&quot;&gt;Ask&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#99D1DB, #ADB1C2);&quot;&gt;&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#E5C890, #13BBB7);font-style: italic;&quot;&gt; Vec&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#99D1DB, #ADB1C2);&quot;&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#E5C890, #13BBB7);font-style: italic;&quot;&gt;Bid&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#99D1DB, #ADB1C2);&quot;&gt;&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#CA9EE6, #F767BB);&quot;&gt;pub&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#CA9EE6, #F767BB);&quot;&gt; struct&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#E5C890, #565869);font-style: italic;&quot;&gt; UpdateData&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#CA9EE6, #F767BB);&quot;&gt;pub&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt; (&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#E5C890, #13BBB7);font-style: italic;&quot;&gt;Vec&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#99D1DB, #ADB1C2);&quot;&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#E5C890, #13BBB7);font-style: italic;&quot;&gt;Ask&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#99D1DB, #ADB1C2);&quot;&gt;&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#E5C890, #13BBB7);font-style: italic;&quot;&gt; Vec&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#99D1DB, #ADB1C2);&quot;&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#E5C890, #13BBB7);font-style: italic;&quot;&gt;Bid&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#99D1DB, #ADB1C2);&quot;&gt;&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;I’m countering the reviewer’s remark about “logic duplication” by saying that general logic needs to be implemented at the &lt;code&gt;Price&lt;&#x2F;code&gt; level, and logic differences can be implemented separately for &lt;code&gt;Bid&lt;&#x2F;code&gt; and &lt;code&gt;Ask&lt;&#x2F;code&gt;. And the presence of strict typing at the library API level provides good user experience, since it won’t be possible to accidentally confuse bids and asks.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;-2&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#-2&quot; aria-label=&quot;Anchor link for: -2&quot;&gt;&lt;i class=&quot;icon&quot;&gt;&lt;&#x2F;i&gt;&lt;&#x2F;a&gt;
Stream&lt;&#x2F;h3&gt;
&lt;p&gt;Initially I used the approach through message sending channels, but then rewrote it to a version more ergonomic for library clients to use: &lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;gitlab.com&#x2F;personal1196&#x2F;trainings&#x2F;okxlivro&#x2F;-&#x2F;merge_requests&#x2F;1&#x2F;diffs?diff_id=1224257646&amp;amp;start_sha=dcb0a49c106f39a254e06d2ebeabd912cc508cd0#76f9c51b493a7919f56a79c87fae8b40195e3848&quot;&gt;changes&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color-scheme: light dark; color: light-dark(#C6D0F5, #565869); background-color: light-dark(#303446, #FAFBFC);&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#CA9EE6, #F767BB);&quot;&gt;pub&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#CA9EE6, #F767BB);&quot;&gt; fn&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#8CAAEE, #09A1ED);font-style: italic;&quot;&gt; orderbook_updates&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#EA999C, #565869);&quot;&gt;instrument_id&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt; &amp;amp;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#E5C890, #565869);font-style: italic;&quot;&gt;str&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt; -&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#E5C890, #13BBB7);font-style: italic;&quot;&gt; Pin&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#99D1DB, #ADB1C2);&quot;&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#E5C890, #13BBB7);font-style: italic;&quot;&gt;Box&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#99D1DB, #ADB1C2);&quot;&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#CA9EE6, #F767BB);&quot;&gt;impl&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#E5C890, #13BBB7);font-style: italic;&quot;&gt; Stream&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#99D1DB, #ADB1C2);&quot;&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#E5C890, #13BBB7);font-style: italic;&quot;&gt;Item&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#E5C890, #13BBB7);font-style: italic;&quot;&gt; Result&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#99D1DB, #ADB1C2);&quot;&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#E5C890, #13BBB7);font-style: italic;&quot;&gt;RealtimeData&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#E5C890, #13BBB7);font-style: italic;&quot;&gt; RealtimeError&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#99D1DB, #ADB1C2);&quot;&gt;&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#99D1DB, #ADB1C2);&quot;&gt;&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#99D1DB, #ADB1C2);&quot;&gt;&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#99D1DB, #ADB1C2);&quot;&gt;&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt;  ...&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#E5C890, #13BBB7);font-style: italic;&quot;&gt;  Box&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#8CAAEE, #09A1ED);font-style: italic;&quot;&gt;pin&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#8CAAEE, #09A1ED);font-style: italic;&quot;&gt;stream!&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt;    ...&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#CA9EE6, #F767BB);&quot;&gt;    while&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#CA9EE6, #F767BB);&quot;&gt; let&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#E5C890, #565869);font-style: italic;&quot;&gt; Some&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;(&lt;&#x2F;span&gt;&lt;span&gt;msg&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; read&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#8CAAEE, #09A1ED);font-style: italic;&quot;&gt;next&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#CA9EE6, #F767BB);&quot;&gt;await&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt;      ...&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#CA9EE6, #F767BB);&quot;&gt;      yield&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#E5C890, #565869);font-style: italic;&quot;&gt; Ok&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;(&lt;&#x2F;span&gt;&lt;span&gt;data&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;    }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;  )&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;As we can see, this approach still requires additional macros, and async iterators are not native to the standard library. We continue to hope and wait.&lt;&#x2F;p&gt;
&lt;p&gt;The remark received here refers to the problem of connection management:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color-scheme: light dark; color: light-dark(#C6D0F5, #565869); background-color: light-dark(#303446, #FAFBFC);&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#CA9EE6, #F767BB);&quot;&gt;pub&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#CA9EE6, #F767BB);&quot;&gt; fn&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#8CAAEE, #09A1ED);font-style: italic;&quot;&gt; orderbook_updates&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#EA999C, #565869);&quot;&gt;instrument_id&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt; &amp;amp;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#E5C890, #565869);font-style: italic;&quot;&gt;str&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt; -&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#E5C890, #13BBB7);font-style: italic;&quot;&gt; Pin&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#99D1DB, #ADB1C2);&quot;&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#E5C890, #13BBB7);font-style: italic;&quot;&gt;Box&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#99D1DB, #ADB1C2);&quot;&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#CA9EE6, #F767BB);&quot;&gt;impl&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#E5C890, #13BBB7);font-style: italic;&quot;&gt; Stream&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#99D1DB, #ADB1C2);&quot;&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#E5C890, #13BBB7);font-style: italic;&quot;&gt;Item&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#E5C890, #13BBB7);font-style: italic;&quot;&gt; Result&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#99D1DB, #ADB1C2);&quot;&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#E5C890, #13BBB7);font-style: italic;&quot;&gt;RealtimeData&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#E5C890, #13BBB7);font-style: italic;&quot;&gt; RealtimeError&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#99D1DB, #ADB1C2);&quot;&gt;&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#99D1DB, #ADB1C2);&quot;&gt;&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#99D1DB, #ADB1C2);&quot;&gt;&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#99D1DB, #ADB1C2);&quot;&gt;&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt;    ..&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#E5C890, #13BBB7);font-style: italic;&quot;&gt;    Box&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#8CAAEE, #09A1ED);font-style: italic;&quot;&gt;pin&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#8CAAEE, #09A1ED);font-style: italic;&quot;&gt;stream!&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#CA9EE6, #F767BB);&quot;&gt;        let&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt; (&lt;&#x2F;span&gt;&lt;span&gt;ws_stream&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;,&lt;&#x2F;span&gt;&lt;span&gt; _&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#E5C890, #565869);&quot;&gt; tokio_tungstenite&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#8CAAEE, #09A1ED);font-style: italic;&quot;&gt;connect_async&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#EF9F76, #2DAE58);&quot;&gt;WS_URL&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#CA9EE6, #F767BB);&quot;&gt;await&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt;?&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#CA9EE6, #F767BB);&quot;&gt;        let&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt; (&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#CA9EE6, #F767BB);&quot;&gt;mut&lt;&#x2F;span&gt;&lt;span&gt; write&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#CA9EE6, #F767BB);&quot;&gt; mut&lt;&#x2F;span&gt;&lt;span&gt; read&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; ws_stream&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#8CAAEE, #09A1ED);font-style: italic;&quot;&gt;split&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        write&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt;            .&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#8CAAEE, #09A1ED);font-style: italic;&quot;&gt;send&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#E5C890, #565869);&quot;&gt;Message&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#8CAAEE, #09A1ED);font-style: italic;&quot;&gt;Text&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;(&lt;&#x2F;span&gt;&lt;span&gt;message_string&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#8CAAEE, #09A1ED);font-style: italic;&quot;&gt;into&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt;            .&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#CA9EE6, #F767BB);&quot;&gt;await&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt;?&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#CA9EE6, #F767BB);&quot;&gt;        while&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#CA9EE6, #F767BB);&quot;&gt; let&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#E5C890, #565869);font-style: italic;&quot;&gt; Some&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;(&lt;&#x2F;span&gt;&lt;span&gt;msg&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; read&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#8CAAEE, #09A1ED);font-style: italic;&quot;&gt;next&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#CA9EE6, #F767BB);&quot;&gt;await&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;It was necessary to extract this logic from the method, which is very logical. I love the pattern where all “resources” are passed as method arguments in minimal necessary forms. This of course forced me to struggle a bit with generics. But after ten minutes of jumping through the tungstenite code, I found the correct error types and brought the method signature to the following form, while splitting one method into two:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color-scheme: light dark; color: light-dark(#C6D0F5, #565869); background-color: light-dark(#303446, #FAFBFC);&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#CA9EE6, #F767BB);&quot;&gt;pub&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#CA9EE6, #F767BB);&quot;&gt; async&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#CA9EE6, #F767BB);&quot;&gt; fn&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#8CAAEE, #09A1ED);font-style: italic;&quot;&gt; subscribe&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#99D1DB, #ADB1C2);&quot;&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#E5C890, #13BBB7);font-style: italic;&quot;&gt;S&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#99D1DB, #ADB1C2);&quot;&gt;&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#EA999C, #565869);&quot;&gt;channels_with_criterias&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt; &amp;amp;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;[&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#E5C890, #13BBB7);font-style: italic;&quot;&gt;ChannelWithCriteria&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;]&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#EA999C, #565869);&quot;&gt; write&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt; &amp;amp;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#CA9EE6, #F767BB);&quot;&gt;mut&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#E5C890, #13BBB7);font-style: italic;&quot;&gt; S&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt; -&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#E5C890, #13BBB7);font-style: italic;&quot;&gt; Result&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#99D1DB, #ADB1C2);&quot;&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#E5C890, #13BBB7);font-style: italic;&quot;&gt; RealtimeError&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#99D1DB, #ADB1C2);&quot;&gt;&amp;gt;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt;...&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#CA9EE6, #F767BB);&quot;&gt;pub&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#CA9EE6, #F767BB);&quot;&gt; fn&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#EA999C, #565869);&quot;&gt; transform_stream&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#99D1DB, #ADB1C2);&quot;&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#E5C890, #13BBB7);font-style: italic;&quot;&gt;T&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#99D1DB, #ADB1C2);&quot;&gt;&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#EA999C, #565869);&quot;&gt;read&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt; &amp;amp;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#CA9EE6, #F767BB);&quot;&gt;mut&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#E5C890, #13BBB7);font-style: italic;&quot;&gt; T&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt; -&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#E5C890, #13BBB7);font-style: italic;&quot;&gt; Pin&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#99D1DB, #ADB1C2);&quot;&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#E5C890, #13BBB7);font-style: italic;&quot;&gt;Box&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#99D1DB, #ADB1C2);&quot;&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#CA9EE6, #F767BB);&quot;&gt;impl&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#E5C890, #13BBB7);font-style: italic;&quot;&gt; Stream&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#99D1DB, #ADB1C2);&quot;&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#E5C890, #13BBB7);font-style: italic;&quot;&gt;Item&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#E5C890, #13BBB7);font-style: italic;&quot;&gt; Item&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#99D1DB, #ADB1C2);&quot;&gt;&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#99D1DB, #ADB1C2);&quot;&gt;&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#99D1DB, #ADB1C2);&quot;&gt;&amp;gt;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;I also changed the return type to support extending to all possible data types for different subscriptions:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color-scheme: light dark; color: light-dark(#C6D0F5, #565869); background-color: light-dark(#303446, #FAFBFC);&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#CA9EE6, #F767BB);&quot;&gt;pub&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#CA9EE6, #F767BB);&quot;&gt; enum&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#E5C890, #565869);font-style: italic;&quot;&gt; RealtimeData&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8CAAEE, #09A1ED);font-style: italic;&quot;&gt;    Books&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#E5C890, #13BBB7);font-style: italic;&quot;&gt;BooksChannelData&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;I can say that I find Rust enums convenient and practical. The only thing I’m really missing is that enum variants don’t have “first-class” support in the language’s type system.&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color-scheme: light dark; color: light-dark(#C6D0F5, #565869); background-color: light-dark(#303446, #FAFBFC);&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#CA9EE6, #F767BB);&quot;&gt;pub&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#CA9EE6, #F767BB);&quot;&gt; enum&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#E5C890, #565869);font-style: italic;&quot;&gt; BooksChannelDelta&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8CAAEE, #09A1ED);font-style: italic;&quot;&gt;    Snapshot&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#E5C890, #13BBB7);font-style: italic;&quot;&gt;SnapshotData&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8CAAEE, #09A1ED);font-style: italic;&quot;&gt;    Update&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#E5C890, #13BBB7);font-style: italic;&quot;&gt;UpdateData&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#CA9EE6, #F767BB);&quot;&gt;pub&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#CA9EE6, #F767BB);&quot;&gt; struct&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#E5C890, #565869);font-style: italic;&quot;&gt; SnapshotData&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#CA9EE6, #F767BB);&quot;&gt;pub&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt; (&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#E5C890, #13BBB7);font-style: italic;&quot;&gt;Vec&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#99D1DB, #ADB1C2);&quot;&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#E5C890, #13BBB7);font-style: italic;&quot;&gt;Ask&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#99D1DB, #ADB1C2);&quot;&gt;&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#E5C890, #13BBB7);font-style: italic;&quot;&gt; Vec&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#99D1DB, #ADB1C2);&quot;&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#E5C890, #13BBB7);font-style: italic;&quot;&gt;Bid&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#99D1DB, #ADB1C2);&quot;&gt;&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#CA9EE6, #F767BB);&quot;&gt;pub&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#CA9EE6, #F767BB);&quot;&gt; struct&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#E5C890, #565869);font-style: italic;&quot;&gt; UpdateData&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#CA9EE6, #F767BB);&quot;&gt;pub&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt; (&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#E5C890, #13BBB7);font-style: italic;&quot;&gt;Vec&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#99D1DB, #ADB1C2);&quot;&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#E5C890, #13BBB7);font-style: italic;&quot;&gt;Ask&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#99D1DB, #ADB1C2);&quot;&gt;&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#E5C890, #13BBB7);font-style: italic;&quot;&gt; Vec&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#99D1DB, #ADB1C2);&quot;&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#E5C890, #13BBB7);font-style: italic;&quot;&gt;Bid&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#99D1DB, #ADB1C2);&quot;&gt;&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;For example, implementation of messages from the exchange - through a WebSocket connection to us can be delivered information both about portfolio updates and its snapshot state.&lt;&#x2F;p&gt;
&lt;p&gt;If we don’t use an enum, then the data itself are identical and the user can confuse them. In the implementation, I not only split them into variants, but also created new wrapper types for greater safety when using.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;-3&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#-3&quot; aria-label=&quot;Anchor link for: -3&quot;&gt;&lt;i class=&quot;icon&quot;&gt;&lt;&#x2F;i&gt;&lt;&#x2F;a&gt;
Error&lt;&#x2F;h3&gt;
&lt;p&gt;I love the simple but incredibly useful &lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;docs.rs&#x2F;derive_more&#x2F;latest&#x2F;derive_more&#x2F;index.html&quot;&gt;derive_more&lt;&#x2F;a&gt; library with procedural macros for all occasions, for example for creating error types:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color-scheme: light dark; color: light-dark(#C6D0F5, #565869); background-color: light-dark(#303446, #FAFBFC);&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#E5C890, #ADB1C2);font-style: italic;&quot;&gt;#&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;[&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#E5C890, #565869);font-style: italic;&quot;&gt;derive&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#E5C890, #13BBB7);font-style: italic;&quot;&gt;Debug&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#E5C890, #13BBB7);font-style: italic;&quot;&gt; Display&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#E5C890, #13BBB7);font-style: italic;&quot;&gt; Error&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#E5C890, #13BBB7);font-style: italic;&quot;&gt; From&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#CA9EE6, #F767BB);&quot;&gt;pub&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#CA9EE6, #F767BB);&quot;&gt; enum&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#E5C890, #565869);font-style: italic;&quot;&gt; CompoundError&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#E5C890, #13BBB7);font-style: italic;&quot;&gt;    Realtime&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt; {&lt;&#x2F;span&gt;&lt;span&gt; source&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#E5C890, #13BBB7);font-style: italic;&quot;&gt; RealtimeError&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt; }&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#E5C890, #13BBB7);font-style: italic;&quot;&gt;    Rest&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt; {&lt;&#x2F;span&gt;&lt;span&gt; source&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#E5C890, #13BBB7);font-style: italic;&quot;&gt; RestError&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt; }&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Here, thanks to the macros, the enum becomes a Rust error, can be displayed as a string and converted from low-level errors - all this without extra hand-written code. It exists - but is generated automatically.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;-4&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#-4&quot; aria-label=&quot;Anchor link for: -4&quot;&gt;&lt;i class=&quot;icon&quot;&gt;&lt;&#x2F;i&gt;&lt;&#x2F;a&gt;
Additional Materials&lt;&#x2F;h2&gt;
&lt;p&gt;If you’re interested in “playing around” with the example from this article, here’s the &lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;gitlab.com&#x2F;personal1196&#x2F;trainings&#x2F;okxlivro&quot;&gt;full project code&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;I’ll also be grateful for feedback, please write your suggestions for improving the project in issues on GitLab.&lt;&#x2F;p&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>Rust Microservices - Project Structure</title>
        <published>2024-12-13T00:00:00+00:00</published>
        <updated>2024-12-13T00:00:00+00:00</updated>
        
        <author>
          <name>
            Nikita Bishonen
          </name>
        </author>
        
        <link rel="alternate" type="text/html" href="https://bshn.rs/blog/2024-12-13-rust-micro-structure/"/>
        <id>https://bshn.rs/blog/2024-12-13-rust-micro-structure/</id>
        
        <content type="html" xml:base="https://bshn.rs/blog/2024-12-13-rust-micro-structure/">&lt;p&gt;Hi! Today I’m sharing my thoughts on a convenient project structure for developing microservices in Rust. This is the first post in a potential “Rust Microservices” series. If I manage to finish it, I’ll compile it into a full book, so if you notice any inaccuracies or have your own thoughts on the topic - I’d be happy if you share them with me.&lt;&#x2F;p&gt;
&lt;p&gt;I’ll start this post with a brief overview. If you’re confident in your knowledge of Rust’s package and module system, feel free to jump to the &lt;a href=&quot;https:&#x2F;&#x2F;bshn.rs&#x2F;blog&#x2F;2024-12-13-rust-micro-structure&#x2F;#sovms&quot;&gt;core concept&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;packages-crates-and-modules-in-rust&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#packages-crates-and-modules-in-rust&quot; aria-label=&quot;Anchor link for: packages-crates-and-modules-in-rust&quot;&gt;&lt;i class=&quot;icon&quot;&gt;&lt;&#x2F;i&gt;&lt;&#x2F;a&gt;
Packages, Crates, and Modules in Rust&lt;&#x2F;h2&gt;
&lt;blockquote&gt;
&lt;p&gt;If you’re not familiar with Rust, I recommend studying the original source - the chapter &lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;doc.rust-lang.org&#x2F;book&#x2F;ch07-00-managing-growing-projects-with-packages-crates-and-modules.html&quot;&gt;Managing Growing Projects with Packages, Crates and Module&lt;&#x2F;a&gt; in the official Rust documentation. What follows is my interpretation, which may be inaccurate or incomplete.&lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
&lt;p&gt;So, in Rust projects we have:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;A Package containing:
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;Cargo(.toml | .lock)&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;One or many crates, each having:
&lt;ul&gt;
&lt;li&gt;A crate root - &lt;code&gt;src&#x2F;(lib.rs | main.rs | bin&#x2F;*.rs)&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;Modules
&lt;ul&gt;
&lt;li&gt;inline - &lt;code&gt;mod _name_ { _body }&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;as separate files - &lt;code&gt;mod _name_;&lt;&#x2F;code&gt; + &lt;code&gt;src&#x2F;(_name_.rs | _name_&#x2F;mod.rs)&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;This creates a nesting doll or the tale of Koschei the Deathless - the needle (module) in an egg, the egg (crate) in a chicken, the chicken (package) in a chest (project).&lt;&#x2F;p&gt;
&lt;p&gt;&lt;img src=&quot;&#x2F;images&#x2F;2024_12_13_rust_micro_structure_01.png&quot; alt=&quot;Packages in Rust&quot; loading=&quot;lazy&quot; decoding=&quot;async&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;p&gt;Let’s examine the rules for accessing modules.&lt;&#x2F;p&gt;
&lt;ol&gt;
&lt;li&gt;Modules can be private (hidden) and public.
&lt;ol&gt;
&lt;li&gt;By default, modules are private.&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;Entities inside a module can also be private and public.
&lt;ol&gt;
&lt;li&gt;By default, entities are private.&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;And then interesting interactions and combinations begin, which I propose to examine with code examples.&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color-scheme: light dark; color: light-dark(#C6D0F5, #565869); background-color: light-dark(#303446, #FAFBFC);&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#CA9EE6, #F767BB);&quot;&gt;mod&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#EF9F76, #565869);&quot;&gt; parent&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#CA9EE6, #F767BB);&quot;&gt;    mod&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#EF9F76, #565869);&quot;&gt; children_private&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#CA9EE6, #F767BB);&quot;&gt;        struct&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#E5C890, #565869);font-style: italic;&quot;&gt; Private&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#CA9EE6, #F767BB);&quot;&gt;        pub&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#CA9EE6, #F767BB);&quot;&gt; struct&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#E5C890, #565869);font-style: italic;&quot;&gt; Public&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&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: light-dark(#CA9EE6, #F767BB);&quot;&gt;    pub&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#CA9EE6, #F767BB);&quot;&gt; mod&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#EF9F76, #565869);&quot;&gt; children_public&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#CA9EE6, #F767BB);&quot;&gt;        struct&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#E5C890, #565869);font-style: italic;&quot;&gt; Private&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#CA9EE6, #F767BB);&quot;&gt;        pub&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#CA9EE6, #F767BB);&quot;&gt; struct&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#E5C890, #565869);font-style: italic;&quot;&gt; Public&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&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: light-dark(#CA9EE6, #F767BB);&quot;&gt;        mod&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#EF9F76, #565869);&quot;&gt; grandchildren&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#CA9EE6, #F767BB);&quot;&gt;            struct&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#E5C890, #565869);font-style: italic;&quot;&gt; Private&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#CA9EE6, #F767BB);&quot;&gt;            pub&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#CA9EE6, #F767BB);&quot;&gt; struct&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#E5C890, #565869);font-style: italic;&quot;&gt; Public&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;        }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;    }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&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: light-dark(#CA9EE6, #F767BB);&quot;&gt;mod&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#EF9F76, #565869);&quot;&gt; neighbour&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Visually, the structure looks like this:&lt;&#x2F;p&gt;
&lt;p&gt;&lt;img src=&quot;&#x2F;images&#x2F;2024_12_13_rust_micro_structure_02.png&quot; alt=&quot;Structure&quot; loading=&quot;lazy&quot; decoding=&quot;async&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;p&gt;With this example, I want to show you the possible connections between modules and entities (in this example, we limit ourselves to empty structs).&lt;&#x2F;p&gt;
&lt;p&gt;Let’s break this down into several situations, which we’ll distinguish by the calling side.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#&quot; aria-label=&quot;Anchor link for: &quot;&gt;&lt;i class=&quot;icon&quot;&gt;&lt;&#x2F;i&gt;&lt;&#x2F;a&gt;
What Can a Parent Module Access?&lt;&#x2F;h3&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color-scheme: light dark; color: light-dark(#C6D0F5, #565869); background-color: light-dark(#303446, #FAFBFC);&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#CA9EE6, #F767BB);&quot;&gt;fn&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#8CAAEE, #09A1ED);font-style: italic;&quot;&gt; test_visibility&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);font-style: italic;&quot;&gt;	&#x2F;&#x2F;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);font-style: italic;&quot;&gt; children_private::Private; &#x2F;&#x2F; Fails due to privacy of struct&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#E5C890, #565869);&quot;&gt;	children_private&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#E5C890, #13BBB7);font-style: italic;&quot;&gt;Public&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);font-style: italic;&quot;&gt;	&#x2F;&#x2F;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);font-style: italic;&quot;&gt; children_public::Private; &#x2F;&#x2F; Fails due to privacy of struct&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#E5C890, #565869);&quot;&gt;	children_public&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#E5C890, #13BBB7);font-style: italic;&quot;&gt;Public&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);font-style: italic;&quot;&gt;	&#x2F;&#x2F;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);font-style: italic;&quot;&gt; children_public::grandchildren::Private; &#x2F;&#x2F; Fails due to privacy of module.&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);font-style: italic;&quot;&gt;	&#x2F;&#x2F;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);font-style: italic;&quot;&gt; children_public::grandchildren::Public; &#x2F;&#x2F; Fails due to privacy of module.&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Above, I show a test snippet for the parent module. As we can see, access is available to both (private and public) child modules, but only to public structs. Access to private “grandchildren” and their public structs is not available. Visually, this looks like:&lt;&#x2F;p&gt;
&lt;p&gt;&lt;img src=&quot;&#x2F;images&#x2F;2024_12_13_rust_micro_structure_03.png&quot; alt=&quot;Parent&quot; loading=&quot;lazy&quot; decoding=&quot;async&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;h3 id=&quot;-1&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#-1&quot; aria-label=&quot;Anchor link for: -1&quot;&gt;&lt;i class=&quot;icon&quot;&gt;&lt;&#x2F;i&gt;&lt;&#x2F;a&gt;
What Can a Child Module Access?&lt;&#x2F;h3&gt;
&lt;p&gt;For this, we’ll make an addition and add two structs to the parent module, analogous to the children.&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color-scheme: light dark; color: light-dark(#C6D0F5, #565869); background-color: light-dark(#303446, #FAFBFC);&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);font-style: italic;&quot;&gt;&#x2F;&#x2F;&#x2F;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);font-style: italic;&quot;&gt; Test visibility of super model and another sub-models of module one level above.&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#CA9EE6, #F767BB);&quot;&gt;fn&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#8CAAEE, #09A1ED);font-style: italic;&quot;&gt; test_visibility&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#CA9EE6, #F767BB);&quot;&gt;	super&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#E5C890, #13BBB7);font-style: italic;&quot;&gt;Public&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#CA9EE6, #F767BB);&quot;&gt;	super&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#E5C890, #13BBB7);font-style: italic;&quot;&gt;Private&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);font-style: italic;&quot;&gt;	&#x2F;&#x2F;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);font-style: italic;&quot;&gt; super::children_private::Private; &#x2F;&#x2F; Fails due to privacy of struct&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#CA9EE6, #F767BB);&quot;&gt;	super&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#E5C890, #565869);&quot;&gt;children_private&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#E5C890, #13BBB7);font-style: italic;&quot;&gt;Public&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);font-style: italic;&quot;&gt;	&#x2F;&#x2F;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);font-style: italic;&quot;&gt; self::grandchildren::Private; &#x2F;&#x2F; Fails due to privacy of struct&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#E78284, #2DAE58);&quot;&gt;    self&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#E5C890, #565869);&quot;&gt;grandchildren&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#E5C890, #13BBB7);font-style: italic;&quot;&gt;Public&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;&lt;img src=&quot;&#x2F;images&#x2F;2024_12_13_rust_micro_structure_04.png&quot; alt=&quot;Child&quot; loading=&quot;lazy&quot; decoding=&quot;async&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;p&gt;As we can see, our child’s tentacles reach quite far, and only private structs of sibling and child modules are inaccessible. However, private structs of the parent module are well within reach.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;-2&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#-2&quot; aria-label=&quot;Anchor link for: -2&quot;&gt;&lt;i class=&quot;icon&quot;&gt;&lt;&#x2F;i&gt;&lt;&#x2F;a&gt;
What Can a Great-Grandchild Access?&lt;&#x2F;h3&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color-scheme: light dark; color: light-dark(#C6D0F5, #565869); background-color: light-dark(#303446, #FAFBFC);&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);font-style: italic;&quot;&gt;&#x2F;&#x2F;&#x2F;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);font-style: italic;&quot;&gt; Test visibility of super model and another sub-models of module two levels above.&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#CA9EE6, #F767BB);&quot;&gt;fn&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#8CAAEE, #09A1ED);font-style: italic;&quot;&gt; test_visibility&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#CA9EE6, #F767BB);&quot;&gt;	super&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#E5C890, #13BBB7);font-style: italic;&quot;&gt;Private&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#CA9EE6, #F767BB);&quot;&gt;	super&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#E5C890, #13BBB7);font-style: italic;&quot;&gt;Public&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);font-style: italic;&quot;&gt;	&#x2F;&#x2F;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);font-style: italic;&quot;&gt; super::super::children_private::Private; &#x2F;&#x2F; Fails due to privacy of struct&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#CA9EE6, #F767BB);&quot;&gt;	super&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#CA9EE6, #F767BB);&quot;&gt;super&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#E5C890, #565869);&quot;&gt;children_private&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#E5C890, #13BBB7);font-style: italic;&quot;&gt;Public&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#CA9EE6, #F767BB);&quot;&gt;	super&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#CA9EE6, #F767BB);&quot;&gt;super&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#E5C890, #13BBB7);font-style: italic;&quot;&gt;Private&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#CA9EE6, #F767BB);&quot;&gt;	super&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#CA9EE6, #F767BB);&quot;&gt;super&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#E5C890, #13BBB7);font-style: italic;&quot;&gt;Public&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;&lt;img src=&quot;&#x2F;images&#x2F;2024_12_13_rust_micro_structure_05.png&quot; alt=&quot;Great-grandchild&quot; loading=&quot;lazy&quot; decoding=&quot;async&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;p&gt;For the great-grandchild, the situation is similar. I decided to show it for better understanding of how this multi-level mechanism works in Rust.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;-3&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#-3&quot; aria-label=&quot;Anchor link for: -3&quot;&gt;&lt;i class=&quot;icon&quot;&gt;&lt;&#x2F;i&gt;&lt;&#x2F;a&gt;
What Can a Neighbor Access?&lt;&#x2F;h3&gt;
&lt;blockquote&gt;
&lt;p&gt;Unfortunately, I only noticed at this stage that all diagrams up to this point included the neighbor inside the parent module. In reality, it’s located alongside, not inside the parent. The diagram below contains the correct placement of this module.&lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color-scheme: light dark; color: light-dark(#C6D0F5, #565869); background-color: light-dark(#303446, #FAFBFC);&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);font-style: italic;&quot;&gt;&#x2F;&#x2F;&#x2F;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);font-style: italic;&quot;&gt; Test visibilit of sub-modules inside another module on the same level.&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#CA9EE6, #F767BB);&quot;&gt;fn&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#8CAAEE, #09A1ED);font-style: italic;&quot;&gt; test_visibility&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#CA9EE6, #F767BB);&quot;&gt;	crate&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#E5C890, #565869);&quot;&gt;parent&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#E5C890, #13BBB7);font-style: italic;&quot;&gt;Public&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);font-style: italic;&quot;&gt;	&#x2F;&#x2F;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);font-style: italic;&quot;&gt; crate::parent::Private; &#x2F;&#x2F; Fails due to privacy of struct&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);font-style: italic;&quot;&gt;	&#x2F;&#x2F;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);font-style: italic;&quot;&gt; crate::parent::children_private::Private; &#x2F;&#x2F; Fails due to privacy of module&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);font-style: italic;&quot;&gt;	&#x2F;&#x2F;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);font-style: italic;&quot;&gt; crate::parent::children_private::Public; &#x2F;&#x2F; Fails due to privacy of module&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);font-style: italic;&quot;&gt;	&#x2F;&#x2F;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);font-style: italic;&quot;&gt; crate::parent::children_public::Private; &#x2F;&#x2F; Fails due to privacy of struct&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#CA9EE6, #F767BB);&quot;&gt;	crate&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#E5C890, #565869);&quot;&gt;parent&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#E5C890, #565869);&quot;&gt;children_public&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#E5C890, #13BBB7);font-style: italic;&quot;&gt;Public&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);font-style: italic;&quot;&gt;	&#x2F;&#x2F;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);font-style: italic;&quot;&gt; crate::parent::children_public::grandchildren::Private; &#x2F;&#x2F; Fails due to privacy of a module&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);font-style: italic;&quot;&gt;	&#x2F;&#x2F;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);font-style: italic;&quot;&gt; crate::parent::children_public::grandchildren::Public; &#x2F;&#x2F; Fails due to privacy of a module&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;&lt;img src=&quot;&#x2F;images&#x2F;2024_12_13_rust_micro_structure_06.png&quot; alt=&quot;Neighbor&quot; loading=&quot;lazy&quot; decoding=&quot;async&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;p&gt;The neighbor’s situation is quite boring - only public entities and paths to them are accessible. Note that the parent module is not public, yet the neighbor can still see it 👀&lt;&#x2F;p&gt;
&lt;h2 id=&quot;sovms&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#sovms&quot; aria-label=&quot;Anchor link for: sovms&quot;&gt;&lt;i class=&quot;icon&quot;&gt;&lt;&#x2F;i&gt;&lt;&#x2F;a&gt;
SOVMS&lt;&#x2F;h2&gt;
&lt;p&gt;Or Structure Based on Visibility of Modules. The idea is that in Rust, we already have defined access rules (which I described in detail above) to module entities depending on their relationships (what relationship the calling module has to the called module).&lt;&#x2F;p&gt;
&lt;blockquote&gt;
&lt;p&gt;I decided that the project structure should also be laid out based on these Rust language features to be more idiomatic. The idea is new, and as I test it, I’ll update this post.&lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
&lt;p&gt;To get an idiomatic project structure, we should place modules based on who and what should see them. Is this part of the code used throughout the entire service? Move it as high as possible. Is another part of the code specific? Isolate it in a separate branch or hide it deeper.&lt;&#x2F;p&gt;
&lt;p&gt;The point is that modules shouldn’t be decomposed according to business domains (at least this shouldn’t be the basis of division). After all, in microservice architecture, these should be separate services (or separate Rust packages for monolithic applications). This way, we strive for the coveted golden ratio of &lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Larry_Constantine#Structured_design&quot;&gt;loose coupling and high cohesion&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;-4&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#-4&quot; aria-label=&quot;Anchor link for: -4&quot;&gt;&lt;i class=&quot;icon&quot;&gt;&lt;&#x2F;i&gt;&lt;&#x2F;a&gt;
TL;DR&lt;&#x2F;h3&gt;
&lt;p&gt;How do I see using this approach in writing microservices? Let me not waste more of your time reading my thoughts and show you a template:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color-scheme: light dark; color: light-dark(#C6D0F5, #565869); background-color: light-dark(#303446, #FAFBFC);&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);font-style: italic;&quot;&gt;&#x2F;&#x2F;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);font-style: italic;&quot;&gt;! This is the base service crate. Better to make it a library, so functionality regarding how&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);font-style: italic;&quot;&gt;&#x2F;&#x2F;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);font-style: italic;&quot;&gt;! exactly to run it will be stored separately inside one main.rs or different bins.&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: light-dark(#CA9EE6, #F767BB);&quot;&gt;mod&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#EF9F76, #565869);&quot;&gt; interfaces&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);font-style: italic;&quot;&gt;    &#x2F;&#x2F;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);font-style: italic;&quot;&gt;!&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#CA9EE6, #F767BB);&quot;&gt;    mod&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#EF9F76, #565869);&quot;&gt; graphql&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);font-style: italic;&quot;&gt;        &#x2F;&#x2F;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);font-style: italic;&quot;&gt;!&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&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: light-dark(#CA9EE6, #F767BB);&quot;&gt;    mod&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#EF9F76, #565869);&quot;&gt; http&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);font-style: italic;&quot;&gt;        &#x2F;&#x2F;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);font-style: italic;&quot;&gt;!&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&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: light-dark(#CA9EE6, #F767BB);&quot;&gt;    mod&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#EF9F76, #565869);&quot;&gt; grpc&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);font-style: italic;&quot;&gt;        &#x2F;&#x2F;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);font-style: italic;&quot;&gt;!&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;    }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&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: light-dark(#CA9EE6, #F767BB);&quot;&gt;mod&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#EF9F76, #565869);&quot;&gt; core&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);font-style: italic;&quot;&gt;    &#x2F;&#x2F;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);font-style: italic;&quot;&gt;!&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#CA9EE6, #F767BB);&quot;&gt;    mod&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#EF9F76, #565869);&quot;&gt; api&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);font-style: italic;&quot;&gt;        &#x2F;&#x2F;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);font-style: italic;&quot;&gt;!&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&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: light-dark(#CA9EE6, #F767BB);&quot;&gt;    mod&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#EF9F76, #565869);&quot;&gt; config&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);font-style: italic;&quot;&gt;        &#x2F;&#x2F;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);font-style: italic;&quot;&gt;!&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;    }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&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: light-dark(#CA9EE6, #F767BB);&quot;&gt;mod&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#EF9F76, #565869);&quot;&gt; resources&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);font-style: italic;&quot;&gt;    &#x2F;&#x2F;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);font-style: italic;&quot;&gt;!&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#CA9EE6, #F767BB);&quot;&gt;    mod&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#EF9F76, #565869);&quot;&gt; db&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);font-style: italic;&quot;&gt;        &#x2F;&#x2F;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);font-style: italic;&quot;&gt;!&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&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: light-dark(#CA9EE6, #F767BB);&quot;&gt;    mod&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#EF9F76, #565869);&quot;&gt; kafka&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);font-style: italic;&quot;&gt;        &#x2F;&#x2F;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);font-style: italic;&quot;&gt;!&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&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: light-dark(#CA9EE6, #F767BB);&quot;&gt;    mod&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#EF9F76, #565869);&quot;&gt; third_party_integration&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);font-style: italic;&quot;&gt;        &#x2F;&#x2F;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);font-style: italic;&quot;&gt;!&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;    }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;You can create a new package with two crates:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;main is responsible only for starting the application&lt;&#x2F;li&gt;
&lt;li&gt;lib stores the structure and is used in main, tests (integration), and additional “bins” if needed&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h3 id=&quot;-5&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#-5&quot; aria-label=&quot;Anchor link for: -5&quot;&gt;&lt;i class=&quot;icon&quot;&gt;&lt;&#x2F;i&gt;&lt;&#x2F;a&gt;
Real Example&lt;&#x2F;h3&gt;
&lt;p&gt;In this example, some names have been changed, but this is a real structure of one of several services. Writing them actually prompted me to derive some general theory regarding structuring microservices in Rust.&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color-scheme: light dark; color: light-dark(#C6D0F5, #565869); background-color: light-dark(#303446, #FAFBFC);&quot;&gt;&lt;code data-lang=&quot;shellscript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8CAAEE, #09A1ED);font-style: italic;&quot;&gt;src&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8CAAEE, #09A1ED);font-style: italic;&quot;&gt;├──&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#A6D189, #CF9C00);&quot;&gt; bin&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8CAAEE, #09A1ED);font-style: italic;&quot;&gt;│&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#A6D189, #CF9C00);&quot;&gt;   └──&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#A6D189, #CF9C00);&quot;&gt; events_processor.rs&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8CAAEE, #09A1ED);font-style: italic;&quot;&gt;├──&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#A6D189, #CF9C00);&quot;&gt; core&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8CAAEE, #09A1ED);font-style: italic;&quot;&gt;│&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#A6D189, #CF9C00);&quot;&gt;   ├──&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#A6D189, #CF9C00);&quot;&gt; api.rs&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8CAAEE, #09A1ED);font-style: italic;&quot;&gt;│&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#A6D189, #CF9C00);&quot;&gt;   ├──&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#A6D189, #CF9C00);&quot;&gt; configuration.rs&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8CAAEE, #09A1ED);font-style: italic;&quot;&gt;│&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#A6D189, #CF9C00);&quot;&gt;   └──&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#A6D189, #CF9C00);&quot;&gt; mod.rs&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8CAAEE, #09A1ED);font-style: italic;&quot;&gt;├──&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#A6D189, #CF9C00);&quot;&gt; interfaces&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8CAAEE, #09A1ED);font-style: italic;&quot;&gt;│&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#A6D189, #CF9C00);&quot;&gt;   ├──&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#A6D189, #CF9C00);&quot;&gt; graphql&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8CAAEE, #09A1ED);font-style: italic;&quot;&gt;│&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#A6D189, #CF9C00);&quot;&gt;   │&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#A6D189, #CF9C00);&quot;&gt;   ├──&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#A6D189, #CF9C00);&quot;&gt; mod.rs&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8CAAEE, #09A1ED);font-style: italic;&quot;&gt;│&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#A6D189, #CF9C00);&quot;&gt;   │&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#A6D189, #CF9C00);&quot;&gt;   ├──&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#A6D189, #CF9C00);&quot;&gt; mutations.rs&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8CAAEE, #09A1ED);font-style: italic;&quot;&gt;│&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#A6D189, #CF9C00);&quot;&gt;   │&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#A6D189, #CF9C00);&quot;&gt;   ├──&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#A6D189, #CF9C00);&quot;&gt; queries.rs&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8CAAEE, #09A1ED);font-style: italic;&quot;&gt;│&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#A6D189, #CF9C00);&quot;&gt;   │&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#A6D189, #CF9C00);&quot;&gt;   └──&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#A6D189, #CF9C00);&quot;&gt; subscriptions.rs&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8CAAEE, #09A1ED);font-style: italic;&quot;&gt;│&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#A6D189, #CF9C00);&quot;&gt;   └──&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#A6D189, #CF9C00);&quot;&gt; mod.rs&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8CAAEE, #09A1ED);font-style: italic;&quot;&gt;├──&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#A6D189, #CF9C00);&quot;&gt; lib.rs&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8CAAEE, #09A1ED);font-style: italic;&quot;&gt;├──&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#A6D189, #CF9C00);&quot;&gt; main.rs&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8CAAEE, #09A1ED);font-style: italic;&quot;&gt;└──&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#A6D189, #CF9C00);&quot;&gt; resources&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8CAAEE, #09A1ED);font-style: italic;&quot;&gt;    ├──&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#A6D189, #CF9C00);&quot;&gt; node_proxy.rs&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8CAAEE, #09A1ED);font-style: italic;&quot;&gt;    ├──&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#A6D189, #CF9C00);&quot;&gt; indexer_proxy.rs&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8CAAEE, #09A1ED);font-style: italic;&quot;&gt;    ├──&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#A6D189, #CF9C00);&quot;&gt; db.rs&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8CAAEE, #09A1ED);font-style: italic;&quot;&gt;    ├──&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#A6D189, #CF9C00);&quot;&gt; mod.rs&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8CAAEE, #09A1ED);font-style: italic;&quot;&gt;    ├──&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#A6D189, #CF9C00);&quot;&gt; reservoir_proxy.rs&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8CAAEE, #09A1ED);font-style: italic;&quot;&gt;    └──&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#A6D189, #CF9C00);&quot;&gt; real_time_data_ws.rs&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;&lt;h3 id=&quot;-6&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#-6&quot; aria-label=&quot;Anchor link for: -6&quot;&gt;&lt;i class=&quot;icon&quot;&gt;&lt;&#x2F;i&gt;&lt;&#x2F;a&gt;
My Experience&lt;&#x2F;h3&gt;
&lt;p&gt;I can say that I find this structure convenient because it combines the advantages of the good old three-layer architectures and hexagonal architectures applicable to microservices. We divide our application into three branches:&lt;&#x2F;p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;code&gt;Resources&lt;&#x2F;code&gt; - everything that’s outside our service and where we’re consumers goes here. Databases, other services, message brokers (partially). Everything where we initiate communication and where we know more about the interlocutor than they know about us. (Previously I called this part &lt;code&gt;clients&lt;&#x2F;code&gt;, but the name resources seems more appropriate now). The main task of resources is to handle the specifics of interacting with these resources. Here we can have implementations of traits for encoding and decoding our data types for a specific database, and here we write “proxies” that transform schemas of other services into the one we operate with inside the service.&lt;&#x2F;li&gt;
&lt;li&gt;&lt;code&gt;Interfaces&lt;&#x2F;code&gt; - everything that serves as entry points for requests to our service goes here. HTTP&#x2F;gRPC API, GraphQL, even message brokers if it’s part of processing incoming requests - everything goes here. Just like resources, here we try to isolate all specifics related to the particular mechanism of client-server interaction (that’s why I previously called this part &lt;code&gt;servers&lt;&#x2F;code&gt;). For example, all request deserializations and response serializations should be implemented here. After that, we should work with “clean” types.&lt;&#x2F;li&gt;
&lt;li&gt;&lt;code&gt;Core&lt;&#x2F;code&gt; - this is the “cleanest” and “most important” place in our service. The main business logic is implemented here. Here we operate not with JSON that came over the network, but with its statically typed and verified representation. From the core, we can call resources, but ideally should know nothing about interfaces. However, we shouldn’t have access to low-level concepts of resources. Only to the public API.&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;p&gt;How does module placement help here? We see that all three branches are neighbors to each other, meaning they can only know public things, and specifics are safe to change (for example, changing the database or supporting REST alongside gRPC).&lt;&#x2F;p&gt;
&lt;p&gt;Inside branches, we go from general to specific and also separate independent parts into branches.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;code&gt;graphql&lt;&#x2F;code&gt; consists of independent &lt;code&gt;queries&lt;&#x2F;code&gt;, &lt;code&gt;mutations&lt;&#x2F;code&gt;, &lt;code&gt;subscriptions&lt;&#x2F;code&gt;, but the common schema is in the root module:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color-scheme: light dark; color: light-dark(#C6D0F5, #565869); background-color: light-dark(#303446, #FAFBFC);&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);font-style: italic;&quot;&gt;&#x2F;&#x2F;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);font-style: italic;&quot;&gt;! graphql&#x2F;mod.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: light-dark(#CA9EE6, #F767BB);&quot;&gt;pub&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#CA9EE6, #F767BB);&quot;&gt; async&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#CA9EE6, #F767BB);&quot;&gt; fn&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#8CAAEE, #09A1ED);font-style: italic;&quot;&gt; schema&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt; -&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#E5C890, #13BBB7);font-style: italic;&quot;&gt; Result&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#99D1DB, #ADB1C2);&quot;&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#E5C890, #13BBB7);font-style: italic;&quot;&gt;Schema&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#99D1DB, #ADB1C2);&quot;&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#E5C890, #13BBB7);font-style: italic;&quot;&gt;Query&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#E5C890, #13BBB7);font-style: italic;&quot;&gt; Mutation&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#E5C890, #13BBB7);font-style: italic;&quot;&gt; Subscription&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#99D1DB, #ADB1C2);&quot;&gt;&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#99D1DB, #ADB1C2);&quot;&gt;&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#CA9EE6, #F767BB);&quot;&gt;    let&lt;&#x2F;span&gt;&lt;span&gt; configuration&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#E5C890, #13BBB7);font-style: italic;&quot;&gt; Configuration&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#8CAAEE, #09A1ED);font-style: italic;&quot;&gt;from_env&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt;?&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#CA9EE6, #F767BB);&quot;&gt;    let&lt;&#x2F;span&gt;&lt;span&gt; pool&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#E5C890, #565869);&quot;&gt; database&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#8CAAEE, #09A1ED);font-style: italic;&quot;&gt;connect&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt;&amp;amp;&lt;&#x2F;span&gt;&lt;span&gt;configuration&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#8CAAEE, #565869);&quot;&gt;database&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#CA9EE6, #F767BB);&quot;&gt;await&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt;?&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#CA9EE6, #F767BB);&quot;&gt;    let&lt;&#x2F;span&gt;&lt;span&gt; producer&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#E5C890, #565869);&quot;&gt; kafka&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#8CAAEE, #09A1ED);font-style: italic;&quot;&gt;build_producer&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt;&amp;amp;&lt;&#x2F;span&gt;&lt;span&gt;configuration&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#8CAAEE, #565869);&quot;&gt;kafka&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt;?&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#E5C890, #565869);font-style: italic;&quot;&gt;    Ok&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#E5C890, #13BBB7);font-style: italic;&quot;&gt;Schema&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#8CAAEE, #09A1ED);font-style: italic;&quot;&gt;build&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#E5C890, #13BBB7);font-style: italic;&quot;&gt;Query&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#E5C890, #13BBB7);font-style: italic;&quot;&gt; Mutation&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#E5C890, #13BBB7);font-style: italic;&quot;&gt; Subscription&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt;        .&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#8CAAEE, #09A1ED);font-style: italic;&quot;&gt;enable_federation&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt;        .&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#8CAAEE, #09A1ED);font-style: italic;&quot;&gt;enable_subscription_in_federation&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt;...&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Each sub-module will call public “clean” methods from &lt;code&gt;core&#x2F;api.rs&lt;&#x2F;code&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;code&gt;api.rs&lt;&#x2F;code&gt; in my example contains common types in the root (both private and public), which its sub-modules &lt;code&gt;api::queries&lt;&#x2F;code&gt; and &lt;code&gt;api::commands&lt;&#x2F;code&gt; have full access to, but private types and implementations of the &lt;code&gt;api&lt;&#x2F;code&gt; module itself are inaccessible to anyone except its sub-modules.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;-7&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#-7&quot; aria-label=&quot;Anchor link for: -7&quot;&gt;&lt;i class=&quot;icon&quot;&gt;&lt;&#x2F;i&gt;&lt;&#x2F;a&gt;
Additional Materials&lt;&#x2F;h2&gt;
&lt;p&gt;If you’re interested in “playing” with the example from this article, here’s the full project code from the modules chapter:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color-scheme: light dark; color: light-dark(#C6D0F5, #565869); background-color: light-dark(#303446, #FAFBFC);&quot;&gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#E5C890, #ADB1C2);font-style: italic;&quot;&gt;#&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#E5C890, #565869);font-style: italic;&quot;&gt;!&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;[&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#E5C890, #565869);font-style: italic;&quot;&gt;allow&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#E5C890, #565869);font-style: italic;&quot;&gt;clippy&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#E5C890, #565869);font-style: italic;&quot;&gt;all&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#E5C890, #565869);font-style: italic;&quot;&gt; dead_code&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#E5C890, #565869);font-style: italic;&quot;&gt; path_statements&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&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: light-dark(#CA9EE6, #F767BB);&quot;&gt;fn&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#8CAAEE, #09A1ED);font-style: italic;&quot;&gt; main&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8CAAEE, #09A1ED);font-style: italic;&quot;&gt;    println!&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#A6D189, #ADB1C2);&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#A6D189, #CF9C00);&quot;&gt;Hello, modules privacy!&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#A6D189, #ADB1C2);&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&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: light-dark(#CA9EE6, #F767BB);&quot;&gt;mod&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#EF9F76, #565869);&quot;&gt; parent&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#CA9EE6, #F767BB);&quot;&gt;    struct&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#E5C890, #565869);font-style: italic;&quot;&gt; Private&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#CA9EE6, #F767BB);&quot;&gt;    pub&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#CA9EE6, #F767BB);&quot;&gt; struct&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#E5C890, #565869);font-style: italic;&quot;&gt; Public&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&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: light-dark(#CA9EE6, #F767BB);&quot;&gt;    mod&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#EF9F76, #565869);&quot;&gt; children_private&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#CA9EE6, #F767BB);&quot;&gt;        struct&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#E5C890, #565869);font-style: italic;&quot;&gt; Private&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#CA9EE6, #F767BB);&quot;&gt;        pub&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#CA9EE6, #F767BB);&quot;&gt; struct&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#E5C890, #565869);font-style: italic;&quot;&gt; Public&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&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: light-dark(#CA9EE6, #F767BB);&quot;&gt;    pub&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#CA9EE6, #F767BB);&quot;&gt; mod&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#EF9F76, #565869);&quot;&gt; children_public&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#CA9EE6, #F767BB);&quot;&gt;        struct&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#E5C890, #565869);font-style: italic;&quot;&gt; Private&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#CA9EE6, #F767BB);&quot;&gt;        pub&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#CA9EE6, #F767BB);&quot;&gt; struct&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#E5C890, #565869);font-style: italic;&quot;&gt; Public&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&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: light-dark(#CA9EE6, #F767BB);&quot;&gt;        mod&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#EF9F76, #565869);&quot;&gt; grandchildren&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#CA9EE6, #F767BB);&quot;&gt;            struct&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#E5C890, #565869);font-style: italic;&quot;&gt; Private&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#CA9EE6, #F767BB);&quot;&gt;            pub&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#CA9EE6, #F767BB);&quot;&gt; struct&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#E5C890, #565869);font-style: italic;&quot;&gt; Public&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&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: light-dark(#949CBB, #ADB1C2);font-style: italic;&quot;&gt;            &#x2F;&#x2F;&#x2F;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);font-style: italic;&quot;&gt; Test visibility of super model and another sub-models of module two levels above.&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#CA9EE6, #F767BB);&quot;&gt;            fn&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#8CAAEE, #09A1ED);font-style: italic;&quot;&gt; test_visibility&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#CA9EE6, #F767BB);&quot;&gt;                super&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#E5C890, #13BBB7);font-style: italic;&quot;&gt;Private&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#CA9EE6, #F767BB);&quot;&gt;                super&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#E5C890, #13BBB7);font-style: italic;&quot;&gt;Public&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);font-style: italic;&quot;&gt;                &#x2F;&#x2F;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);font-style: italic;&quot;&gt; super::super::children_private::Private; &#x2F;&#x2F; Fails due to privacy of struct&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#CA9EE6, #F767BB);&quot;&gt;                super&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#CA9EE6, #F767BB);&quot;&gt;super&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#E5C890, #565869);&quot;&gt;children_private&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#E5C890, #13BBB7);font-style: italic;&quot;&gt;Public&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#CA9EE6, #F767BB);&quot;&gt;                super&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#CA9EE6, #F767BB);&quot;&gt;super&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#E5C890, #13BBB7);font-style: italic;&quot;&gt;Private&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#CA9EE6, #F767BB);&quot;&gt;                super&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#CA9EE6, #F767BB);&quot;&gt;super&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#E5C890, #13BBB7);font-style: italic;&quot;&gt;Public&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;            }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&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: light-dark(#949CBB, #ADB1C2);font-style: italic;&quot;&gt;        &#x2F;&#x2F;&#x2F;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);font-style: italic;&quot;&gt; Test visibility of super model and another sub-models of module one level above.&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#CA9EE6, #F767BB);&quot;&gt;        fn&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#8CAAEE, #09A1ED);font-style: italic;&quot;&gt; test_visibility&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#CA9EE6, #F767BB);&quot;&gt;            super&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#E5C890, #13BBB7);font-style: italic;&quot;&gt;Public&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#CA9EE6, #F767BB);&quot;&gt;            super&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#E5C890, #13BBB7);font-style: italic;&quot;&gt;Private&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);font-style: italic;&quot;&gt;            &#x2F;&#x2F;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);font-style: italic;&quot;&gt; super::children_private::Private; &#x2F;&#x2F; Fails due to privacy of struct&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#CA9EE6, #F767BB);&quot;&gt;            super&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#E5C890, #565869);&quot;&gt;children_private&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#E5C890, #13BBB7);font-style: italic;&quot;&gt;Public&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);font-style: italic;&quot;&gt;            &#x2F;&#x2F;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);font-style: italic;&quot;&gt; self::grandchildren::Private; &#x2F;&#x2F; Fails due to privacy of struct&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#E78284, #2DAE58);&quot;&gt;            self&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#E5C890, #565869);&quot;&gt;grandchildren&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#E5C890, #13BBB7);font-style: italic;&quot;&gt;Public&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;        }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&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: light-dark(#949CBB, #ADB1C2);font-style: italic;&quot;&gt;    &#x2F;&#x2F;&#x2F;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);font-style: italic;&quot;&gt; Test visibility of sub-modules inside current module.&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#CA9EE6, #F767BB);&quot;&gt;    fn&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#8CAAEE, #09A1ED);font-style: italic;&quot;&gt; test_visibility&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);font-style: italic;&quot;&gt;        &#x2F;&#x2F;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);font-style: italic;&quot;&gt; children_private::Private; &#x2F;&#x2F; Fails due to privacy of struct&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#E5C890, #565869);&quot;&gt;        children_private&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#E5C890, #13BBB7);font-style: italic;&quot;&gt;Public&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);font-style: italic;&quot;&gt;        &#x2F;&#x2F;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);font-style: italic;&quot;&gt; children_public::Private; &#x2F;&#x2F; Fails due to privacy of struct&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#E5C890, #565869);&quot;&gt;        children_public&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#E5C890, #13BBB7);font-style: italic;&quot;&gt;Public&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);font-style: italic;&quot;&gt;        &#x2F;&#x2F;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);font-style: italic;&quot;&gt; children_public::grandchildren::Private; &#x2F;&#x2F; Fails due to privacy of module.&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);font-style: italic;&quot;&gt;        &#x2F;&#x2F;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);font-style: italic;&quot;&gt; children_public::grandchildren::Public; &#x2F;&#x2F; Fails due to privacy of module.&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;    }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&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: light-dark(#CA9EE6, #F767BB);&quot;&gt;mod&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#EF9F76, #565869);&quot;&gt; neighbour&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);font-style: italic;&quot;&gt;    &#x2F;&#x2F;&#x2F;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);font-style: italic;&quot;&gt; Test visibilit of sub-modules inside another module on the same level.&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#CA9EE6, #F767BB);&quot;&gt;    fn&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#8CAAEE, #09A1ED);font-style: italic;&quot;&gt; test_visibility&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#CA9EE6, #F767BB);&quot;&gt;        crate&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#E5C890, #565869);&quot;&gt;parent&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#E5C890, #13BBB7);font-style: italic;&quot;&gt;Public&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);font-style: italic;&quot;&gt;        &#x2F;&#x2F;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);font-style: italic;&quot;&gt; crate::parent::Private; &#x2F;&#x2F; Fails due to privacy of struct&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);font-style: italic;&quot;&gt;        &#x2F;&#x2F;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);font-style: italic;&quot;&gt; crate::parent::children_private::Private; &#x2F;&#x2F; Fails due to privacy of module&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);font-style: italic;&quot;&gt;        &#x2F;&#x2F;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);font-style: italic;&quot;&gt; crate::parent::children_private::Public; &#x2F;&#x2F; Fails due to privacy of module&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);font-style: italic;&quot;&gt;        &#x2F;&#x2F;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);font-style: italic;&quot;&gt; crate::parent::children_public::Private; &#x2F;&#x2F; Fails due to privacy of struct&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#CA9EE6, #F767BB);&quot;&gt;        crate&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#E5C890, #565869);&quot;&gt;parent&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#E5C890, #565869);&quot;&gt;children_public&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#81C8BE, #ADB1C2);&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#E5C890, #13BBB7);font-style: italic;&quot;&gt;Public&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);font-style: italic;&quot;&gt;        &#x2F;&#x2F;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);font-style: italic;&quot;&gt; crate::parent::children_public::grandchildren::Private; &#x2F;&#x2F; Fails due to privacy of a module&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);font-style: italic;&quot;&gt;        &#x2F;&#x2F;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);font-style: italic;&quot;&gt; crate::parent::children_public::grandchildren::Public; &#x2F;&#x2F; Fails due to privacy of a module&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;    }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#949CBB, #ADB1C2);&quot;&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;</content>
        
    </entry>
</feed>
