<div dir="ltr"><div class="gmail_quote gmail_quote_container"><div dir="ltr" class="gmail_attr">On Wed, 4 Dec 2024 at 12:56, Timon Gehr via Digitalmars-d <<a href="mailto:digitalmars-d@puremagic.com">digitalmars-d@puremagic.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">On 12/3/24 12:55, Manu wrote:<br>
> Maybe someone has a pattern for doing this kind of thing...<br>
<br>
There are a couple solutions that look okay already, but basically, <br>
importing into any unordered scope works, e.g.<br>
<br>
```d<br>
module default_serialise;<br>
ubyte[] serialise(T)(T arg)if(!is(T==struct)){ return [1]; }<br>
```<br>
<br>
```d<br>
module user_code;<br>
struct S{}<br>
ubyte[] serialise(S){ return [2]; }<br>
```<br>
<br>
```d<br>
import default_serialise;<br>
<br>
void main(){<br>
import std;<br>
static struct Dummy{<br>
import default_serialise: serialise;<br>
import user_code: serialise;<br>
}<br>
import user_code;<br>
writeln(Dummy.serialise(1)); // [1]<br>
writeln(Dummy.serialise(S())); // [2]<br>
}<br>
```<br>
<br>
You can also use a dummy template scope (template Dummy(), and then <br>
`Dummy!().serialise`).<br>
<br>
I dislike function-local import semantics quite a bit as they do not <br>
follow the well-thought-out overloading rules that apply to other imports.<br></blockquote><div><br></div><div>"Unordered scope"; it never occurred to me that was a concept! But I can see that now...</div><div>What a horrible hack, but I guess that could work.</div><div>I'll see if I can do anything with this idea...<br></div></div></div>