Open Boddlnagg opened 9 years ago
I guess that one first step for that to happen would be to exploit rust traits for the backends. Specifically common.rs
should define traits for MidiInput
, MidiOutput
, MidiInputConnection
and MidiOutputConnection
. The next step would be the backends to implement those traits. And finally factory methods in common.rs
could instantiate the user's selected backend implementations.
Does that sound right @Boddlnagg ?
I think there are two ways of doing this: (1) As you said, define traits and then use trait objects, which gives us dynamic dispatch automatically (2) Use an enum with one variant per backend, and the impl on the enum dispatches method calls to the right implementation.
I'm not sure which is better ... I think one disadvantage of (1) is that it requires boxing. I'm not sure of the performance impact, however, and aiming for an easy API might be the better goal. Maybe one should look at how other Rust libraries deal with dynamic backend selection (e.g. database abstractions, ...).
Using traits (option (1)) might also not be feasible due to object safety rules.
Another option might be https://crates.io/crates/trait-union
E.g. compile with support for both ALSA and JACK, and give the application the ability to dynamically select the backend. It is not clear how this interacts with the
jack
feature-flag.