Skip to content
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

Added 'unwrap_or_exit'. #11

Merged
merged 1 commit into from Dec 15, 2017
Merged

Added 'unwrap_or_exit'. #11

merged 1 commit into from Dec 15, 2017

Conversation

goyox86
Copy link
Contributor

@goyox86 goyox86 commented Dec 15, 2017

In the coreutils and userutils and pretty much all the crates that
implement CLI applications is very common to execute system calls or
other library code that returns optional types and inmediately exit the
program in case of an None or an Err is found displaying a message
to STDERR with something like "foo: file not found" where 'foo' is the
utility.

In code it looks like this:

let user = get_user_by_id(uid).unwrap_or_else(|err| {
  eprintln!("passwd: {}", err);
  exit(1);
})

And after this commit we could do:

let user = get_user_by_id(uid).unwrap_or_exit(1);

@MggMuggins came with a proposal in #10
(in which this work is based on) and after discussing we agreed to
implement unwrap_or_exit.

In the `coreutils` and `userutils` and pretty much all the crates that
implement CLI applications is very common to execute system calls or
other library code that returns optional types and inmediately exit the
program in case of an `None` or an `Err` is found displaying a message
to STDERR with something like "foo: file not found" where 'foo' is the
utility.

In code it looks like this:

```rust
let user = get_user_by_id(uid).unwrap_or_else(|err| {
  eprintln!("passwd: {}", err);
  exit(1);
})
```

And after this commit we could do:

```rust
let user = get_user_by_id(uid).unwrap_or_exit(1);
```

@MggMuggins came with a proposal in redox-os#10
(in which this work is based on) and after discussing we agreed to
implement `unwrap_or_exit`.
@jackpot51 jackpot51 merged commit f38608a into redox-os:master Dec 15, 2017
@jackpot51
Copy link
Member

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants