This repository has been archived by the owner on Sep 18, 2020. It is now read-only.
Consider using enum_dispatch
instead of dynamic dispatching
#4
Labels
There's an important and repetitive pattern in the
api
,player
andlyrics
modules. These support multiple possible implementations of a base trait, and are associated in anenum
. This requires ainit_
function to initialize the struct depending on the chosen enum variant:This makes the implementations of
ThingBase
modular, as they can be split into different files, and is the most straightforward solution I found, which is what was used in the Python implementation of Vidify, too.The second approach which will later be simplified by the
enum_dispatch
crate allows to use this solution instead, which avoids dynamic dispatching:I haven't looked at it in depth but it would be an interesting change to avoid dynamic dispatching both to simplify the code (no
Box<dyn Trait>
), and to optimize it a bit (this shouldn't really be noticeable anyway, but theenum_dispatch
claims to be ten times faster). What I'm not sure of is if the initialization of the structs would still be as easy directly from the enum. Avoidinginit_api
would reduce boilerplate as well, but it might not be exactly what I'm looking for. This might also add complexity to an important part of thecore
member, which must be relatively simple in case the GUI is implemented in a different language.The text was updated successfully, but these errors were encountered: