Don't require Plugin to impl Default
Boscop opened this issue · 2 comments
The fact that a plugin has to be Default
makes it very unergonomic, especially if the plugin state contains many types that aren't Default
, which are initialized in new()
(such as Sender
/Receiver
), requiring wrapping them in Option
etc.
Plugin::new
only requires Default
because PluginInstance
impls Plugin
but doesn't impl the Plugin::new
method (PluginInstance
is not Default
)!
PluginInstance
has an inherent new
method with a different signature: fn new(effect: *mut AEffect, lib: Arc<Library>) -> PluginInstance
.
The options we have is to either impl Plugin::new
for PluginInstance
(it is never called anyway, (because Plugin::new
is only called on the client side, but PluginInstance
is only used on the host side), so we could just use unreachable!()
) or moving the new
method from Plugin
into a new trait PluginWithNew: Plugin { fn new(host: HostCallback) -> Self; }
.
I've wanted to do this for so long. It is very unergonomic indeed.
It's a breaking change, since it now requires plugins to implement new
, but most non-trivial plugins probably do that anyway, and it's very easy to adapt a plugin that doesn't.
We could consider, as a next step, removing the Default
implementation for HostCallback
, which was really only there to make it slightly less unergonomic to implement Default
for a Plugin
. This would save the check for the callback being initialized on every call and statically guard against that panic situation.
Review for PR coming up...