Skip to content
Auto interface implementation generator for D.
D
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
example
source
.gitignore
LICENSE.txt
README.rst
dub.json

README.rst

autointf

An helper-library to auto-generate interface implementation from a template function.

Installation:

Using dub:

"dependencies": {
    "autointf": "*"
}

Quickstart

See example app:

import std.stdio;
import autointf;


class AutoJsonRpc(I) : I
{
    private int id;

    private ReturnType!Func executeMethod(alias Func, ARGS...)(ARGS args)
    {
        import std.traits;
        import std.array : join;
        import std.conv : to;

        // retrieve some compile time informations
        alias RT    = ReturnType!Func;
        alias PTT   = ParameterTypeTuple!Func;
        enum  Name  = __traits(identifier, Func);

        string[] params;
        foreach (i, PT; PTT)
            params ~= to!string(args[i]);

        return `{"jsonrpc": "2.0", "method": "` ~ Name ~ `", "params": [`
            ~ params.join(",") ~ `], "id": ` ~ (id++).to!string() ~ "}";
    }

    mixin(autoImplementMethods!(I, executeMethod)());
}


interface IAPI
{
    string helloWorld(int number, string str);

    @noAutoImplement()
    final string foo() { return "foo"; }
}

void main()
{
    auto api = new AutoJsonRpc!IAPI();

    writeln(api.helloWorld(42, "foo"));
    // > {"jsonrpc": "2.0", "method": "helloWorld", "params": [42,foo], "id": 0}

    writeln(api.foo());
    // > foo
}
You can’t perform that action at this time.