grue/generation/names/
doughty.rs1use rand::prelude::*;
2
3macro_rules! random_choice {
4 ($self_:ident, $a:ident) => {
5 if $self_.$a.len() > 0 {
6 let mut rng = thread_rng();
7 let choice = rng.gen_range(0, $self_.$a.len());
8 $self_.$a[choice].to_owned()
9 } else {
10 String::default()
11 }
12 };
13}
14
15#[derive(Debug, Default, Clone, Deserialize)]
16pub struct Doughty {
17 pub syllables: Vec<String>,
18 pub male_suffixes: Vec<String>,
19 pub female_suffixes: Vec<String>,
20}
21
22impl Doughty {
23 pub fn random_syllable(&self) -> String {
24 random_choice!(self, syllables)
25 }
26
27 pub fn random_male_suffix(&self) -> String {
28 random_choice!(self, male_suffixes)
29 }
30
31 pub fn random_female_suffix(&self) -> String {
32 random_choice!(self, female_suffixes)
33 }
34}