feature(sender): added random name generator #79
2 changed files with 40 additions and 0 deletions
|
|
@ -39,6 +39,7 @@
|
|||
/// The `start` function takes ownership of the `WebSocketStream` and the file
|
||||
/// paths, so we pass it the `paths` vector by value.
|
||||
pub mod client;
|
||||
pub mod util;
|
||||
|
||||
use crate::sender::client as sender;
|
||||
use tokio_tungstenite::{
|
||||
|
|
|
|||
39
src/sender/util.rs
Normal file
39
src/sender/util.rs
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
use rand::{seq::SliceRandom, thread_rng};
|
||||
|
||||
fn generate_random_name() -> String {
|
||||
let mut rng = thread_rng();
|
||||
let adjective = adjectives().choose(&mut rng).unwrap();
|
||||
// let adjective = adjectives().sample(&mut rng).unwrap();
|
||||
let noun1 = nouns1().choose(&mut rng).unwrap();
|
||||
let noun2 = nouns2().choose(&mut rng).unwrap();
|
||||
|
||||
format!("{adjective}-{noun1}-{noun2}")
|
||||
}
|
||||
|
||||
fn adjectives() -> &'static [&'static str] {
|
||||
static ADJECTIVES: &[&str] = &["funny", "smart", "creative", "friendly", "great"];
|
||||
ADJECTIVES
|
||||
}
|
||||
|
||||
fn nouns1() -> &'static [&'static str] {
|
||||
static NOUNS1: &[&str] = &["dog", "cat", "flower", "tree", "house"];
|
||||
NOUNS1
|
||||
}
|
||||
|
||||
fn nouns2() -> &'static [&'static str] {
|
||||
static NOUNS2: &[&str] = &["cookie", "cake", "frosting"];
|
||||
NOUNS2
|
||||
}
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn test_generate_random_name() {
|
||||
let name = generate_random_name();
|
||||
|
||||
assert!(name.contains('-'));
|
||||
assert!(name.split('-').count() == 3);
|
||||
assert!(name.len() > 0);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue