-
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
Errors returned by connect() aren't Sync #55
Comments
Yes, it's actually not intentional, so thanks for raising it!
I don't have a better idea right now, either ... I need to think about it little more. |
@Deewiant I'm trying to build my project for linux and running into this issue with alsa, did you find a workaround? error[E0277]: `*mut alsa_sys::_snd_seq` cannot be shared between threads safely
--> vmidi/src/midiport.rs:51:29
|
51 | /*.map_err(|e| e.kind())*/?,
| ^ `*mut alsa_sys::_snd_seq` cannot be shared between threads safely
|
= help: within `ConnectError<MidiInput>`, the trait `Sync` is not implemented for `*mut alsa_sys::_snd_seq`
= note: required because it appears within the type `alsa::seq::Seq`
= note: required because it appears within the type `std::option::Option<alsa::seq::Seq>`
= note: required because it appears within the type `midir::backend::alsa::MidiInput`
= note: required because it appears within the type `MidiInput`
= note: required because it appears within the type `ConnectError<MidiInput>`
= note: required because of the requirements on the impl of `From<ConnectError<MidiInput>>` for `anyhow::Error`
= note: required by `std::convert::From::from`
error[E0277]: `Cell<bool>` cannot be shared between threads safely
--> vmidi/src/midiport.rs:51:29
|
51 | /*.map_err(|e| e.kind())*/?,
| ^ `Cell<bool>` cannot be shared between threads safely
|
= help: within `ConnectError<MidiInput>`, the trait `Sync` is not implemented for `Cell<bool>`
= note: required because it appears within the type `alsa::seq::Seq`
= note: required because it appears within the type `std::option::Option<alsa::seq::Seq>`
= note: required because it appears within the type `midir::backend::alsa::MidiInput`
= note: required because it appears within the type `MidiInput`
= note: required because it appears within the type `ConnectError<MidiInput>`
= note: required because of the requirements on the impl of `From<ConnectError<MidiInput>>` for `anyhow::Error`
= note: required by `std::convert::From::from`
error[E0277]: `*mut alsa_sys::_snd_seq` cannot be shared between threads safely
--> vmidi/src/midiport.rs:80:54
|
80 | Ok(midi.connect(&port, "")/*.map_err(|e| e.kind())*/?)
| ^ `*mut alsa_sys::_snd_seq` cannot be shared between threads safely
|
= help: within `ConnectError<MidiOutput>`, the trait `Sync` is not implemented for `*mut alsa_sys::_snd_seq`
= note: required because it appears within the type `alsa::seq::Seq`
= note: required because it appears within the type `std::option::Option<alsa::seq::Seq>`
= note: required because it appears within the type `midir::backend::alsa::MidiOutput`
= note: required because it appears within the type `MidiOutput`
= note: required because it appears within the type `ConnectError<MidiOutput>`
= note: required because of the requirements on the impl of `From<ConnectError<MidiOutput>>` for `anyhow::Error`
= note: required by `std::convert::From::from`
error[E0277]: `Cell<bool>` cannot be shared between threads safely
--> vmidi/src/midiport.rs:80:54
|
80 | Ok(midi.connect(&port, "")/*.map_err(|e| e.kind())*/?)
| ^ `Cell<bool>` cannot be shared between threads safely
|
= help: within `ConnectError<MidiOutput>`, the trait `Sync` is not implemented for `Cell<bool>`
= note: required because it appears within the type `alsa::seq::Seq`
= note: required because it appears within the type `std::option::Option<alsa::seq::Seq>`
= note: required because it appears within the type `midir::backend::alsa::MidiOutput`
= note: required because it appears within the type `MidiOutput`
= note: required because it appears within the type `ConnectError<MidiOutput>`
= note: required because of the requirements on the impl of `From<ConnectError<MidiOutput>>` for `anyhow::Error`
= note: required by `std::convert::From::from` |
@Boscop The workaround I mentioned should work, i.e. throwing away the Ok(midi.connect(&port, "").map_err(|e| ConnectError::new(e.kind(), ()))?) |
@Deewiant But doesn't that lose information about the error? The details? |
@Boscop You only lose the |
I was trying to use https://github.com/dtolnay/anyhow with midir's errors and ran into this rather quickly: The
ConnectError<MidiInput>
andConnectError<MidiOutput>
types don't implementSync
(at least with ALSA), which makes them incompatible with e.g. anyhow's Error trait.This can be demonstrated by tweaking the tests in this silly way:
cargo test
then complains:I guess the intention with these error types is that
connect
consumes the originalMidiInput
/MidiOutput
, but logically only does so if it succeeds, so including it in the error provides a means of getting it back on failure. That makes sense, but it does lead to this kind of papercut.This can be worked around by doing something like
ConnectError::new(e.kind(), ())
, or converting the error to a string immediately, but it's a bit awkward.The best idea off the top of my head would be to offer an API for disregarding the "inner" value in these errors, which would streamline the workaround a bit. But maybe there's a cleaner solution.
This really is just a papercut in the API, so it's not a big deal. But it's a bit non-obvious and maybe even non-intentional, so I figured I'd raise it here.
The text was updated successfully, but these errors were encountered: