Skip to content

Commit 1677325

Browse files
committed
fix new clippy lint to put all variables directly in format strings
1 parent 37e30a2 commit 1677325

File tree

4 files changed

+13
-13
lines changed

4 files changed

+13
-13
lines changed

src/action.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,6 @@ impl Default for Action {
3636

3737
impl Action {
3838
pub(crate) fn what_do(s: &str) -> Self {
39-
Self::Clarify(format!("What do you want to {}?", s))
39+
Self::Clarify(format!("What do you want to {s}?"))
4040
}
4141
}

src/game.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ impl Game {
290290
Outcome::Active(output) => {
291291
res = format!("{}\n\n{}{}", res, output, self.combat())
292292
}
293-
Outcome::Idle(output) => res = format!("{}\n\n{}", res, output,),
293+
Outcome::Idle(output) => res = format!("{res}\n\n{output}"),
294294
}
295295
}
296296
}
@@ -332,7 +332,7 @@ impl Game {
332332

333333
if player.hp() <= 0 {
334334
self.dead = true;
335-
format!("{}\n\nYou die.", res)
335+
format!("{res}\n\nYou die.")
336336
} else {
337337
res
338338
}
@@ -534,7 +534,7 @@ impl Game {
534534
if inv.is_empty() {
535535
"Your inventory is empty.".to_owned()
536536
} else {
537-
format!("You are carrying:{}", inv)
537+
format!("You are carrying:{inv}")
538538
}
539539
}
540540

@@ -702,7 +702,7 @@ impl Game {
702702
Action::Open(noun) => Outcome::Active(self.parse_open(noun)),
703703
Action::Sleep => Outcome::Active("Time passes...".to_owned()),
704704
Action::Take(noun) => Outcome::Active(self.parse_take(noun)),
705-
Action::Unknown(verb) => Outcome::Idle(format!("I do not know the verb \"{}\".", verb)),
705+
Action::Unknown(verb) => Outcome::Idle(format!("I do not know the verb \"{verb}\".")),
706706
Action::Version => Outcome::Idle(format!("Kingslayer {}", env!("CARGO_PKG_VERSION"))),
707707
Action::Walk(direction) => Outcome::Active(self.parse_walk(direction)),
708708
Action::Wear(_) => Outcome::Active("You can't do that yet.".to_owned()),
@@ -940,7 +940,7 @@ impl Game {
940940
}
941941

942942
fn cant_see_any(noun: &str) -> String {
943-
format!("You can't see any {} here.", noun)
943+
format!("You can't see any {noun} here.")
944944
}
945945

946946
fn list_names(names: &[&str], sep: &str) -> String {
@@ -955,7 +955,7 @@ fn list_names(names: &[&str], sep: &str) -> String {
955955
"{a} {}, {sep} {a} {}",
956956
names[1..names.len() - 1]
957957
.iter()
958-
.fold(names[0].to_owned(), |acc, i| format!("{}, {a} {}", acc, i)),
958+
.fold(names[0].to_owned(), |acc, i| format!("{acc}, {a} {i}")),
959959
names[names.len() - 1]
960960
)
961961
}

src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ fn main() -> ExitCode {
66
match run() {
77
Ok(code) => code,
88
Err(err) => {
9-
eprintln!("{}", err);
9+
eprintln!("{err}");
1010
ExitCode::FAILURE
1111
}
1212
}

src/tokens.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,8 @@ impl Tokens {
104104
}
105105
match (noun.is_empty(), prep.as_str(), obj.is_empty()) {
106106
(false, _, false) => Action::Attack(noun.to_owned(), obj.to_owned()),
107-
(true, _, false) => Action::what_do(&format!("{} {} the {}", verb, prep, obj)),
108-
(false, _, true) => Action::what_do(&format!("{} the {} {}", verb, noun, prep)),
107+
(true, _, false) => Action::what_do(&format!("{verb} {prep} the {obj}")),
108+
(false, _, true) => Action::what_do(&format!("{verb} the {noun} {prep}")),
109109
(true, _, true) => Action::what_do(verb),
110110
}
111111
}
@@ -135,7 +135,7 @@ impl Tokens {
135135
match prep.as_str() {
136136
"in" => Action::Walk("enter".to_owned()),
137137
"out" => Action::Walk("exit".to_owned()),
138-
_ => Action::Clarify(format!("Where do you want to {}?", verb)),
138+
_ => Action::Clarify(format!("Where do you want to {verb}?")),
139139
}
140140
} else {
141141
Action::Walk(noun.to_owned())
@@ -177,8 +177,8 @@ impl Tokens {
177177
(true, "on", false) => Action::Wear(obj.to_owned()),
178178
(true, "on", true) => Action::what_do("put on"),
179179
(false, _, false) => Action::Put(noun.to_owned(), obj.to_owned()),
180-
(true, _, false) => Action::what_do(&format!("{} {} the {}", verb, prep, obj)),
181-
(false, _, true) => Action::what_do(&format!("{} the {} {}", verb, noun, prep)),
180+
(true, _, false) => Action::what_do(&format!("{verb} {prep} the {obj}")),
181+
(false, _, true) => Action::what_do(&format!("{verb} the {noun} {prep}")),
182182
(true, _, true) => Action::what_do(verb),
183183
}
184184
}

0 commit comments

Comments
 (0)