Skip to content

Commit b1cae32

Browse files
committed
Update to rand 0.6.5 and migrate off deprecated methods. Closes #81
* Import from rand_xorshift crate * Use shuffle/choose from SliceRandom trait See https://rust-random.github.io/book/update-0.6.html
1 parent de25096 commit b1cae32

File tree

5 files changed

+33
-17
lines changed

5 files changed

+33
-17
lines changed

Cargo.lock

Lines changed: 23 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ serde_json = "1.0.39"
2828
flate2 = { version = "1.0.7", features = ["rust_backend"], default-features = false }
2929
zip = { version = "0.5.2", features = ["deflate"], default-features = false }
3030
image = "0.21.1"
31-
rand = "0.5.5"
31+
rand = "0.6.5"
32+
rand_xorshift = "0.1.1"
3233
hex = "0.3.2"
3334
base64 = "0.10.1"
3435
log = { version = "0.4.6", features = ["std"] }

src/chunk_builder.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ struct BuildReply {
110110

111111
fn build_func(id: usize, models: Arc<RwLock<model::Factory>>, work_recv: mpsc::Receiver<BuildReq>, built_send: mpsc::Sender<(usize, BuildReply)>) {
112112
use rand::{self, SeedableRng, Rng};
113+
use rand_xorshift;
113114
loop {
114115
let BuildReq {
115116
snapshot,
@@ -121,7 +122,7 @@ fn build_func(id: usize, models: Arc<RwLock<model::Factory>>, work_recv: mpsc::R
121122
Err(_) => return,
122123
};
123124

124-
let mut rng = rand::XorShiftRng::from_seed([
125+
let mut rng = rand_xorshift::XorShiftRng::from_seed([
125126
((position.0 as u32) & 0xff) as u8,
126127
(((position.0 as u32) >> 8) & 0xff) as u8,
127128
(((position.0 as u32) >> 16) & 0xff) as u8,

src/model/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ use crate::types::hash::FNVHash;
1818
use log::{error};
1919

2020
use rand::Rng;
21+
use rand::seq::SliceRandom;
2122
use image::GenericImageView;
2223

2324
pub struct Factory {
@@ -756,7 +757,7 @@ pub struct Variants {
756757
impl Variants {
757758
fn choose_model<R: Rng>(&self, rng: &mut R) -> &Model {
758759
// TODO: Weighted random
759-
rng.choose(&self.models).unwrap()
760+
self.models.choose(rng).unwrap()
760761
}
761762
}
762763

src/ui/logo.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ use crate::ui;
55
use crate::render;
66
use crate::resources;
77
use std::time::{SystemTime, UNIX_EPOCH};
8-
use rand;
9-
use rand::Rng;
8+
use rand::{self, seq::SliceRandom};
9+
use rand_xorshift;
1010

1111
pub struct Logo {
1212
_shadow: ui::BatchRef,
@@ -101,8 +101,8 @@ impl Logo {
101101
text_strings.push(line.to_owned().replace("\r", ""));
102102
}
103103
}
104-
let mut r: rand::XorShiftRng = rand::SeedableRng::from_seed([45, 0, 0, 0, 64, 0, 0, 0, 32, 0, 0, 0, 12, 0, 0, 0]);
105-
r.shuffle(&mut text_strings[..]);
104+
let mut r: rand_xorshift::XorShiftRng = rand::SeedableRng::from_seed([45, 0, 0, 0, 64, 0, 0, 0, 32, 0, 0, 0, 12, 0, 0, 0]);
105+
text_strings.shuffle(&mut r);
106106
}
107107

108108
let txt = ui::TextBuilder::new()

0 commit comments

Comments
 (0)