Skip to content

Commit 98c065f

Browse files
committed
formatting
1 parent 18ce4e6 commit 98c065f

File tree

4 files changed

+7216
-7220
lines changed

4 files changed

+7216
-7220
lines changed

rustfmt.toml

-1
This file was deleted.

src/args.rs

+44-47
Original file line numberDiff line numberDiff line change
@@ -3,64 +3,61 @@ use clap::{Parser, ValueEnum};
33
#[derive(Parser)]
44
#[command(author, about, next_line_help = true)]
55
pub struct Args {
6-
/// The string that joines the random words, if there are more than 1
7-
#[arg(short, long, default_value_t = String::from(" "))]
8-
joiner: String,
6+
/// The string that joines the random words, if there are more than 1
7+
#[arg(short, long, default_value_t = String::from(" "))]
8+
joiner: String,
99

10-
/// Sets the case of every word
11-
#[arg(short, long, value_enum, default_value_t = Case::Lower)]
12-
case: Case,
10+
/// Sets the case of every word
11+
#[arg(short, long, value_enum, default_value_t = Case::Lower)]
12+
case: Case,
1313

14-
/// Disable interpreting \n as a newline and \t as a tab
15-
#[arg(short, long)]
16-
raw: bool,
14+
/// Disable interpreting \n as a newline and \t as a tab
15+
#[arg(short, long)]
16+
raw: bool,
1717

18-
/// Amount of random words to print
19-
#[arg(default_value_t = 1)]
20-
pub amount: usize,
18+
/// Amount of random words to print
19+
#[arg(default_value_t = 1)]
20+
pub amount: usize,
2121
}
2222

2323
impl Args {
24-
pub fn get_joiner(&self) -> String {
25-
if self.raw {
26-
self.joiner.clone()
27-
} else {
28-
self.joiner
29-
.clone()
30-
.replace("\\n", "\n")
31-
.replace("\\t", "\t")
32-
}
33-
}
34-
35-
pub fn alter_case(&self, mut words: Vec<String>) -> Vec<String> {
36-
self.case.alter_case(&mut words);
37-
words.to_vec()
38-
}
24+
pub fn get_joiner(&self) -> String {
25+
if self.raw {
26+
self.joiner.clone()
27+
} else {
28+
self.joiner.clone().replace("\\n", "\n").replace("\\t", "\t")
29+
}
30+
}
31+
32+
pub fn alter_case(&self, mut words: Vec<String>) -> Vec<String> {
33+
self.case.alter_case(&mut words);
34+
words.to_vec()
35+
}
3936
}
4037

4138
#[derive(ValueEnum, Clone, Copy)]
4239
pub enum Case {
43-
Caps,
44-
Title,
45-
Lower,
40+
Caps,
41+
Title,
42+
Lower,
4643
}
4744

4845
impl Case {
49-
fn alter_case(self, words: &mut [String]) {
50-
match self {
51-
Self::Caps => {
52-
for x in words.iter_mut() {
53-
x.make_ascii_uppercase();
54-
}
55-
}
56-
57-
Self::Title => {
58-
for x in words.iter_mut() {
59-
x[0..1].make_ascii_uppercase();
60-
}
61-
}
62-
63-
Self::Lower => {}
64-
}
65-
}
46+
fn alter_case(self, words: &mut [String]) {
47+
match self {
48+
Self::Caps => {
49+
for x in words.iter_mut() {
50+
x.make_ascii_uppercase();
51+
}
52+
}
53+
54+
Self::Title => {
55+
for x in words.iter_mut() {
56+
x[0..1].make_ascii_uppercase();
57+
}
58+
}
59+
60+
Self::Lower => {}
61+
}
62+
}
6663
}

src/main.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@ mod args;
66
mod words;
77

88
fn main() {
9-
let args = args::Args::parse();
10-
let picked_words = args.alter_case(get_random_words(args.amount));
9+
let args = args::Args::parse();
10+
let picked_words = args.alter_case(get_random_words(args.amount));
1111

12-
println!("{}", picked_words.join(&args.get_joiner()));
12+
println!("{}", picked_words.join(&args.get_joiner()));
1313
}
1414

1515
fn get_random_words(amount: usize) -> Vec<String> {
16-
WORDS
17-
.choose_multiple(&mut rand::thread_rng(), amount)
18-
.map(|word| (*word).to_string())
19-
.collect()
16+
WORDS
17+
.choose_multiple(&mut rand::thread_rng(), amount)
18+
.map(|word| (*word).to_string())
19+
.collect()
2020
}

0 commit comments

Comments
 (0)