<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: tbxyz</title>
    <description>The latest articles on DEV Community by tbxyz (@tbxyz_0).</description>
    <link>https://dev.to/tbxyz_0</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3305653%2Fc5975ec1-adab-47b4-b518-433d123dfebd.png</url>
      <title>DEV Community: tbxyz</title>
      <link>https://dev.to/tbxyz_0</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/tbxyz_0"/>
    <language>en</language>
    <item>
      <title>A learning experience with NetworkManager and zbus</title>
      <dc:creator>tbxyz</dc:creator>
      <pubDate>Sun, 29 Jun 2025 14:16:31 +0000</pubDate>
      <link>https://dev.to/tbxyz_0/a-learning-experience-with-networkmanager-and-zbus-1emk</link>
      <guid>https://dev.to/tbxyz_0/a-learning-experience-with-networkmanager-and-zbus-1emk</guid>
      <description>&lt;p&gt;Traveling heavily recently, I've become fatigued from typing all the WiFi passphrases. My phone can happily connect via a QR code. Why does my laptop required so much typing, I asked. So I proposed a simple project.&lt;/p&gt;

&lt;p&gt;Researching how I might use my web-cam to connect to WiFi networks, I came across the &lt;a href="https://rbs.io/2024/07/network-manager-and-rusts-zbus/" rel="noopener noreferrer"&gt;Network Manager and Rust's Zbus article on rbs.io&lt;/a&gt;. I use &lt;code&gt;NewtworkManager&lt;/code&gt; and I enjoy working with &lt;code&gt;rust&lt;/code&gt;. I know next to nothing about DBus, but I thought some knowledge of hacking Linux networks couldn't do me any harm. Besides I had some free time.&lt;/p&gt;

&lt;p&gt;The above article set me on the right path. The &lt;code&gt;zbus&lt;/code&gt; documentation is still a little obscure in some salient details, however. Hopefully this post will help fill those in. The finished code is hosted in &lt;a href="https://github.com/tbro/scampi" rel="noopener noreferrer"&gt;the scampi repo&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;I first needed to generate a &lt;code&gt;settings.rs&lt;/code&gt; with &lt;code&gt;zbus-xmlgen&lt;/code&gt; as described in the above article. It is straightforward to create a connection by building the nested structures of &lt;code&gt;HashMap&lt;/code&gt;s also described there. While that solution works, it is tedious, unsightly and doesn't make the most of rust's type system. &lt;a href="https://github.com/dbus2/zbus/issues/312" rel="noopener noreferrer"&gt;Finding the issue for using &lt;code&gt;DeserializeStruct&lt;/code&gt; with nested structs closed&lt;/a&gt;, I hoped there might now be a more ergonomic way forward.&lt;/p&gt;

&lt;p&gt;With the help of the &lt;a href="https://dbus2.github.io/zbus/faq.html" rel="noopener noreferrer"&gt;zbus book&lt;/a&gt; I managed to piece together a solution that feels a little more rust-like. Of course there are many pieces to the puzzle. You need serde and the zvariant::Type macro. But all that is gleaned fairly easily from the documentation, I think. The more salient discovery was that zbus allows declaring &lt;a href="https://www.alteeve.com/w/List_of_DBus_data_types" rel="noopener noreferrer"&gt;DBbus signatures&lt;/a&gt; on your types. This is done via a macro, like so:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#[zvariant(signature = "a{sa{sv}}")]`
struct MyType{..}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Declaring the correct signature(&lt;code&gt;a{sa{sv}}&lt;/code&gt;) on the struct passed to &lt;code&gt;NetworkManager&lt;/code&gt;'s &lt;code&gt;Settings.add_connection()&lt;/code&gt; allowed it to navigate &lt;code&gt;Dbus&lt;/code&gt;'s type system. Its children don't have any children of their own, so &lt;code&gt;SerializedDict&lt;/code&gt; and &lt;code&gt;DeserializeDict&lt;/code&gt; works fine on them.&lt;/p&gt;

&lt;p&gt;For a more complete example you can have a look at &lt;a href="https://github.com/tbro/scampi/blob/9642b1a0ee6175469803bf572e13c90915b7d9e9/src/network_manager/mod.rs#L63-L73" rel="noopener noreferrer"&gt;the code&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;I believe I could go further and replace some fields defined as &lt;code&gt;String&lt;/code&gt; with more appropriate types, but it's one more thing to learn and I think this is good enough for now.&lt;/p&gt;

&lt;p&gt;Originally published in &lt;a href="https://tbro.github.io/posts/2025-06-27-network-manager-and-zbus.html" rel="noopener noreferrer"&gt;my blog&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>linux</category>
      <category>rust</category>
      <category>cli</category>
      <category>programming</category>
    </item>
  </channel>
</rss>
