<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:atom="http://www.w3.org/2005/Atom" version="2.0">
    <channel>
      <title>Devcartes - Rust</title>
      <link>https://devcartes.de</link>
      <description></description>
      <generator>Zola</generator>
      <language>de</language>
      <atom:link href="https://devcartes.de/tags/rust/rss.xml" rel="self" type="application/rss+xml"/>
      <lastBuildDate>Sun, 27 Sep 2026 00:00:00 +0000</lastBuildDate>
      <item>
          <title>Migration von Hugo zu Zola</title>
          <pubDate>Sun, 27 Sep 2026 00:00:00 +0000</pubDate>
          <author>Tristan</author>
          <link>https://devcartes.de/blog/migration/</link>
          <guid>https://devcartes.de/blog/migration/</guid>
          <description xml:base="https://devcartes.de/blog/migration/">&lt;h2 id=&quot;was-passiert-hier&quot;&gt;Was passiert hier&lt;/h2&gt;
&lt;p&gt;Ich habe mich nach langer Überlegung dazu entschlossen meine Website von &lt;a rel=&quot;external&quot; href=&quot;https://gohugo.io&quot;&gt;Hugo&lt;/a&gt; zu &lt;a rel=&quot;external&quot; href=&quot;https://www.getzola.org&quot;&gt;Zola&lt;/a&gt; umzuziehen.&lt;/p&gt;
&lt;p&gt;Du fragst dich nun vielleicht, &quot;Wer ist Hugo und was hat diese Zola mit ihm zu schaffen?&quot; und, wenn du meinen Blog schon eine Weile verfolgst, wirst du dich vielleicht ebenfalls fragen, &quot;Wo sind all die Artikel hin&quot;.&lt;/p&gt;
&lt;p&gt;Auf diese Fragen möchte ich in diesem Artikel kurz eingehen.&lt;/p&gt;
&lt;h2 id=&quot;hugo-und-zola&quot;&gt;Hugo und Zola&lt;/h2&gt;
&lt;h3 id=&quot;static-site-generators-ssg&quot;&gt;Static Site Generators (SSG)&lt;/h3&gt;
&lt;p&gt;&lt;a rel=&quot;external&quot; href=&quot;https://de.wikipedia.org/wiki/Statische_Webseite#Statische-Website-Generatoren&quot;&gt;Static Site Generators&lt;/a&gt; sind Programme, die aus Textdateien, oft &lt;a rel=&quot;external&quot; href=&quot;https://de.wikipedia.org/wiki/Markdown&quot;&gt;Markdown&lt;/a&gt;, eine &lt;a rel=&quot;external&quot; href=&quot;https://de.wikipedia.org/wiki/Statische_Webseite&quot;&gt;statische Webseite&lt;/a&gt; generieren.&lt;/p&gt;
&lt;p&gt;Statische Seiten haben Vorteile gegenüber dynamischen bzw. server-seitig gebauten Seiten:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Laden extrem schnell&lt;/li&gt;
&lt;li&gt;Sind sehr sicher (keine DB Zugriffe, kein JavaScript)&lt;/li&gt;
&lt;li&gt;Einfach neuen Content zu schreiben und zu veröffentlichen&lt;/li&gt;
&lt;li&gt;Kein spezieller Server zum Hosten benötigt&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&quot;hugo&quot;&gt;Hugo&lt;/h3&gt;
&lt;table&gt;&lt;thead&gt;&lt;tr&gt;&lt;th&gt;&lt;/th&gt;&lt;th&gt;&lt;/th&gt;&lt;/tr&gt;&lt;/thead&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;Sprache&lt;/td&gt;&lt;td&gt;Go&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;Setup&lt;/td&gt;&lt;td&gt;Ausführbare Binärdatei&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;Konfiguration&lt;/td&gt;&lt;td&gt;YAML, TOML, JSON&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;Template Engine&lt;/td&gt;&lt;td&gt;Go Template&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;Community&lt;/td&gt;&lt;td&gt;Groß&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;Komplexität&lt;/td&gt;&lt;td&gt;Hoch&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;Lernkurve&lt;/td&gt;&lt;td&gt;Steil&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;Dokumentation&lt;/td&gt;&lt;td&gt;Sehr gut&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;h3 id=&quot;zola&quot;&gt;Zola&lt;/h3&gt;
&lt;table&gt;&lt;thead&gt;&lt;tr&gt;&lt;th&gt;&lt;/th&gt;&lt;th&gt;&lt;/th&gt;&lt;/tr&gt;&lt;/thead&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;Sprache&lt;/td&gt;&lt;td&gt;Rust&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;Setup&lt;/td&gt;&lt;td&gt;Ausführbare Binärdatei&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;Konfiguration&lt;/td&gt;&lt;td&gt;TOML&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;Template Engine&lt;/td&gt;&lt;td&gt;Tera&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;Community&lt;/td&gt;&lt;td&gt;Klein&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;Komplexität&lt;/td&gt;&lt;td&gt;Niedrig&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;Lernkurve&lt;/td&gt;&lt;td&gt;Flach&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;Dokumentation&lt;/td&gt;&lt;td&gt;Sehr gut&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;h2 id=&quot;warum-das-ganze&quot;&gt;Warum das ganze&lt;/h2&gt;
&lt;p&gt;Ich finde Hugo nicht schlecht, im Gegenteil, es gab und gibt gute Gründe, warum ich mich ursprünglich dafür entschieden habe.
Deshalb möchte ich hier auch keinen wertenden Vergleich anstellen, sondern nur die wenigen Punkte hervorheben, die mich veranlasst haben zu wechseln.&lt;/p&gt;
&lt;p&gt;Was sind denn nun die Gründe für meinen Umzug?&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Schlankere Themes:&lt;/strong&gt; Die Zola Themes bestehen aus deutlich weniger Dateien und sind somit leichter anpassbar.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Tera:&lt;/strong&gt; Ist eine mächtige, einfach zu erlernende Template Engine, die ich aus einem anderen Projekt bereits kenne.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Schlichtheit:&lt;/strong&gt; Zola hat weniger Umfang, aber es macht genau das, was es soll und das mag ich an Werkzeugen.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;wann-ist-es-fertig&quot;&gt;Wann ist es fertig&lt;/h2&gt;
&lt;h3 id=&quot;technischer-stand&quot;&gt;Technischer Stand&lt;/h3&gt;
&lt;p&gt;Technisch ist die Seite bereits umgezogen, wenn du diesen Artikel hier liest.
Meine &lt;a rel=&quot;external&quot; href=&quot;https://de.wikipedia.org/wiki/CI/CD&quot;&gt;CI/CD Pipeline&lt;/a&gt; für die Seite funktioniert und auch sonst bin ich mit dem Aufbau zufrieden.&lt;/p&gt;
&lt;h3 id=&quot;die-artikel&quot;&gt;Die Artikel&lt;/h3&gt;
&lt;p&gt;Wie bereits angesprochen, sind meine Artikel aktuell nicht sichtbar.&lt;/p&gt;
&lt;p&gt;Das liegt erstens daran, dass ich die sogenannten &quot;Frontmatter&quot; anpassen muss, da diese nur bedingt kompatibel sind zwischen Hugo und Zola.&lt;br /&gt;
Zweitens habe ich mir bei der Umstellung alle Artikel nochmal durchgelesen und bin mit der Qualität nicht zufrieden.&lt;/p&gt;
&lt;p&gt;Das bedeutet konkret, dass die Artikel nach und nach wieder online kommen werden.
Alles in allem wird der Prozess vermutlich 1-2 Monate dauern.&lt;/p&gt;
&lt;h2 id=&quot;abschlussworte&quot;&gt;Abschlussworte&lt;/h2&gt;
&lt;p&gt;Ich hoffe du schaust auch während der Umbauphase regelmäßig vorbei, es könnte sich lohnen, denn während ich die bestehenden Artikel einer Generalüberholung unterziehe, kommen auch neue Artikel dazu.&lt;/p&gt;
</description>
      </item>
      <item>
          <title>Rusty Bytes: Traits und mehr</title>
          <pubDate>Wed, 11 Mar 2026 00:00:00 +0100</pubDate>
          <author>Tristan</author>
          <link>https://devcartes.de/blog/rusty-bytes-traits/</link>
          <guid>https://devcartes.de/blog/rusty-bytes-traits/</guid>
          <description xml:base="https://devcartes.de/blog/rusty-bytes-traits/">&lt;h2 id=&quot;was-sind-traits&quot;&gt;Was sind Traits?&lt;/h2&gt;
