-
Notifications
You must be signed in to change notification settings - Fork 78
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
Common midir error trait #87
base: master
Are you sure you want to change the base?
Common midir error trait #87
Conversation
Thanks for the PR! I have a few questions:
|
#[derive(Debug)] In other words, client code can tell whether the problem was on the MIDI side or on the device side, and that's all I want to know. In particular, I don't want to expose the nature of the MIDI implementation. The first draft used rtmidi, but then I decided that I like midir better, and I'd like to be able to replace the MIDI implementation without changing client code. If you accept my pull request, I'll be able to consume all midir errors with a single conversion: impl<E: MidirError + Display> From for MyFancyMidiDeviceError { Without my pull request, I have to implement the From trait for all midir error types. (Or I could introduce MidirError in my library and add implementations for all midir error types.)
|
Here's another way to accomplish what I have in mind: Replace multiple error types with a single error enum whose variants are the current error types. That would also allow me to uniformly absorb midir errors, but it would be much more intrusive and wouldn't be backwards compatible, i.e., it would require a major version number change. |
Not a whole lot. The code added could go into user crates equally well. If anything, this PR is not about opening up some entirely new use case; it's more about reducing boilerplate in dependent crates
Tons of crates have a blanket error enum that encompasses all possible errors within the library. However, this is mostly for the crate's own convenience of not having to return fine-grained error types (like midir honorably does). This PR is non-standard in that it introduces an error trait instead of an enum. Since you can't store a trait directly, users are expected users to store an opaque object like Not sure if an error trait or enum is more idiomatic here. Both would suit @nettoyeurny's use case equally well since you could call |
Hi! I'd like to handle midir errors in a uniform way, and so I added a common midir error trait.