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.
This commit is contained in:
Joe Ardent 2018-10-24 18:10:05 -07:00
parent 549d0e97cc
commit c67c1c459c
3 changed files with 15 additions and 20 deletions

2
Cargo.lock generated
View file

@ -89,7 +89,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]] [[package]]
name = "randical" name = "randical"
version = "0.1.0" version = "0.1.1"
dependencies = [ dependencies = [
"clap 2.32.0 (registry+https://github.com/rust-lang/crates.io-index)", "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)", "rand 0.5.5 (registry+https://github.com/rust-lang/crates.io-index)",

View file

@ -1,8 +1,7 @@
[package] [package]
name = "randical" name = "randical"
version = "0.1.0" version = "0.1.1"
authors = ["Joe Ardent <code@ardent.nebcorp.com>"] authors = ["Joe Ardent <code@ardent.nebcorp.com>"]
edition = "2018"
description = "A simple UNIX commandline utility to generate sequences of random values of different types." description = "A simple UNIX commandline utility to generate sequences of random values of different types."

View file

@ -1,10 +1,13 @@
extern crate clap;
extern crate rand;
use std::process::exit; use std::process::exit;
use clap::{App, Arg, ArgMatches}; use clap::{App, Arg, ArgMatches};
use rand::prelude::*; use rand::prelude::*;
const VERSION: &'static str = "1"; const VERSION: &str = "1";
const DEFAULT_NUM_VALS: usize = 1; const DEFAULT_NUM_VALS: usize = 1;
fn get_args() -> ArgMatches<'static> { fn get_args() -> ArgMatches<'static> {
@ -38,23 +41,18 @@ fn get_args() -> ArgMatches<'static> {
} }
fn print_bool(b: &mut ThreadRng) { fn print_bool(b: &mut ThreadRng) {
let t: usize; let t = if b.gen() { 1 } else { 0 };
if b.gen() {
t = 1;
} else {
t = 0;
}
println!("{}", t); println!("{}", t);
} }
fn get_generator(args: &ArgMatches) -> Box<FnMut() -> ()> { fn get_generator(args: &ArgMatches) -> Box<dyn FnMut() -> ()> {
let mut rng = thread_rng(); let mut rng = thread_rng();
match args.value_of("TYPE").unwrap_or("b") { match args.value_of("TYPE").unwrap_or("b") {
"f" => return Box::new(move || println!("{}", rng.gen::<f64>())), "f" => Box::new(move || println!("{}", rng.gen::<f64>())),
"u" => return Box::new(move || println!("{}", rng.gen::<u64>())), "u" => Box::new(move || println!("{}", rng.gen::<u64>())),
"s" => return Box::new(move || println!("{}", rng.gen::<i64>())), "s" => Box::new(move || println!("{}", rng.gen::<i64>())),
_ => return Box::new(move || print_bool(&mut rng)), _ => Box::new(move || print_bool(&mut rng)),
} }
} }
@ -68,12 +66,10 @@ fn main() {
.unwrap() .unwrap()
.parse() .parse()
.unwrap_or(DEFAULT_NUM_VALS) .unwrap_or(DEFAULT_NUM_VALS)
} else { } else if do_exit {
if do_exit {
0 0
} else { } else {
DEFAULT_NUM_VALS DEFAULT_NUM_VALS
}
}; };
let mut gen = get_generator(&args); let mut gen = get_generator(&args);