Skip to content

Commit 5357288

Browse files
author
navigaid
committed
use std::process::ExitCode::{FAILURE, SUCCESS} instead of literals
see rust-lang/rust#48711
1 parent edaf5e7 commit 5357288

File tree

3 files changed

+31
-21
lines changed

3 files changed

+31
-21
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "nothing"
3-
version = "0.1.4"
3+
version = "0.1.5"
44
edition = "2021"
55
description = "Probably Nothing"
66
license = "MIT"

examples/main.rs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,17 @@
1+
//! $ cargo run --example main; echo $?
2+
//! args = Nothing
3+
//! 1
4+
//!
5+
//! $ cargo run --example main Probably Nothing; echo $?
6+
//! args = Something(["Probably", "Nothing"])
7+
//! 0
8+
//!
19
use nothing::{Nothing, Probably, Something};
210

311
fn get_args() -> Probably<Vec<String>> {
4-
let args: Vec<String> = std::env::args().skip(1).collect();
5-
match args.len() {
6-
0 => Nothing,
7-
_ => Something(args),
12+
match std::env::args().collect::<Vec<String>>() {
13+
args @ _ if args.len() > 1 => Something(args),
14+
_ => Nothing,
815
}
916
}
1017

lib.rs

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,43 @@
1-
#![feature(termination_trait_lib)]
2-
#![feature(derive_default_enum)]
1+
#![feature(
2+
derive_default_enum,
3+
process_exitcode_placeholder,
4+
termination_trait_lib
5+
)]
36

47
//! nothing
58
//! =======
6-
//!
9+
//!
710
//! [![crates.io](https://img.shields.io/crates/v/nothing.svg)](https://crates.io/crates/nothing)
811
//! [![Documentation](https://docs.rs/nothing/badge.svg)](https://docs.rs/nothing)
912
//! [![Build Status](https://travis-ci.org/btwiuse/nothing.svg?branch=master)](https://travis-ci.org/btwiuse/nothing)
10-
//!
13+
//!
1114
//! This is my own version of [Option](https://doc.rust-lang.org/stable/std/option/enum.Option.html). Definition:
12-
//!
15+
//!
1316
//! ```
1417
//! pub enum Probably<T> {
1518
//! Nothing,
1619
//! Something(T),
1720
//! }
1821
//! ```
19-
//!
22+
//!
2023
//! # Why?
21-
//!
24+
//!
2225
//! The point is that you can use [Probably] as the return type of your main function:
23-
//!
26+
//!
2427
//! ```
2528
//! use nothing::{Probably, Nothing};
26-
//!
29+
//!
2730
//! fn main() -> Probably<()> {
2831
//! Nothing
2932
//! }
3033
//! ```
31-
//!
32-
//! Exit code is `0` if it is [Something], `1` if [Nothing].
33-
//!
34+
//!
35+
//! Exit code is `0` if it is [Something], `1` if [Nothing].
36+
//!
3437
//! See [./examples/main.rs](https://github.com/btwiuse/nothing/blob/master/examples/main.rs)
35-
//!
38+
//!
3639
//! ![Probably::Nothing](https://i.imgur.com/AuDdbOK.png)
37-
//!
40+
//!
3841
//! It's probably nothing.
3942
4043
/// [Probably] is modelled after [Option]:
@@ -52,8 +55,8 @@ pub use Probably::{Nothing, Something};
5255
impl<T> std::process::Termination for Probably<T> {
5356
fn report(self) -> i32 {
5457
match self {
55-
Nothing => 1,
56-
_ => 0,
58+
Nothing => std::process::ExitCode::FAILURE.report(),
59+
_ => std::process::ExitCode::SUCCESS.report(),
5760
}
5861
}
5962
}

0 commit comments

Comments
 (0)