From cb91c7f8963e7d92cc38090482eac1c1f44569a3 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 14 Apr 2026 13:06:56 +0000 Subject: [PATCH 1/2] Bump rand from 0.8.5 to 0.9.3 in /hhss/rust Bumps [rand](https://github.com/rust-random/rand) from 0.8.5 to 0.9.3. - [Release notes](https://github.com/rust-random/rand/releases) - [Changelog](https://github.com/rust-random/rand/blob/0.9.3/CHANGELOG.md) - [Commits](https://github.com/rust-random/rand/compare/0.8.5...0.9.3) --- updated-dependencies: - dependency-name: rand dependency-version: 0.9.3 dependency-type: direct:production ... Signed-off-by: dependabot[bot] --- hhss/rust/Cargo.lock | 41 ++++++++++++++++++++++++++++------------- hhss/rust/Cargo.toml | 2 +- 2 files changed, 29 insertions(+), 14 deletions(-) diff --git a/hhss/rust/Cargo.lock b/hhss/rust/Cargo.lock index 2f620dd..d934f8e 100644 --- a/hhss/rust/Cargo.lock +++ b/hhss/rust/Cargo.lock @@ -10,13 +10,14 @@ checksum = "9555578bc9e57714c812a1f84e4fc5b4d21fcb063490c624de019f7464c91268" [[package]] name = "getrandom" -version = "0.2.16" +version = "0.3.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "335ff9f135e4384c8150d6f27c6daed433577f86b4750418338c01a1a2528592" +checksum = "899def5c37c4fd7b2664648c28120ecec138e4d395b459e5ca34f9cce2dd77fd" dependencies = [ "cfg-if", "libc", - "wasi", + "r-efi", + "wasip2", ] [[package]] @@ -59,22 +60,27 @@ dependencies = [ "proc-macro2", ] +[[package]] +name = "r-efi" +version = "5.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "69cdb34c158ceb288df11e18b4bd39de994f6657d83847bdffdbd7f346754b0f" + [[package]] name = "rand" -version = "0.8.5" +version = "0.9.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" +checksum = "7ec095654a25171c2124e9e3393a930bddbffdc939556c914957a4c3e0a87166" dependencies = [ - "libc", "rand_chacha", "rand_core", ] [[package]] name = "rand_chacha" -version = "0.3.1" +version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" +checksum = "d3022b5f1df60f26e1ffddd6c66e8aa15de382ae63b3a0c1bfc0e4d3e3f325cb" dependencies = [ "ppv-lite86", "rand_core", @@ -82,9 +88,9 @@ dependencies = [ [[package]] name = "rand_core" -version = "0.6.4" +version = "0.9.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" +checksum = "76afc826de14238e6e8c374ddcc1fa19e374fd8dd986b0d2af0d02377261d83c" dependencies = [ "getrandom", ] @@ -107,10 +113,19 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5a5f39404a5da50712a4c1eecf25e90dd62b613502b7e925fd4e4d19b5c96512" [[package]] -name = "wasi" -version = "0.11.1+wasi-snapshot-preview1" +name = "wasip2" +version = "1.0.2+wasi-0.2.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9517f9239f02c069db75e65f174b3da828fe5f5b945c4dd26bd25d89c03ebcf5" +dependencies = [ + "wit-bindgen", +] + +[[package]] +name = "wit-bindgen" +version = "0.51.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ccf3ec651a847eb01de73ccad15eb7d99f80485de043efb2f370cd654f4ea44b" +checksum = "d7249219f66ced02969388cf2bb044a09756a083d0fab1e566056b04d9fbcaa5" [[package]] name = "zerocopy" diff --git a/hhss/rust/Cargo.toml b/hhss/rust/Cargo.toml index 711446e..4d5d995 100644 --- a/hhss/rust/Cargo.toml +++ b/hhss/rust/Cargo.toml @@ -8,4 +8,4 @@ name = "hhss" path = "hhss.rs" [dependencies] -rand = "0.8" \ No newline at end of file +rand = "0.9" \ No newline at end of file From a4fd841f6c379c50bbd447d782530ace3dacde79 Mon Sep 17 00:00:00 2001 From: Seunghoon Lee Date: Wed, 15 Apr 2026 13:44:31 +0900 Subject: [PATCH 2/2] [hhss/Rust] Upgrade rand. --- hhss/rust/hhss.rs | 91 +++++++++++++++++++++++++++-------------------- 1 file changed, 52 insertions(+), 39 deletions(-) diff --git a/hhss/rust/hhss.rs b/hhss/rust/hhss.rs index 88ab8ec..2c63c9b 100644 --- a/hhss/rust/hhss.rs +++ b/hhss/rust/hhss.rs @@ -1,9 +1,9 @@ +use rand::seq::IndexedRandom; +use rand::seq::SliceRandom; use std::env; use std::fs; use std::io; use std::process; -use rand::seq::SliceRandom; -use rand::thread_rng; const MIN_SENTENCE_NUM: usize = 5; const MIN_USER_NUM: usize = 1; @@ -13,12 +13,12 @@ const USER_TEMPLATE: &str = "${user}"; fn main() { let args: Vec = env::args().collect(); - + if args.len() != 2 { eprintln!("hhss: argc != 2."); process::exit(1); } - + let num_sentences = match parse_num_sentences(&args[1]) { Ok(n) => n, Err(e) => { @@ -26,15 +26,18 @@ fn main() { process::exit(1); } }; - + let sentences = match read_data_file(SENTENCE_FILE) { Ok(lines) => lines, Err(e) => { - eprintln!("hhss: failed to open {} as mode \"r\": {}", SENTENCE_FILE, e); + eprintln!( + "hhss: failed to open {} as mode \"r\": {}", + SENTENCE_FILE, e + ); process::exit(1); } }; - + let users = match read_data_file(USER_FILE) { Ok(lines) => lines, Err(e) => { @@ -42,27 +45,35 @@ fn main() { process::exit(1); } }; - + if sentences.len() < MIN_SENTENCE_NUM { - eprintln!("hhss: it is required for {} to have valid lines more than or equal to {}.", - SENTENCE_FILE, MIN_SENTENCE_NUM); + eprintln!( + "hhss: it is required for {} to have valid lines more than or equal to {}.", + SENTENCE_FILE, MIN_SENTENCE_NUM + ); process::exit(1); } - + if users.len() < MIN_USER_NUM { - eprintln!("hhss: it is required for {} to have valid lines more than or equal to {}.", - USER_FILE, MIN_USER_NUM); + eprintln!( + "hhss: it is required for {} to have valid lines more than or equal to {}.", + USER_FILE, MIN_USER_NUM + ); process::exit(1); } - + if num_sentences > sentences.len() { - eprintln!("hhss: argv[1] = {} needs to be <= {}, the number of valid lines in {}.", - num_sentences, sentences.len(), SENTENCE_FILE); + eprintln!( + "hhss: argv[1] = {} needs to be <= {}, the number of valid lines in {}.", + num_sentences, + sentences.len(), + SENTENCE_FILE + ); process::exit(1); } - + let selected_sentences = select_random_sentences(&sentences, num_sentences); - + for sentence in selected_sentences { let processed_sentence = replace_templates(&sentence, &users); println!("{}", processed_sentence); @@ -73,19 +84,22 @@ fn parse_num_sentences(arg: &str) -> Result { match arg.parse::() { Ok(n) => { if n < MIN_SENTENCE_NUM { - Err(format!("argv[1] = {} needs to be >= {}.", n, MIN_SENTENCE_NUM)) + Err(format!( + "argv[1] = {} needs to be >= {}.", + n, MIN_SENTENCE_NUM + )) } else { Ok(n) } } - Err(_) => Err("no conversion can be performed.".to_string()) + Err(_) => Err("no conversion can be performed.".to_string()), } } fn read_data_file(filename: &str) -> Result, io::Error> { let contents = fs::read_to_string(filename)?; let mut valid_lines = Vec::new(); - + for line in contents.lines() { let trimmed = line.trim(); // Skip empty lines and comments @@ -93,19 +107,19 @@ fn read_data_file(filename: &str) -> Result, io::Error> { valid_lines.push(trimmed.to_string()); } } - + Ok(valid_lines) } fn select_random_sentences(sentences: &[String], count: usize) -> Vec { let mut indices: Vec = (0..sentences.len()).collect(); - let mut rng = thread_rng(); - + // Fisher-Yates shuffle - indices.shuffle(&mut rng); - + indices.shuffle(&mut rand::rng()); + // Take first 'count' indices and get corresponding sentences - indices.into_iter() + indices + .into_iter() .take(count) .map(|i| sentences[i].clone()) .collect() @@ -114,30 +128,29 @@ fn select_random_sentences(sentences: &[String], count: usize) -> Vec { fn replace_templates(sentence: &str, users: &[String]) -> String { let mut result = String::new(); let mut last_user: Option = None; - let mut rng = thread_rng(); - + let parts: Vec<&str> = sentence.split(USER_TEMPLATE).collect(); - + for (i, part) in parts.iter().enumerate() { result.push_str(part); - + // If this is not the last part, we need to add a user name if i < parts.len() - 1 { let mut available_users = users.to_vec(); - + // If we have more than one user and we used one before, remove it to avoid repetition if users.len() > 1 { if let Some(last) = &last_user { available_users.retain(|u| u != last); } } - - let selected_user = available_users.choose(&mut rng).unwrap(); + + let selected_user = available_users.choose(&mut rand::rng()).unwrap(); result.push_str(selected_user); last_user = Some(selected_user.clone()); } } - + result } @@ -158,7 +171,7 @@ mod tests { let users = vec!["Alice".to_string(), "Bob".to_string()]; let sentence = "Hello ${user}, how are you ${user}?"; let result = replace_templates(sentence, &users); - + // Should contain both users and they should be different assert!(result.contains("Alice") || result.contains("Bob")); assert!(result.contains("Hello")); @@ -175,13 +188,13 @@ mod tests { "Fourth".to_string(), "Fifth".to_string(), ]; - + let selected = select_random_sentences(&sentences, 3); assert_eq!(selected.len(), 3); - + // All selected sentences should be from the original list for sentence in &selected { assert!(sentences.contains(sentence)); } } -} \ No newline at end of file +}