-
Notifications
You must be signed in to change notification settings - Fork 666
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
Introduce set_errno #2283
Introduce set_errno #2283
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about a usage example? And FTR, what function from the errno crate does this replace? Oh, and don't worry about the test failure on DragonflyBSD; it's unrelated.
If you are asking for a use case, I simply noticed that fish shell depends both on nix and errno, so I digged into it and that's how I found out that nix does not have a way to set errnos. And if you are asking me to add rustdoc usage example, sure I can do that, just let me know that I misunderstood the question.
Simply errno::set_errno |
Yeah, a rustdoc example would be great. Also, you'll have to rebase to fix the CI failure. |
95c18b4
to
47f3223
Compare
Rebased, examples added to module docs, and to set and clear functions |
I'm not sure if this should be top level function, if clear is a static method already? Currently we have: pub fn errno() -> i32;
pub fn set_errno(errno: Errno);
impl Errno {
pub fn clear(); // Does the same'ish action as set but lives in diferent scope
pub fn last() -> Errno;
} So that's not consistent. But moving set to a method does not seem entirely right either? impl Errno {
pub fn set(&self); // Like so?
pub fn set(errno: Errno) // Or perhaps like this?
} Personally I would just move clear to top level as well to make it consistent, but that's already part of public API, so I would rather not break it for no reason. |
Excellent question. I agree that the current situation is inconsistent. I'm a fan of namespaces, so my preference would be: impl Errno {
fn set(self) {...}
fn clear() {...}
fn last() { ...}
} |
It is indeed not consistent. I think the following approach is ok: impl Errno {
pub fn set(errno: Errno) {} So when people use it, For impl Errno {
/// Returns the platform-specific value of errno
pub fn last_raw() -> i32 { }
} And
@asomers thoughts on this? |
I agree with renaming |
Just for symmetry: impl Errno {
pub fn from_raw(raw: i32) -> Errno
pub fn last_raw() -> i32
} |
To deprecate an interface, we do it like this. The version of the next release will be |
Done.
|
LGTM! Thanks! But I would like to know @asomers's view on the new APIs before merging this PR. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
What does this PR do
This adds a way to set errno, it makes it possible to fully drop errno crate in crates that already use nix.
Checklist:
CONTRIBUTING.md