-
Notifications
You must be signed in to change notification settings - Fork 56
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
Enhance error handling #38
Comments
Sadly, the nanomsg error code are platform dependants and I don't know how to port this kind of C code in rust:
|
We can represent them with cfg and const types. #[cfg(not(target_os = "windows"))]
use libc::{EPROTONOSUPPORT};
#[cfg(target_os = "windows")]
const EPROTONOSUPPORT: c_int = (NN_HAUSNUMERO + 2) Some of the errors are already defined in the libc bindings that Rust ships with as they are standard POSIX errors. The issue is finding out what platforms don't have them defined, I'm guessing windows is the major one that doesn't have them. Also Rust hardcodes the values for each of these constants while Nanomsg has the |
As usual, there is already some Rust goodness to support what we need. All of it in the trait FromPrimitive. I think I will update ErrorKind to take advantage of this. |
While implementing the part that gets the nanomsg error message attached to the error code, I tried to use c_str_to_static_slice to avoid the copy but failed to import the function so far. @thehydroimpulse, any idea about how to do this ? |
@blabaere mm, trying it on play.rust-lang.org seems to work for me. I'm not sure if that has just been added on a more-recent nightly, though. |
The native nanomsg lib has quite a lot of constants for the errors, and they should be reported to the nanomsg.rs users. The nn_errno and nn_strerror should be used internally to produce usable results.
The text was updated successfully, but these errors were encountered: