Skip to content

Commit

Permalink
deps: rand 0.8 -> 0.9 (#3808)
Browse files Browse the repository at this point in the history
  • Loading branch information
Madoshakalaka authored Feb 21, 2025
1 parent 960c4f2 commit 3c6fed4
Show file tree
Hide file tree
Showing 16 changed files with 80 additions and 88 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/benchmark.yml
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ jobs:
- name: Build benchmark-struct app
working-directory: yew/tools/benchmark-struct
run: |
wasm-pack build \
RUSTFLAGS='--cfg getrandom_backend="wasm_js"' wasm-pack build \
--release \
--target web \
--no-typescript \
Expand All @@ -101,7 +101,7 @@ jobs:
- name: Build benchmark-hooks app
working-directory: yew/tools/benchmark-hooks
run: |
wasm-pack build \
RUSTFLAGS='--cfg getrandom_backend="wasm_js"' wasm-pack build \
--release \
--target web \
--no-typescript \
Expand Down
64 changes: 33 additions & 31 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion ci/build-examples.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ for path in examples/*; do
# shellcheck disable=SC2164
cd "$path"
dist_dir="$output/$example"
export RUSTFLAGS="--cfg nightly_yew"
export RUSTFLAGS="--cfg nightly_yew --cfg getrandom_backend=\"wasm_js\""

trunk build --release --dist "$dist_dir" --public-url "$PUBLIC_URL_PREFIX/$example" --no-sri

Expand Down
4 changes: 2 additions & 2 deletions examples/boids/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ license = "MIT OR Apache-2.0"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
anyhow = "1.0"
getrandom = { version = "0.2", features = ["js"] }
rand = "0.8"
getrandom = { version = "0.3", features = ["wasm_js"] }
rand = "0.9"
serde = { version = "1.0", features = ["derive"] }
yew = { path = "../../packages/yew", features = ["csr"] }
gloo = "0.11"
Expand Down
10 changes: 5 additions & 5 deletions examples/boids/src/boid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,18 @@ pub struct Boid {

impl Boid {
pub fn new_random(settings: &Settings) -> Self {
let mut rng = rand::thread_rng();
let mut rng = rand::rng();

let max_radius = settings.min_distance / 2.0;
let min_radius = max_radius / 6.0;
// by using the third power large boids become rarer
let radius = min_radius + rng.gen::<f64>().powi(3) * (max_radius - min_radius);
let radius = min_radius + rng.random::<f64>().powi(3) * (max_radius - min_radius);

Self {
position: Vector2D::new(rng.gen::<f64>() * SIZE.x, rng.gen::<f64>() * SIZE.y),
velocity: Vector2D::from_polar(rng.gen::<f64>() * math::TAU, settings.max_speed),
position: Vector2D::new(rng.random::<f64>() * SIZE.x, rng.random::<f64>() * SIZE.y),
velocity: Vector2D::from_polar(rng.random::<f64>() * math::TAU, settings.max_speed),
radius,
hue: rng.gen::<f64>() * math::TAU,
hue: rng.random::<f64>() * math::TAU,
}
}

Expand Down
4 changes: 2 additions & 2 deletions examples/function_memory_game/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ strum = "0.27"
strum_macros = "0.27"
gloo = "0.11"
nanoid = "0.4"
rand = "0.8"
getrandom = { version = "0.2", features = ["js"] }
rand = "0.9"
getrandom = { version = "0.3", features = ["wasm_js"] }
yew = { path = "../../packages/yew", features = ["csr"] }

[dependencies.web-sys]
Expand Down
4 changes: 2 additions & 2 deletions examples/function_memory_game/src/helper.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
use nanoid::nanoid;
use rand::rng;
use rand::seq::SliceRandom;
use rand::thread_rng;

use crate::constant::RAW_CARDS;
use crate::state::Card;

pub fn shuffle_cards() -> Vec<Card> {
let mut raw_cards = RAW_CARDS;

raw_cards.shuffle(&mut thread_rng());
raw_cards.shuffle(&mut rng());

raw_cards
.iter()
Expand Down
2 changes: 1 addition & 1 deletion examples/function_router/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ instant = { version = "0.1", features = ["wasm-bindgen"] }
once_cell = "1"

[target.'cfg(target_arch = "wasm32")'.dependencies]
getrandom = { version = "0.2", features = ["js"] }
getrandom = { version = "0.3.1", features = ["wasm_js"] }

[[bin]]
name = "function_router"
Expand Down
4 changes: 2 additions & 2 deletions examples/game_of_life/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ edition = "2021"
license = "MIT OR Apache-2.0"

[dependencies]
getrandom = { version = "0.2", features = ["js"] }
getrandom = { version = "0.3", features = ["wasm_js"] }
log = "0.4"
rand = "0.8"
rand = "0.9"
wasm-logger = "0.2"
yew = { path = "../../packages/yew", features = ["csr"] }
gloo = "0.11"
2 changes: 1 addition & 1 deletion examples/game_of_life/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ pub struct App {
impl App {
pub fn random_mutate(&mut self) {
for cellule in self.cellules.iter_mut() {
if rand::thread_rng().gen() {
if rand::rng().random() {
cellule.set_alive();
} else {
cellule.set_dead();
Expand Down
4 changes: 2 additions & 2 deletions examples/keyed_list/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ license = "MIT OR Apache-2.0"

[dependencies]
fake = "4.0.0"
getrandom = { version = "0.2", features = ["js"] }
getrandom = { version = "0.3", features = ["wasm_js"] }
instant = { version = "0.1", features = ["wasm-bindgen"] }
log = "0.4"
rand = "0.8"
rand = "0.9"
wasm-logger = "0.2"
yew = { path = "../../packages/yew", features = ["csr"] }

Expand Down
11 changes: 7 additions & 4 deletions examples/keyed_list/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,13 @@ impl Component for App {
true
}
Msg::SwapRandom => {
let (a, b) = random::choose_two_distinct_mut(&mut self.persons).unwrap();
log::info!("Swapping {} and {}.", a.info().id, b.info().id);
std::mem::swap(a, b);
true
if let Some((a, b)) = random::choose_two_distinct_mut(&mut self.persons) {
log::info!("Swapping {} and {}.", a.info().id, b.info().id);
std::mem::swap(a, b);
true
} else {
false
}
}
Msg::ReverseList => {
self.persons.reverse();
Expand Down
Loading

0 comments on commit 3c6fed4

Please sign in to comment.