<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Rusteceans of the Fediverse, can you help me with a declarative macro problem?]]></title><description><![CDATA[<p dir="auto">Rusteceans of the Fediverse, can you help me with a declarative macro problem?</p>
<p dir="auto">Assum I want to something similar to this:</p>
<pre><code class="language-rust">sql_schema!{
    SchemaName
    enum FooTable = "foo" {
         FooBarField = "foo_bar",
         FooBazField = "foo_baz",
    }
    enum OtherTable = "other {
         // …
    }
}
</code></pre>
<p dir="auto">into:</p>
<ul>
<li>An enum <code>SchemaName</code> that has the members <code>FooTable</code> and <code>OtherTable</code>.</li>
<li>Two enums <code>FooTable</code> and <code>OtherTable</code> with an automatically implemented trait that returns the given strings.</li>
<li>Another enum <code>SchemaNameField</code> that has the members <code>FooTable(FooTable)</code> and <code>OtherTable(OtherTable)</code></li>
</ul>
<p dir="auto">Is that at all possible with declarative macros? How do I structure this without it turning into a recursion nightmare?</p>
<p dir="auto">#rustlang</p>
]]></description><link>https://bbs.spacc.eu.org/new/topic/402a0d52-d901-4896-967e-0f0e4bd56097/rusteceans-of-the-fediverse-can-you-help-me-with-a-declarative-macro-problem</link><generator>RSS for Node</generator><lastBuildDate>Mon, 09 Nov 2026 13:11:57 GMT</lastBuildDate><atom:link href="https://bbs.spacc.eu.org/new/topic/402a0d52-d901-4896-967e-0f0e4bd56097.rss" rel="self" type="application/rss+xml"/><pubDate>Sat, 01 Aug 2026 14:22:49 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Rusteceans of the Fediverse, can you help me with a declarative macro problem? on Thu, 06 Aug 2026 21:32:22 GMT]]></title><description><![CDATA[<p dir="auto">This is what I ended up with:</p>
<p dir="auto"><a href="https://codeberg.org/unobtanium/criterium/src/branch/main/src/sql/schema_macro.rs" target="_blank" rel="noopener noreferrer nofollow ugc">https://codeberg.org/unobtanium/criterium/src/branch/main/src/sql/schema_macro.rs</a></p>
<p dir="auto">Huge Thank You goes to <a class="plugin-mentions-user plugin-mentions-a" href="/user/steffo%40a.junimo.party">@steffo@a.junimo.party</a> :drgn_heart:</p>
]]></description><link>https://bbs.spacc.eu.org/new/post/https://pleroma.envs.net/objects/ebb062fb-8dc7-4352-8a03-638492912134</link><guid isPermaLink="true">https://bbs.spacc.eu.org/new/post/https://pleroma.envs.net/objects/ebb062fb-8dc7-4352-8a03-638492912134</guid><dc:creator><![CDATA[slatian@pleroma.envs.net]]></dc:creator><pubDate>Thu, 06 Aug 2026 21:32:22 GMT</pubDate></item><item><title><![CDATA[Reply to Rusteceans of the Fediverse, can you help me with a declarative macro problem? on Sat, 01 Aug 2026 16:10:04 GMT]]></title><description><![CDATA[<p><span><a href="/user/slatian%40pleroma.envs.net" rel="nofollow noopener">@<span>slatian</span></a></span> wait no i remembered correctly</p><blockquote><p><a href="https://doc.rust-lang.org/reference/macros-by-example.html#r-macro.decl.repetition.fragment" rel="nofollow noopener">Each repetition in the transcriber must contain at least one metavariable to decide how many times to expand it.</a></p></blockquote>]]></description><link>https://bbs.spacc.eu.org/new/post/https://a.junimo.party/users/steffo/statuses/117021121220266713</link><guid isPermaLink="true">https://bbs.spacc.eu.org/new/post/https://a.junimo.party/users/steffo/statuses/117021121220266713</guid><dc:creator><![CDATA[steffo@a.junimo.party]]></dc:creator><pubDate>Sat, 01 Aug 2026 16:10:04 GMT</pubDate></item><item><title><![CDATA[Reply to Rusteceans of the Fediverse, can you help me with a declarative macro problem? on Sat, 01 Aug 2026 16:04:38 GMT]]></title><description><![CDATA[<p><span><a href="/user/slatian%40pleroma.envs.net" rel="nofollow noopener">@<span>slatian</span></a></span> yep</p>]]></description><link>https://bbs.spacc.eu.org/new/post/https://a.junimo.party/users/steffo/statuses/117021099840930243</link><guid isPermaLink="true">https://bbs.spacc.eu.org/new/post/https://a.junimo.party/users/steffo/statuses/117021099840930243</guid><dc:creator><![CDATA[steffo@a.junimo.party]]></dc:creator><pubDate>Sat, 01 Aug 2026 16:04:38 GMT</pubDate></item><item><title><![CDATA[Reply to Rusteceans of the Fediverse, can you help me with a declarative macro problem? on Sat, 01 Aug 2026 15:54:11 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/steffo%40a.junimo.party">@steffo@a.junimo.party</a></p>
<p dir="auto">The optional comma could just be eaten by a <code>$(…),* $(,)?</code></p>
<p dir="auto">Or am I missing something? (I don't write a lot of macros.)</p>
]]></description><link>https://bbs.spacc.eu.org/new/post/https://pleroma.envs.net/objects/1291f713-1038-43f1-b019-ee72b7b6a9e6</link><guid isPermaLink="true">https://bbs.spacc.eu.org/new/post/https://pleroma.envs.net/objects/1291f713-1038-43f1-b019-ee72b7b6a9e6</guid><dc:creator><![CDATA[slatian@pleroma.envs.net]]></dc:creator><pubDate>Sat, 01 Aug 2026 15:54:11 GMT</pubDate></item><item><title><![CDATA[Reply to Rusteceans of the Fediverse, can you help me with a declarative macro problem? on Sat, 01 Aug 2026 15:40:40 GMT]]></title><description><![CDATA[<p><span><a href="/user/slatian%40pleroma.envs.net" rel="nofollow noopener">@<span>slatian</span></a></span> a thing to be aware of, <code>$(),*</code> does not allow trailing commas, so this would work</p><pre><code>    enum Mimetype = "mimetype" {<br />        Charset = "charset"<br />    }<br /></code></pre><p>but this would give a weird error</p><pre><code>    enum Mimetype = "mimetype" {<br />        Charset = "charset",<br />    }<br /></code></pre>]]></description><link>https://bbs.spacc.eu.org/new/post/https://a.junimo.party/users/steffo/statuses/117021000322177999</link><guid isPermaLink="true">https://bbs.spacc.eu.org/new/post/https://a.junimo.party/users/steffo/statuses/117021000322177999</guid><dc:creator><![CDATA[steffo@a.junimo.party]]></dc:creator><pubDate>Sat, 01 Aug 2026 15:40:40 GMT</pubDate></item><item><title><![CDATA[Reply to Rusteceans of the Fediverse, can you help me with a declarative macro problem? on Sat, 01 Aug 2026 15:36:49 GMT]]></title><description><![CDATA[<p><span><a href="/user/slatian%40pleroma.envs.net" rel="nofollow noopener">@<span>slatian</span></a></span> sure! you can add <code>Stefano Pigozzi &lt;me@steffo.eu&gt;</code> to the <code>contributors</code> section of <code>Cargo.toml</code> if you want, but dw, it's just a snippet of code that fit in a fedi post <img class="not-responsive emoji" src="https://s3.fr-par.scw.cloud/a-junimo-party-media/custom_emojis/images/000/002/697/original/neocat_laugh.png" title=":neocat_laugh:" /></p>]]></description><link>https://bbs.spacc.eu.org/new/post/https://a.junimo.party/users/steffo/statuses/117020990450676152</link><guid isPermaLink="true">https://bbs.spacc.eu.org/new/post/https://a.junimo.party/users/steffo/statuses/117020990450676152</guid><dc:creator><![CDATA[steffo@a.junimo.party]]></dc:creator><pubDate>Sat, 01 Aug 2026 15:36:49 GMT</pubDate></item><item><title><![CDATA[Reply to Rusteceans of the Fediverse, can you help me with a declarative macro problem? on Sat, 01 Aug 2026 15:33:16 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/steffo%40a.junimo.party">@steffo@a.junimo.party</a> It took a while for me to wrap my Brain around this :drgn_sparkle: &lt;- didn't expect it to be that … simple and especially readable.</p>
<p dir="auto">Given that I can almost 1:1 copy this into <a href="https://codeberg.org/unobtanium/criterium" target="_blank" rel="noopener noreferrer nofollow ugc">criterium</a> (licensed <code>LGPL-3.0-only</code>): May I? If yes, what name do you want in the copyright header?</p>
]]></description><link>https://bbs.spacc.eu.org/new/post/https://pleroma.envs.net/objects/a677fc8c-bdc6-45e6-9e10-b5099032ba92</link><guid isPermaLink="true">https://bbs.spacc.eu.org/new/post/https://pleroma.envs.net/objects/a677fc8c-bdc6-45e6-9e10-b5099032ba92</guid><dc:creator><![CDATA[slatian@pleroma.envs.net]]></dc:creator><pubDate>Sat, 01 Aug 2026 15:33:16 GMT</pubDate></item><item><title><![CDATA[Reply to Rusteceans of the Fediverse, can you help me with a declarative macro problem? on Sat, 01 Aug 2026 15:21:34 GMT]]></title><description><![CDATA[<p><span><a href="/user/slatian%40pleroma.envs.net" rel="nofollow noopener">@<span>slatian</span></a></span> something like this?</p><pre><code>pub trait Table {<br />    fn sql_safe_table_name(&amp;self) -&gt; &amp;'static str;<br />}<br /><br />pub trait Field {<br />    fn sql_safe_field_name(&amp;self) -&gt; &amp;'static str;<br />}<br /><br />macro_rules! sql_schema {<br />    {<br />        $schema_name:ident,<br />        $(<br />            enum $table_name:ident = $table_value:literal {<br />                $( $field_name:ident = $field_value:literal ),*<br />            }<br />        )*<br />    } =&gt; {<br />        pub enum $schema_name {<br />            $( $table_name ),*<br />        }<br /><br />        impl Table for $schema_name {<br />            fn sql_safe_table_name(&amp;self) -&gt; &amp;'static str {<br />                match self {<br />                    $( $schema_name::$table_name =&gt; $table_value ),*<br />                }<br />            }<br />        }<br /><br />        $(<br />            // it's not possible to concatenate things to identifiers without the use of a proc macro<br />            // so we just re-use $table_name<br />            pub enum $table_name {<br />                $( $field_name ),*<br />            }<br /><br />            impl Field for $table_name {<br />                fn sql_safe_field_name(&amp;self) -&gt; &amp;'static str {<br />                    match self {<br />                        $( $table_name::$field_name =&gt; $field_value ),*<br />                    }<br />                }<br />            }<br />        )*<br />    }<br />}<br /><br />sql_schema! {<br />    BaseTable,<br />    enum MimeParameter = "mime_parameter" {<br />        Key = "key",<br />        MimeParameterId = "mime_parameter_id"<br />    }<br />    enum Mimetype = "mimetype" {<br />        Charset = "charset"<br />         // …<br />    }<br />}<br /></code></pre><p>you can use <code>cargo expand</code> to see what it generates</p>]]></description><link>https://bbs.spacc.eu.org/new/post/https://a.junimo.party/users/steffo/statuses/117020928896253420</link><guid isPermaLink="true">https://bbs.spacc.eu.org/new/post/https://a.junimo.party/users/steffo/statuses/117020928896253420</guid><dc:creator><![CDATA[steffo@a.junimo.party]]></dc:creator><pubDate>Sat, 01 Aug 2026 15:21:34 GMT</pubDate></item><item><title><![CDATA[Reply to Rusteceans of the Fediverse, can you help me with a declarative macro problem? on Sat, 01 Aug 2026 15:16:49 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/steffo%40a.junimo.party">@steffo@a.junimo.party</a> Sorry, I haven't touched that code in quite a while … And I also didn't expect anyone to dive in this deep :drgn_heart:</p>
<p dir="auto">The Declaration for my example would be:</p>
<pre><code class="language-rust">sql_schema!{
    BaseTable
    enum MimeParameter = "mime_parameter" {
         Key = "key",
         MimeParameterId = "mime_parameter_id",
         // …
    }
    enum Mimetype = "mimetype" {
         // …
    }
    enum Origin = "origin" {
        // …
    }
    // …
}
</code></pre>
]]></description><link>https://bbs.spacc.eu.org/new/post/https://pleroma.envs.net/objects/90d80c56-3717-4a72-977d-755843f303be</link><guid isPermaLink="true">https://bbs.spacc.eu.org/new/post/https://pleroma.envs.net/objects/90d80c56-3717-4a72-977d-755843f303be</guid><dc:creator><![CDATA[slatian@pleroma.envs.net]]></dc:creator><pubDate>Sat, 01 Aug 2026 15:16:49 GMT</pubDate></item><item><title><![CDATA[Reply to Rusteceans of the Fediverse, can you help me with a declarative macro problem? on Sat, 01 Aug 2026 15:15:44 GMT]]></title><description><![CDATA[<p><span><a href="/user/slatian%40pleroma.envs.net" rel="nofollow noopener">@<span>slatian</span></a></span> unsure, give me a few mins and i'm (re)writing the macro_rules like that</p>]]></description><link>https://bbs.spacc.eu.org/new/post/https://a.junimo.party/users/steffo/statuses/117020907541806153</link><guid isPermaLink="true">https://bbs.spacc.eu.org/new/post/https://a.junimo.party/users/steffo/statuses/117020907541806153</guid><dc:creator><![CDATA[steffo@a.junimo.party]]></dc:creator><pubDate>Sat, 01 Aug 2026 15:15:44 GMT</pubDate></item><item><title><![CDATA[Reply to Rusteceans of the Fediverse, can you help me with a declarative macro problem? on Sat, 01 Aug 2026 15:15:08 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/steffo%40a.junimo.party">@steffo@a.junimo.party</a> In that case I think it would be easier to write the whole thing as a procedural macro?</p>
]]></description><link>https://bbs.spacc.eu.org/new/post/https://pleroma.envs.net/objects/39ed7469-ce52-4ed9-9747-30cd094a3d63</link><guid isPermaLink="true">https://bbs.spacc.eu.org/new/post/https://pleroma.envs.net/objects/39ed7469-ce52-4ed9-9747-30cd094a3d63</guid><dc:creator><![CDATA[slatian@pleroma.envs.net]]></dc:creator><pubDate>Sat, 01 Aug 2026 15:15:08 GMT</pubDate></item><item><title><![CDATA[Reply to Rusteceans of the Fediverse, can you help me with a declarative macro problem? on Sat, 01 Aug 2026 15:13:14 GMT]]></title><description><![CDATA[<p><span><a href="/user/slatian%40pleroma.envs.net" rel="nofollow noopener">@<span>slatian</span></a></span> yeah, that can be done, the only impossible thing is appending <code>Field</code> to identifier names, as that would require a procedural macro (an external one would also work)</p><p>shouldn't be an issue because in one case they're enums names and in the other they're enum variants, and the two can be disambiguated</p>]]></description><link>https://bbs.spacc.eu.org/new/post/https://a.junimo.party/users/steffo/statuses/117020897752384759</link><guid isPermaLink="true">https://bbs.spacc.eu.org/new/post/https://a.junimo.party/users/steffo/statuses/117020897752384759</guid><dc:creator><![CDATA[steffo@a.junimo.party]]></dc:creator><pubDate>Sat, 01 Aug 2026 15:13:14 GMT</pubDate></item><item><title><![CDATA[Reply to Rusteceans of the Fediverse, can you help me with a declarative macro problem? on Sat, 01 Aug 2026 15:08:44 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/steffo%40a.junimo.party">@steffo@a.junimo.party</a></p>
<p dir="auto">I've noticed, that I forgot to link a file, this one is where everything gets tied together:</p>
<p dir="auto"><a href="https://codeberg.org/unobtanium/unobtanium/src/branch/main/lib-unobtanium/src/database/schemas.rs" target="_blank" rel="noopener noreferrer nofollow ugc">https://codeberg.org/unobtanium/unobtanium/src/branch/main/lib-unobtanium/src/database/schemas.rs</a></p>
]]></description><link>https://bbs.spacc.eu.org/new/post/https://pleroma.envs.net/objects/fe0ed47d-914a-4526-959c-f4421af59102</link><guid isPermaLink="true">https://bbs.spacc.eu.org/new/post/https://pleroma.envs.net/objects/fe0ed47d-914a-4526-959c-f4421af59102</guid><dc:creator><![CDATA[slatian@pleroma.envs.net]]></dc:creator><pubDate>Sat, 01 Aug 2026 15:08:44 GMT</pubDate></item><item><title><![CDATA[Reply to Rusteceans of the Fediverse, can you help me with a declarative macro problem? on Sat, 01 Aug 2026 15:07:21 GMT]]></title><description><![CDATA[<p><span><a href="/user/slatian%40pleroma.envs.net" rel="nofollow noopener">@<span>slatian</span></a></span> where is SchemaName used then? is it <code>BaseTable</code>?</p>]]></description><link>https://bbs.spacc.eu.org/new/post/https://a.junimo.party/users/steffo/statuses/117020874585381936</link><guid isPermaLink="true">https://bbs.spacc.eu.org/new/post/https://a.junimo.party/users/steffo/statuses/117020874585381936</guid><dc:creator><![CDATA[steffo@a.junimo.party]]></dc:creator><pubDate>Sat, 01 Aug 2026 15:07:21 GMT</pubDate></item><item><title><![CDATA[Reply to Rusteceans of the Fediverse, can you help me with a declarative macro problem? on Sat, 01 Aug 2026 15:03:57 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/steffo%40a.junimo.party">@steffo@a.junimo.party</a> That's the inner enums, so <code>FooBarField</code> and <code>FooBazField</code> in my example above.</p>
]]></description><link>https://bbs.spacc.eu.org/new/post/https://pleroma.envs.net/objects/dc21183f-10d2-4f05-8b76-13768843209e</link><guid isPermaLink="true">https://bbs.spacc.eu.org/new/post/https://pleroma.envs.net/objects/dc21183f-10d2-4f05-8b76-13768843209e</guid><dc:creator><![CDATA[slatian@pleroma.envs.net]]></dc:creator><pubDate>Sat, 01 Aug 2026 15:03:57 GMT</pubDate></item><item><title><![CDATA[Reply to Rusteceans of the Fediverse, can you help me with a declarative macro problem? on Sat, 01 Aug 2026 14:55:17 GMT]]></title><description><![CDATA[<p><span><a href="/user/slatian%40pleroma.envs.net" rel="nofollow noopener">@<span>slatian</span></a></span> how can i get the identifiers for the enum variants of the fields?</p><p>like </p><pre><code>Key,<br />MimeParameterId,<br />MimetypeId,<br />Value,<br /></code></pre>]]></description><link>https://bbs.spacc.eu.org/new/post/https://a.junimo.party/users/steffo/statuses/117020827175527352</link><guid isPermaLink="true">https://bbs.spacc.eu.org/new/post/https://a.junimo.party/users/steffo/statuses/117020827175527352</guid><dc:creator><![CDATA[steffo@a.junimo.party]]></dc:creator><pubDate>Sat, 01 Aug 2026 14:55:17 GMT</pubDate></item><item><title><![CDATA[Reply to Rusteceans of the Fediverse, can you help me with a declarative macro problem? on Sat, 01 Aug 2026 14:41:55 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/steffo%40a.junimo.party">@steffo@a.junimo.party</a> That's supposed to become a mapping for fields in an sql database to rust enums and the strings are the actual table and column names in the database.</p>
<p dir="auto">And now that you'Re asking I actually have an example implementation (generated by a lua script):</p>
<ul>
<li><a href="https://codeberg.org/unobtanium/unobtanium/src/branch/main/lib-unobtanium/src/database/tables.rs" target="_blank" rel="noopener noreferrer nofollow ugc">https://codeberg.org/unobtanium/unobtanium/src/branch/main/lib-unobtanium/src/database/tables.rs</a></li>
<li><a href="https://codeberg.org/unobtanium/unobtanium/src/branch/main/lib-unobtanium/src/database/fields.rs" target="_blank" rel="noopener noreferrer nofollow ugc">https://codeberg.org/unobtanium/unobtanium/src/branch/main/lib-unobtanium/src/database/fields.rs</a></li>
</ul>
]]></description><link>https://bbs.spacc.eu.org/new/post/https://pleroma.envs.net/objects/c5c005d7-c7f8-4799-b24e-b96fcfbb977f</link><guid isPermaLink="true">https://bbs.spacc.eu.org/new/post/https://pleroma.envs.net/objects/c5c005d7-c7f8-4799-b24e-b96fcfbb977f</guid><dc:creator><![CDATA[slatian@pleroma.envs.net]]></dc:creator><pubDate>Sat, 01 Aug 2026 14:41:55 GMT</pubDate></item><item><title><![CDATA[Reply to Rusteceans of the Fediverse, can you help me with a declarative macro problem? on Sat, 01 Aug 2026 14:38:58 GMT]]></title><description><![CDATA[<p><span><a href="/user/slatian%40pleroma.envs.net" rel="nofollow noopener">@<span>slatian</span></a></span> what are the field strings for?</p>]]></description><link>https://bbs.spacc.eu.org/new/post/https://a.junimo.party/users/steffo/statuses/117020759641074968</link><guid isPermaLink="true">https://bbs.spacc.eu.org/new/post/https://a.junimo.party/users/steffo/statuses/117020759641074968</guid><dc:creator><![CDATA[steffo@a.junimo.party]]></dc:creator><pubDate>Sat, 01 Aug 2026 14:38:58 GMT</pubDate></item><item><title><![CDATA[Reply to Rusteceans of the Fediverse, can you help me with a declarative macro problem? on Sat, 01 Aug 2026 14:24:26 GMT]]></title><description><![CDATA[<p><span><a href="/user/slatian%40pleroma.envs.net" rel="nofollow noopener">@<span>slatian</span></a></span> i think it should be? let me try real quick</p>]]></description><link>https://bbs.spacc.eu.org/new/post/https://a.junimo.party/users/steffo/statuses/117020705827679735</link><guid isPermaLink="true">https://bbs.spacc.eu.org/new/post/https://a.junimo.party/users/steffo/statuses/117020705827679735</guid><dc:creator><![CDATA[steffo@a.junimo.party]]></dc:creator><pubDate>Sat, 01 Aug 2026 14:24:26 GMT</pubDate></item></channel></rss>