Skip to content

Commit

Permalink
use std::process::ExitCode::{FAILURE, SUCCESS} instead of literals
Browse files Browse the repository at this point in the history
  • Loading branch information
navigaid committed Apr 4, 2022
1 parent edaf5e7 commit 5357288
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 21 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "nothing"
version = "0.1.4"
version = "0.1.5"
edition = "2021"
description = "Probably Nothing"
license = "MIT"
Expand Down
15 changes: 11 additions & 4 deletions examples/main.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
//! $ cargo run --example main; echo $?
//! args = Nothing
//! 1
//!
//! $ cargo run --example main Probably Nothing; echo $?
//! args = Something(["Probably", "Nothing"])
//! 0
//!
use nothing::{Nothing, Probably, Something};

fn get_args() -> Probably<Vec<String>> {
let args: Vec<String> = std::env::args().skip(1).collect();
match args.len() {
0 => Nothing,
_ => Something(args),
match std::env::args().collect::<Vec<String>>() {
args @ _ if args.len() > 1 => Something(args),
_ => Nothing,
}
}

Expand Down
35 changes: 19 additions & 16 deletions lib.rs
Original file line number Diff line number Diff line change
@@ -1,40 +1,43 @@
#![feature(termination_trait_lib)]
#![feature(derive_default_enum)]
#![feature(
derive_default_enum,
process_exitcode_placeholder,
termination_trait_lib
)]

//! nothing
//! =======
//!
//!
//! [![crates.io](https://img.shields.io/crates/v/nothing.svg)](https://crates.io/crates/nothing)
//! [![Documentation](https://docs.rs/nothing/badge.svg)](https://docs.rs/nothing)
//! [![Build Status](https://travis-ci.org/btwiuse/nothing.svg?branch=master)](https://travis-ci.org/btwiuse/nothing)
//!
//!
//! This is my own version of [Option](https://doc.rust-lang.org/stable/std/option/enum.Option.html). Definition:
//!
//!
//! ```
//! pub enum Probably<T> {
//! Nothing,
//! Something(T),
//! }
//! ```
//!
//!
//! # Why?
//!
//!
//! The point is that you can use [Probably] as the return type of your main function:
//!
//!
//! ```
//! use nothing::{Probably, Nothing};
//!
//!
//! fn main() -> Probably<()> {
//! Nothing
//! }
//! ```
//!
//! Exit code is `0` if it is [Something], `1` if [Nothing].
//!
//!
//! Exit code is `0` if it is [Something], `1` if [Nothing].
//!
//! See [./examples/main.rs](https://github.com/btwiuse/nothing/blob/master/examples/main.rs)
//!
//!
//! ![Probably::Nothing](https://i.imgur.com/AuDdbOK.png)
//!
//!
//! It's probably nothing.
/// [Probably] is modelled after [Option]:
Expand All @@ -52,8 +55,8 @@ pub use Probably::{Nothing, Something};
impl<T> std::process::Termination for Probably<T> {
fn report(self) -> i32 {
match self {
Nothing => 1,
_ => 0,
Nothing => std::process::ExitCode::FAILURE.report(),
_ => std::process::ExitCode::SUCCESS.report(),
}
}
}
Expand Down

0 comments on commit 5357288

Please sign in to comment.