Is there a way to generate an interface from a class in D using mixin or template?

I use vibe.d to create some REST interfaces from classes. However, vibe.d requires me to provide an interface and a class that implements this interface. My application is small and contains only one implementation of this interface, and it is very annoying for me to edit both places when I want to make some changes.

So the question is: is there any mixin or template that can generate interfacefrom a given definition class? It should be quite possible to implement, but I could not find any examples. std.typeconsIt has WhiteHoleand BlackHoleto automatically implement interfaces, but I want something opposite to them.

Thanks.

+4
source share
1 answer

You can write such a mixin, but this will create a cyclical dependency problem - the ability to generate an interface, but not inherit the class from it. One possible solution is to use the new std.typecons.wrap to do this in 3 steps:

  • determine the actual class
  • create an interface from it
  • create a wrapper class that maps the actual to the interface through std.typecons.wrap

mixin , D. , . cloning funcion , vibe.d: cloneFunction

StackOverflow, .

, , , , . , , TODO. .

+3

All Articles