In a project I have this "controller" function:
void create_fso (O) (Request req)
{
:
auto npathname = (extract name from req)
:
O.create (npathname);
:
}
public import fsobjects;
which creates a file system object. The possible object types I collected in a separate module fsobject.d
:
module fsobjects;
import std.file : write;
import std.file : mkdir;
struct File {
enum title = "file";
enum void function (string) create = (fn => write (fn, ""));
}
struct Directory {
enum title = "directory";
enum void function (string) create = (fn => mkdir (fn));
}
Within the router the controller templates are instantiated as
register_action (GET | POST, "/file.create", &create_fso!(File));
register_action (GET | POST, "/directory.create", &create_fso!(Directory));
This all works fine. But: Unless fsobjects.d is compiled linking fails with the error message
... undefined reference to `_D9fsobjects12__ModuleInfoZ'
Is there any chance to rephrase fsobjects.d such that it becomes a "header only"/"compile only" file of which no object file must be presented to the linker?