Closed helgoboss closed 3 years ago
Actually that's not so useful. This is most relevant for enums that are passed as parameters of callback functions (functions that are called by REAPER and implemented by the plug-in) because in this case the parameter value usually needs to be compared. In the other direction usually not that often. The problem is that this comparison can also be made by matching - and matching doesn't take Hash
or PartialEq
into account.
A more consistent solution would probably be a newtype along with a few known constants.
Made ModKey
and TouchedParameterType
newtypes.
Further candidates used in control surface API (which are also used for the opposite direction, that is, plug-in to REAPER):
AutomationMode
InputMonitoringMode
Plus, there are many enums returned by functions.
At the moment many of them don't even have Custom
variant. So if the REAPER devs decide to add a new mode, a non-upgraded reaper-rs-based plug-in would panic. The good side is that this is a kind of "hey, there's something new we must support". But a panic in medium API level is too opinionated, it should be left to the consumer how to handle this situation.
As an overview, I can think of the following approaches to handle an unknown variant coming from REAPER:
Custom(...)
variant
Foo
variant and a consumer employs this new variant by matching with Custom(...)
. At some point reaper-rs gets updated to support this new variant. Everything fine and working correctly until now, better than panic from a user perspective. However, as soon as the consumer upgrades to the latest version of reaper-rs, Foo
will be returned, so it won't match anymore with Custom(...)
. Worst thing: This will not be a compile-time error!Unknown
variant
Custom
but not exposing the actual value.ControllerNumber
type in helgoboss-midi
).I really like the Unknown
variant approach and will apply it to each enum that potentially suffers this problem (each enum that is returned by REAPER or a callback parameter). Sorry, it's an API change but this one seems important. Much more panic-proof everything. Can remove lots of expect()
calls in the medium-level API.
Medium-level API: Some of the defined enums are designed in a way that is open to future additions of variants in the REAPER API: By using a
Custom(...)
variant, e.g. this one:Shift
variant is translated to the number 16 when passed to REAPER API. It shouldn't make any difference equality-wise if we useCustom(16)
instead. At the moment it does. Just compare and hashto_raw()
instead ofself
!