Hi. I finish my tetris game in rust but I want to exercise with generics and I want to abstract underlying framework(piston) with generic abstract layer which allow me to use any framework without change the game code. Of Course my approach is to use generics. Normally in c++ my code would look like that
#include <iostream>
struct RenderContext {
};
struct Game {
void handleEvent(RenderContext&) {
std::cout<<"Some rendering"<<std::endl;
}
};
template<typename S>
struct AbstractionLayer {
S& subsciber;
AbstractionLayer(S& s) : subsciber(s) {}
void emitEvent() {
RenderContext ctx;
subsciber.handleEvent(ctx);
}
};
int main() {
Game theGame;
AbstractionLayer layer(theGame);
layer.emitEvent();
return 0;
}
The point here is to not have additional memory allocation and have single indirection(call) and I should be able to achieve this because I know everything in compile time. No runtime decisions
Can I achieve something similar or better in rust