&lt;p&gt;Traits sind Rusts Version von Interfaces.
Ein Trait definiert eine Schnittstelle, eine Menge von Methoden, die ein Typ implementieren muss, außer es gibt eine Standardimplementierung.
Wer schon mit Interfaces aus C#, Java oder Kotlin gearbeitet hat, kennt das Konzept.&lt;/p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #CDD6F4; background-color: #1E1E2E;&quot; &gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #CBA6F7;&quot;&gt;trait&lt;/span&gt;&lt;span style=&quot;color: #F9E2AF;font-style: italic;&quot;&gt; Greet&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #CBA6F7;&quot;&gt;    fn&lt;/span&gt;&lt;span style=&quot;color: #89B4FA;font-style: italic;&quot;&gt; hello&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #94E2D5;&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span style=&quot;color: #F38BA8;&quot;&gt;self&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: #94E2D5;&quot;&gt; -&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #F9E2AF;font-style: italic;&quot;&gt; String&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #CBA6F7;&quot;&gt;struct&lt;/span&gt;&lt;span style=&quot;color: #F9E2AF;font-style: italic;&quot;&gt; German&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #CBA6F7;&quot;&gt;struct&lt;/span&gt;&lt;span style=&quot;color: #F9E2AF;font-style: italic;&quot;&gt; English&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #CBA6F7;&quot;&gt;impl&lt;/span&gt;&lt;span style=&quot;color: #F9E2AF;font-style: italic;&quot;&gt; Greet&lt;/span&gt;&lt;span style=&quot;color: #CBA6F7;&quot;&gt; for&lt;/span&gt;&lt;span style=&quot;color: #F9E2AF;font-style: italic;&quot;&gt; German&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #CBA6F7;&quot;&gt;    fn&lt;/span&gt;&lt;span style=&quot;color: #89B4FA;font-style: italic;&quot;&gt; hello&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #94E2D5;&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span style=&quot;color: #F38BA8;&quot;&gt;self&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: #94E2D5;&quot;&gt; -&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #F9E2AF;font-style: italic;&quot;&gt; String&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #F9E2AF;font-style: italic;&quot;&gt;        String&lt;/span&gt;&lt;span style=&quot;color: #94E2D5;&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #89B4FA;font-style: italic;&quot;&gt;from&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #A6E3A1;&quot;&gt;&amp;quot;Hallo!&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #CBA6F7;&quot;&gt;impl&lt;/span&gt;&lt;span style=&quot;color: #F9E2AF;font-style: italic;&quot;&gt; Greet&lt;/span&gt;&lt;span style=&quot;color: #CBA6F7;&quot;&gt; for&lt;/span&gt;&lt;span style=&quot;color: #F9E2AF;font-style: italic;&quot;&gt; English&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #CBA6F7;&quot;&gt;    fn&lt;/span&gt;&lt;span style=&quot;color: #89B4FA;font-style: italic;&quot;&gt; hello&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #94E2D5;&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span style=&quot;color: #F38BA8;&quot;&gt;self&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: #94E2D5;&quot;&gt; -&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #F9E2AF;font-style: italic;&quot;&gt; String&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #F9E2AF;font-style: italic;&quot;&gt;        String&lt;/span&gt;&lt;span style=&quot;color: #94E2D5;&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #89B4FA;font-style: italic;&quot;&gt;from&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #A6E3A1;&quot;&gt;&amp;quot;Hello!&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Traits können auch eine &lt;strong&gt;Standardimplementierung&lt;/strong&gt; mitbringen, die ein Typ überschreiben kann aber nicht muss:&lt;/p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #CDD6F4; background-color: #1E1E2E;&quot; &gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #CBA6F7;&quot;&gt;trait&lt;/span&gt;&lt;span style=&quot;color: #F9E2AF;font-style: italic;&quot;&gt; Greet&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #CBA6F7;&quot;&gt;    fn&lt;/span&gt;&lt;span style=&quot;color: #89B4FA;font-style: italic;&quot;&gt; hello&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #94E2D5;&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span style=&quot;color: #F38BA8;&quot;&gt;self&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: #94E2D5;&quot;&gt; -&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #F9E2AF;font-style: italic;&quot;&gt; String&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #F9E2AF;font-style: italic;&quot;&gt;        String&lt;/span&gt;&lt;span style=&quot;color: #94E2D5;&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #89B4FA;font-style: italic;&quot;&gt;from&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #A6E3A1;&quot;&gt;&amp;quot;Hi!&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;So weit, so bekannt.&lt;/p&gt;
&lt;p&gt;Interessant wird es, wenn man Traits als Parameter verwendet, denn da beginnt die eigentliche Frage:
Was passiert dann zur Compile-Zeit und welche Auswirkungen hat es auf die Laufzeit?&lt;/p&gt;
&lt;hr /&gt;
&lt;h2 id=&quot;monomorphisierung-polymorphismus-zur-compile-zeit&quot;&gt;Monomorphisierung – Polymorphismus zur Compile-Zeit&lt;/h2&gt;
&lt;p&gt;Wenn eine Funktion einen generischen Typ mit Trait-Bound erwartet, erzeugt der Rust-Compiler für jeden konkreten Typ, mit dem die Funktion aufgerufen wird, eine eigene spezialisierte Version.
Das nennt sich &lt;strong&gt;Monomorphisierung&lt;/strong&gt;.&lt;/p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #CDD6F4; background-color: #1E1E2E;&quot; &gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #CBA6F7;&quot;&gt;fn&lt;/span&gt;&lt;span style=&quot;color: #89B4FA;font-style: italic;&quot;&gt; greet&lt;/span&gt;&lt;span style=&quot;color: #89DCEB;&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #F9E2AF;font-style: italic;&quot;&gt;T&lt;/span&gt;&lt;span style=&quot;color: #94E2D5;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #F9E2AF;font-style: italic;&quot;&gt; Greet&lt;/span&gt;&lt;span style=&quot;color: #89DCEB;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #EBA0AC;&quot;&gt;g&lt;/span&gt;&lt;span style=&quot;color: #94E2D5;&quot;&gt;: &amp;amp;&lt;/span&gt;&lt;span style=&quot;color: #F9E2AF;font-style: italic;&quot;&gt;T&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #89B4FA;font-style: italic;&quot;&gt;    println!&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #A6E3A1;&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;{}&lt;/span&gt;&lt;span style=&quot;color: #A6E3A1;&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;,&lt;/span&gt;&lt;span&gt; g&lt;/span&gt;&lt;span style=&quot;color: #94E2D5;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #89B4FA;font-style: italic;&quot;&gt;hello&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;());&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Der Compiler sieht, dass &lt;code&gt;greet&lt;/code&gt; mit &lt;code&gt;German&lt;/code&gt; und &lt;code&gt;English&lt;/code&gt; aufgerufen wird, und erzeugt intern je eine Funktion für Englisch und eine für Deutsch:&lt;/p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #CDD6F4; background-color: #1E1E2E;&quot; &gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #CBA6F7;&quot;&gt;fn&lt;/span&gt;&lt;span style=&quot;color: #89B4FA;font-style: italic;&quot;&gt; greet_german&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #EBA0AC;&quot;&gt;g&lt;/span&gt;&lt;span style=&quot;color: #94E2D5;&quot;&gt;: &amp;amp;&lt;/span&gt;&lt;span style=&quot;color: #F9E2AF;font-style: italic;&quot;&gt;German&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;) {&lt;/span&gt;&lt;span style=&quot;color: #89B4FA;font-style: italic;&quot;&gt; println!&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #A6E3A1;&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;{}&lt;/span&gt;&lt;span style=&quot;color: #A6E3A1;&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;,&lt;/span&gt;&lt;span&gt; g&lt;/span&gt;&lt;span style=&quot;color: #94E2D5;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #89B4FA;font-style: italic;&quot;&gt;hello&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;()); }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #CBA6F7;&quot;&gt;fn&lt;/span&gt;&lt;span style=&quot;color: #89B4FA;font-style: italic;&quot;&gt; greet_english&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #EBA0AC;&quot;&gt;g&lt;/span&gt;&lt;span style=&quot;color: #94E2D5;&quot;&gt;: &amp;amp;&lt;/span&gt;&lt;span style=&quot;color: #F9E2AF;font-style: italic;&quot;&gt;English&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;) {&lt;/span&gt;&lt;span style=&quot;color: #89B4FA;font-style: italic;&quot;&gt; println!&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #A6E3A1;&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;{}&lt;/span&gt;&lt;span style=&quot;color: #A6E3A1;&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;,&lt;/span&gt;&lt;span&gt; g&lt;/span&gt;&lt;span style=&quot;color: #94E2D5;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #89B4FA;font-style: italic;&quot;&gt;hello&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;()); }&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Das ist gleichbedeutend mit dem &lt;code&gt;impl Trait&lt;/code&gt;-Syntax, der etwas lesbarer ist:&lt;/p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #CDD6F4; background-color: #1E1E2E;&quot; &gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #CBA6F7;&quot;&gt;fn&lt;/span&gt;&lt;span style=&quot;color: #89B4FA;font-style: italic;&quot;&gt; greet&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #EBA0AC;&quot;&gt;g&lt;/span&gt;&lt;span style=&quot;color: #94E2D5;&quot;&gt;: &amp;amp;&lt;/span&gt;&lt;span style=&quot;color: #CBA6F7;&quot;&gt;impl&lt;/span&gt;&lt;span style=&quot;color: #F9E2AF;font-style: italic;&quot;&gt; Greet&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #89B4FA;font-style: italic;&quot;&gt;    println!&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #A6E3A1;&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;{}&lt;/span&gt;&lt;span style=&quot;color: #A6E3A1;&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;,&lt;/span&gt;&lt;span&gt; g&lt;/span&gt;&lt;span style=&quot;color: #94E2D5;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #89B4FA;font-style: italic;&quot;&gt;hello&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;());&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;Vorteil:&lt;/strong&gt;&lt;br /&gt;
Zur Laufzeit gibt es keinen Overhead. Der Compiler kennt den konkreten Typ, kann ihn inline optimieren und direkt den richtigen Funktionsaufruf einsetzen.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Nachteil:&lt;/strong&gt;&lt;br /&gt;
Die Binärgröße wächst, denn für jeden Typ, mit dem die Funktion genutzt wird, landet eine eigene Kopie im kompilierten Code.&lt;/p&gt;
&lt;hr /&gt;
&lt;h2 id=&quot;dynamic-dispatch-polymorphismus-zur-laufzeit&quot;&gt;Dynamic Dispatch – Polymorphismus zur Laufzeit&lt;/h2&gt;
&lt;p&gt;Manchmal ist der konkrete Typ erst zur Laufzeit bekannt, so zum Beispiel wenn verschiedene Typen in einer Liste gesammelt werden sollen.&lt;/p&gt;
&lt;p&gt;Hier kommt &lt;code&gt;dyn Trait&lt;/code&gt; ins Spiel.&lt;/p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #CDD6F4; background-color: #1E1E2E;&quot; &gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #CBA6F7;&quot;&gt;fn&lt;/span&gt;&lt;span style=&quot;color: #89B4FA;font-style: italic;&quot;&gt; greet&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #EBA0AC;&quot;&gt;g&lt;/span&gt;&lt;span style=&quot;color: #94E2D5;&quot;&gt;: &amp;amp;&lt;/span&gt;&lt;span style=&quot;color: #CBA6F7;&quot;&gt;dyn&lt;/span&gt;&lt;span style=&quot;color: #F9E2AF;font-style: italic;&quot;&gt; Greet&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #89B4FA;font-style: italic;&quot;&gt;    println!&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #A6E3A1;&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;{}&lt;/span&gt;&lt;span style=&quot;color: #A6E3A1;&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;,&lt;/span&gt;&lt;span&gt; g&lt;/span&gt;&lt;span style=&quot;color: #94E2D5;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #89B4FA;font-style: italic;&quot;&gt;hello&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;());&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Statt einer spezialisierten Funktion pro Typ erzeugt der Compiler ein &lt;strong&gt;Trait Object&lt;/strong&gt;.
Das ist ein sogenannter &lt;strong&gt;Fat Pointer&lt;/strong&gt;, der aus zwei Teilen besteht, einem Zeiger auf die Daten und einem Zeiger auf eine &lt;strong&gt;vtable&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;Die vtable wiederum ist eine Tabelle mit Funktionszeigern für alle Methoden des Traits, wo zur Laufzeit die richtige Implementierung nachgeschlagen und aufgerufen wird.&lt;/p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #CDD6F4; background-color: #1E1E2E;&quot; &gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #CBA6F7;&quot;&gt;let&lt;/span&gt;&lt;span&gt; greeters&lt;/span&gt;&lt;span style=&quot;color: #94E2D5;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #F9E2AF;font-style: italic;&quot;&gt; Vec&lt;/span&gt;&lt;span style=&quot;color: #89DCEB;&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #F9E2AF;font-style: italic;&quot;&gt;Box&lt;/span&gt;&lt;span style=&quot;color: #89DCEB;&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #CBA6F7;&quot;&gt;dyn&lt;/span&gt;&lt;span style=&quot;color: #F9E2AF;font-style: italic;&quot;&gt; Greet&lt;/span&gt;&lt;span style=&quot;color: #89DCEB;&quot;&gt;&amp;gt;&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #94E2D5;&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color: #89B4FA;font-style: italic;&quot;&gt; vec!&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;[&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #F9E2AF;font-style: italic;&quot;&gt;    Box&lt;/span&gt;&lt;span style=&quot;color: #94E2D5;&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #89B4FA;font-style: italic;&quot;&gt;new&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #F9E2AF;font-style: italic;&quot;&gt;German&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #F9E2AF;font-style: italic;&quot;&gt;    Box&lt;/span&gt;&lt;span style=&quot;color: #94E2D5;&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #89B4FA;font-style: italic;&quot;&gt;new&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #F9E2AF;font-style: italic;&quot;&gt;English&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;];&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #CBA6F7;&quot;&gt;for&lt;/span&gt;&lt;span&gt; g&lt;/span&gt;&lt;span style=&quot;color: #CBA6F7;&quot;&gt; in&lt;/span&gt;&lt;span style=&quot;color: #94E2D5;&quot;&gt; &amp;amp;&lt;/span&gt;&lt;span&gt;greeters&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #89B4FA;font-style: italic;&quot;&gt;    println!&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #A6E3A1;&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;{}&lt;/span&gt;&lt;span style=&quot;color: #A6E3A1;&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;,&lt;/span&gt;&lt;span&gt; g&lt;/span&gt;&lt;span style=&quot;color: #94E2D5;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #89B4FA;font-style: italic;&quot;&gt;hello&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;());&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Das wäre mit Monomorphisierung nicht möglich, da der Compiler den Typ jedes Eintrags zur Compile-Zeit kennen müsste.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Vorteil:&lt;/strong&gt;&lt;br /&gt;
Flexibel, kleinere Binärgröße, heterogene Collections möglich.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Nachteil:&lt;/strong&gt;&lt;br /&gt;
Laufzeit-Overhead durch den vtable-Lookup, keine Inlining-Optimierungen möglich.&lt;/p&gt;
&lt;hr /&gt;
&lt;h2 id=&quot;wann-was&quot;&gt;Wann was?&lt;/h2&gt;
&lt;table&gt;&lt;thead&gt;&lt;tr&gt;&lt;th&gt;&lt;/th&gt;&lt;th&gt;&lt;code&gt;impl Trait&lt;/code&gt; / Generics&lt;/th&gt;&lt;th&gt;&lt;code&gt;dyn Trait&lt;/code&gt;&lt;/th&gt;&lt;/tr&gt;&lt;/thead&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;&lt;strong&gt;Auflösung&lt;/strong&gt;&lt;/td&gt;&lt;td&gt;Compile-Zeit&lt;/td&gt;&lt;td&gt;Laufzeit&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;strong&gt;Performance&lt;/strong&gt;&lt;/td&gt;&lt;td&gt;Höher&lt;/td&gt;&lt;td&gt;Etwas geringer&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;strong&gt;Binärgröße&lt;/strong&gt;&lt;/td&gt;&lt;td&gt;Wächst pro Typ&lt;/td&gt;&lt;td&gt;Konstant&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;strong&gt;Heterogene Collections&lt;/strong&gt;&lt;/td&gt;&lt;td&gt;✗&lt;/td&gt;&lt;td&gt;✓&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;strong&gt;Typinformation&lt;/strong&gt;&lt;/td&gt;&lt;td&gt;Vollständig bekannt&lt;/td&gt;&lt;td&gt;Zur Compile-Zeit nicht bekannt&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;p&gt;Als Faustregel gilt:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;impl Trait&lt;/code&gt; ist der Standard&lt;/li&gt;
&lt;li&gt;&lt;code&gt;dyn Trait&lt;/code&gt; kommt zum Einsatz wenn der Typ erst zur Laufzeit bekannt ist oder eine heterogene Collection benötigt wird.&lt;/li&gt;
&lt;/ul&gt;
&lt;hr /&gt;
&lt;h2 id=&quot;fazit&quot;&gt;Fazit&lt;/h2&gt;
&lt;p&gt;Traits sind mehr als nur Interfaces.
Die Entscheidung zwischen Monomorphisierung und Dynamic Dispatch ist eine Entscheidung zwischen Compile-Zeit-Garantien und Laufzeit-Flexibilität.&lt;/p&gt;
&lt;p&gt;Im Vergleich zu Java oder C#, wo jeder Methodenaufruf über eine virtuelle Tabelle aufgelöst wird, gibt Rust einem die Wahl und man muss sich explizit entscheiden, was man möchte.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Explizit&lt;/strong&gt; und &lt;strong&gt;ohne Overhead&lt;/strong&gt;, sind zwei Grundprinzipien bei Rust, die man sich mit einer etwas steileren Lernkurve und mehr Boilerplate-Code erkauft.&lt;/p&gt;
</description>
      </item>
    </channel>
</rss>
