-
Notifications
You must be signed in to change notification settings - Fork 674
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
unistd: Redesign the enum returned by fork() #332
Conversation
Review note: I'd like more than one person to comment on this, and to figure out if this should be made a convention. I can't immediately think of anywhere eles in nix that we do something similar to |
@@ -27,7 +29,7 @@ impl Fork { | |||
|
|||
pub fn is_parent(&self) -> bool { | |||
match *self { | |||
Fork::Parent(_) => true, | |||
Fork::Parent {..} => true, | |||
_ => false | |||
} | |||
} |
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.
pub fn is_parent(&self) -> bool {
!is_child(self)
}
while you're at it? :)
I could not guess the intent of the struct before looking how it was used (as |
☔ The latest upstream changes (presumably #336) made this pull request unmergeable. Please resolve the merge conflicts. |
I'll do that once I get back to the computer. |
This commit changes the name of the enum returned by `fork()` to `ForkResult`, and changes the `Parent` variant to be struct-like. The result can be matched like use nix::unistd::ForkResult::*; match fork().unwrap() { Parent { child } => { ... } Child => { ... } } using the shorthand matching syntax for struct-like enum variants. This is a breaking change.
@fiveop done! |
Looks good to me. I can't think of other similar calls off hand, but it wouldn't surprise me if one exists. I don't think we support it at present, but |
Not yet, but soon: rust-lang/libc#246 |
@homu r+ What lead you to mark our fork wrapper as inline? I do not disagree. I think it makes sence for our wrapper functions that only add error wrapping (I don't want to call it handling). Maybe this is another thing for our conventions? |
📌 Commit c2f8bb7 has been approved by |
unistd: Redesign the enum returned by fork() This changes the name of the enum returned by `fork()` to `ForkResult`, and changes the `Parent` variant to be struct-like. The result can be matched like use nix::unistd::ForkResult::*; match fork().unwrap() { Parent { child } => { ... } Child => { ... } } using the shorthand matching syntax for struct-like enum variants. This is a breaking change.
☀️ Test successful - status |
Vaguely, I think I'd been looking at something in std and saw some things that were slightly more complex than wrappers marked as
This overall is an interesting point. Opened #338 to discuss. |
This changes the name of the enum returned by
fork()
toForkResult
,and changes the
Parent
variant to be struct-like.The result can be matched like
using the shorthand matching syntax for struct-like enum variants.
This is a breaking change.