Why does the following code give:
source/app.d(45,12): Error: cannot implicitly convert expression __lambda1 of type void delegate(HTTPServerRequest req, HTTPServerResponse res) @system to void delegate(HTTPServerRequest req, HTTPServerResponse res) @safe
source/app.d(45,12): Error: cannot implicitly convert expression __lambda1 of type void delegate(HTTPServerRequest req, HTTPServerResponse res) @system to void delegate(HTTPServerRequest req, HTTPServerResponse res) @safe
source/app.d(55,26): Error: template instance app.staticI18NTemplate!"index.dt" error instantiating
import vibe.d;
struct TranslationContext
{
import std.typetuple : TypeTuple;
alias languages = TypeTuple!("en_US", "de_DE");
mixin translationModule!"example";
static string determineLanguage(HTTPServerRequest req)
{
import std.string : split, replace;
auto acc_lang = "Accept-Language" in req.headers;
if (acc_lang)
return replace(split(*acc_lang, ",")[0], "-", "_");
return null;
}
}
void renderI18NTemplate(string file)(HTTPServerRequest req,
HTTPServerResponse res)
{
switch (TranslationContext.determineLanguage(req)) {
default:
static string diet_translate__(string key, string context=null) {
return tr!(TranslationContext, TranslationContext.languages[0])
(key);
}
render!(file, req, diet_translate__)(res);
break;
foreach (lang; TranslationContext.languages) {
case lang:
mixin("struct " ~ lang ~ " {
static string diet_translate__(string key, string
context=null) {
return tr!(TranslationContext, lang)(key); }
}
alias translate = " ~ lang ~ " .diet_translate__;");
render!(file, req, translate)(res);
break;
}
}
}
HTTPServerRequestDelegate staticI18NTemplate(string file)()
{
return (HTTPServerRequest req, HTTPServerResponse res) {
renderI18NTemplate!(file)(req, res);
};
}
shared static this()
{
auto settings = new HTTPServerSettings;
settings.port = 8080;
settings.bindAddresses = ["::1", "127.0.0.1"];
listenHTTP(settings, staticI18NTemplate!"index.dt");
logInfo("Please open http://127.0.0.1:8080/ in your browser.");
}