rusty-diceware

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

commit 765107c10399b2f9f541eb783e77655222de9dbd
parent f6a14f426193273874555b5718a23ca8d5804ecb
Author: Yuval Langer <yuval.langer@gmail.com>
Date:   Sun, 12 May 2019 17:35:34 +0300

Update `rand` dependency version from `^0.5` to `^0.6` and replace deprecated `rand` stuff.

Diffstat:
MCargo.toml | 2+-
Msrc/diceware.rs | 13+++++++------
Msrc/main.rs | 3++-
3 files changed, 10 insertions(+), 8 deletions(-)

diff --git a/Cargo.toml b/Cargo.toml @@ -12,5 +12,5 @@ edition = "2018" [dependencies] -rand = "^0.5" +rand = "^0.6" getopts = "^0.2" diff --git a/src/diceware.rs b/src/diceware.rs @@ -1,5 +1,6 @@ extern crate rand; +use rand::seq::SliceRandom; use std::fmt; include!(concat!(env!("OUT_DIR"), "/diceware.rs")); @@ -59,8 +60,8 @@ impl MiniLockWord { } impl rand::distributions::Distribution<BealeWord> for rand::distributions::Standard { - fn sample<R: rand::Rng + ?Sized>(&self, rng: &mut R) -> BealeWord { - *rng.choose(&BEALE_WORDLIST).unwrap() + fn sample<R: rand::Rng + ?Sized>(&self, mut rng: &mut R) -> BealeWord { + *BEALE_WORDLIST.choose(&mut rng).unwrap() } } @@ -80,8 +81,8 @@ impl fmt::Display for BealeWord { } impl rand::distributions::Distribution<ReinholdWord> for rand::distributions::Standard { - fn sample<R: rand::Rng + ?Sized>(&self, rng: &mut R) -> ReinholdWord { - *rng.choose(&REINHOLD_WORDLIST).unwrap() + fn sample<R: rand::Rng + ?Sized>(&self, mut rng: &mut R) -> ReinholdWord { + *REINHOLD_WORDLIST.choose(&mut rng).unwrap() } } @@ -101,8 +102,8 @@ impl fmt::Display for ReinholdWord { } impl rand::distributions::Distribution<MiniLockWord> for rand::distributions::Standard { - fn sample<R: rand::Rng + ?Sized>(&self, rng: &mut R) -> MiniLockWord { - *rng.choose(&MINILOCK_WORDLIST).unwrap() + fn sample<R: rand::Rng + ?Sized>(&self, mut rng: &mut R) -> MiniLockWord { + *MINILOCK_WORDLIST.choose(&mut rng).unwrap() } } diff --git a/src/main.rs b/src/main.rs @@ -9,6 +9,7 @@ extern crate rand; //use std::env; use getopts::Options; +use rand::rngs::OsRng; use rand::Rng; use std::process::exit; @@ -55,7 +56,7 @@ fn main() { .opt_str("n") .map_or(8, |n_str| n_str.parse::<u64>().ok().unwrap()); - let mut rng = rand::OsRng::new().unwrap(); + let mut rng = OsRng::new().unwrap(); if matches.opt_present("reinhold") { for _ in 0..word_num {