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:
parent
549d0e97cc
commit
c67c1c459c
3 changed files with 15 additions and 20 deletions
2
Cargo.lock
generated
2
Cargo.lock
generated
|
@ -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)",
|
||||
|
|
|
@ -1,8 +1,7 @@
|
|||
[package]
|
||||
name = "randical"
|
||||
version = "0.1.0"
|
||||
version = "0.1.1"
|
||||
authors = ["Joe Ardent <code@ardent.nebcorp.com>"]
|
||||
edition = "2018"
|
||||
|
||||
description = "A simple UNIX commandline utility to generate sequences of random values of different types."
|
||||
|
||||
|
|
30
src/main.rs
30
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<FnMut() -> ()> {
|
||||
fn get_generator(args: &ArgMatches) -> Box<dyn FnMut() -> ()> {
|
||||
let mut rng = thread_rng();
|
||||
|
||||
match args.value_of("TYPE").unwrap_or("b") {
|
||||
"f" => return Box::new(move || println!("{}", rng.gen::<f64>())),
|
||||
"u" => return Box::new(move || println!("{}", rng.gen::<u64>())),
|
||||
"s" => return Box::new(move || println!("{}", rng.gen::<i64>())),
|
||||
_ => return Box::new(move || print_bool(&mut rng)),
|
||||
"f" => Box::new(move || println!("{}", rng.gen::<f64>())),
|
||||
"u" => Box::new(move || println!("{}", rng.gen::<u64>())),
|
||||
"s" => Box::new(move || println!("{}", rng.gen::<i64>())),
|
||||
_ => 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);
|
||||
|
|
Loading…
Reference in a new issue