From c67c1c459ce979a42319d2eafdfd4b15b22abbe6 Mon Sep 17 00:00:00 2001 From: Joe Ardent Date: Wed, 24 Oct 2018 18:10:05 -0700 Subject: [PATCH] Removes need for beta or nightly toolchain. Previously, it was using 'edition = "2018"' in the manifest, which enabled nifty new features like "not having to say 'extern crate'". See https://rust-lang-nursery.github.io/edition-guide/editions/index.html. --- Cargo.lock | 2 +- Cargo.toml | 3 +-- src/main.rs | 30 +++++++++++++----------------- 3 files changed, 15 insertions(+), 20 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 466ad91..248c10b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -89,7 +89,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "randical" -version = "0.1.0" +version = "0.1.1" dependencies = [ "clap 2.32.0 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.5.5 (registry+https://github.com/rust-lang/crates.io-index)", diff --git a/Cargo.toml b/Cargo.toml index fff859d..314f2fa 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,8 +1,7 @@ [package] name = "randical" -version = "0.1.0" +version = "0.1.1" authors = ["Joe Ardent "] -edition = "2018" description = "A simple UNIX commandline utility to generate sequences of random values of different types." diff --git a/src/main.rs b/src/main.rs index 008c626..6b54899 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,10 +1,13 @@ +extern crate clap; +extern crate rand; + use std::process::exit; use clap::{App, Arg, ArgMatches}; use rand::prelude::*; -const VERSION: &'static str = "1"; +const VERSION: &str = "1"; const DEFAULT_NUM_VALS: usize = 1; fn get_args() -> ArgMatches<'static> { @@ -38,23 +41,18 @@ fn get_args() -> ArgMatches<'static> { } fn print_bool(b: &mut ThreadRng) { - let t: usize; - if b.gen() { - t = 1; - } else { - t = 0; - } + let t = if b.gen() { 1 } else { 0 }; println!("{}", t); } -fn get_generator(args: &ArgMatches) -> Box ()> { +fn get_generator(args: &ArgMatches) -> Box ()> { let mut rng = thread_rng(); match args.value_of("TYPE").unwrap_or("b") { - "f" => return Box::new(move || println!("{}", rng.gen::())), - "u" => return Box::new(move || println!("{}", rng.gen::())), - "s" => return Box::new(move || println!("{}", rng.gen::())), - _ => return Box::new(move || print_bool(&mut rng)), + "f" => Box::new(move || println!("{}", rng.gen::())), + "u" => Box::new(move || println!("{}", rng.gen::())), + "s" => Box::new(move || println!("{}", rng.gen::())), + _ => Box::new(move || print_bool(&mut rng)), } } @@ -68,12 +66,10 @@ fn main() { .unwrap() .parse() .unwrap_or(DEFAULT_NUM_VALS) + } else if do_exit { + 0 } else { - if do_exit { - 0 - } else { - DEFAULT_NUM_VALS - } + DEFAULT_NUM_VALS }; let mut gen = get_generator(&args);