Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow to choose backend at runtime #4

Open
Boddlnagg opened this issue Aug 11, 2015 · 4 comments
Open

Allow to choose backend at runtime #4

Boddlnagg opened this issue Aug 11, 2015 · 4 comments
Milestone

Comments

@Boddlnagg
Copy link
Owner

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.

@Boddlnagg Boddlnagg mentioned this issue Aug 11, 2015
@chris-zen
Copy link
Contributor

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 ?

@Boddlnagg
Copy link
Owner Author

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, ...).

@Boddlnagg
Copy link
Owner Author

Using traits (option (1)) might also not be feasible due to object safety rules.

@Boddlnagg Boddlnagg mentioned this issue Dec 27, 2017
@Boddlnagg Boddlnagg added this to the 1.0 milestone Feb 12, 2019
@Boddlnagg
Copy link
Owner Author

Another option might be https://crates.io/crates/trait-union

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants