Skip to content

Commit 92f9a62

Browse files
FlrnFrmmfadeevab
authored andcommitted
Apply clippy suggestions
1 parent 9b429de commit 92f9a62

File tree

13 files changed

+24
-24
lines changed

13 files changed

+24
-24
lines changed

behavioral/command/command/copy.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ impl Command for CopyCommand {
1414
context.clipboard = editor.get_content().to_string();
1515

1616
app.set_user_data(context);
17-
return false;
17+
false
1818
}
1919

2020
fn undo(&mut self, _: &mut Cursive) {}

behavioral/command/command/cut.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ impl Command for CutCommand {
1818
editor.set_content("".to_string());
1919
});
2020

21-
return true;
21+
true
2222
}
2323

2424
fn undo(&mut self, app: &mut Cursive) {

behavioral/command/command/paste.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ impl Command for PasteCommand {
1717
editor.set_content(context.clipboard.clone());
1818
});
1919

20-
return true;
20+
true
2121
}
2222

2323
fn undo(&mut self, app: &mut Cursive) {

behavioral/command/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ fn main() {
2626
.button("Copy", |s| execute(s, CopyCommand::default()))
2727
.button("Cut", |s| execute(s, CutCommand::default()))
2828
.button("Paste", |s| execute(s, PasteCommand::default()))
29-
.button("Undo", |s| undo(s))
29+
.button("Undo", undo)
3030
.button("Quit", |s| s.quit()),
3131
);
3232

behavioral/mediator/train_station.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ impl Mediator for TrainStation {
1919
fn notify_about_arrival(&mut self, train_name: &str) -> bool {
2020
if self.train_on_platform.is_some() {
2121
self.train_queue.push_back(train_name.into());
22-
return false;
22+
false
2323
} else {
2424
self.train_on_platform.replace(train_name.into());
25-
return true;
25+
true
2626
}
2727
}
2828

@@ -53,7 +53,7 @@ impl TrainStation {
5353
}
5454

5555
pub fn depart(&mut self, name: &'static str) {
56-
let train = self.trains.remove(name.into());
56+
let train = self.trains.remove(name);
5757
if let Some(mut train) = train {
5858
train.depart(self);
5959
} else {

creational/abstract-factory/main_dyn.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ mod gui;
66

77
/// The client code calls the creation methods of a factory object instead of
88
/// creating products directly with a constructor call.
9-
fn render(factory: &Box<dyn gui::GuiFactoryDynamic>) {
9+
fn render(factory: &dyn gui::GuiFactoryDynamic) {
1010
let button1 = factory.create_button();
1111
let button2 = factory.create_button();
1212
let checkbox1 = factory.create_checkbox();
@@ -24,16 +24,16 @@ fn main() {
2424
let windows = false;
2525

2626
// Allocate a factory object in runtime depending on unpredictable input.
27-
let factory: Box<dyn gui::GuiFactoryDynamic> = if windows {
28-
Box::new(WindowsFactory)
27+
let factory: &dyn gui::GuiFactoryDynamic = if windows {
28+
&WindowsFactory
2929
} else {
30-
Box::new(MacFactory)
30+
&MacFactory
3131
};
3232

3333
// Factory invocation can be inlined right here then.
3434
let button = factory.create_button();
3535
button.press();
3636

3737
// Factory object can be passed to a function as a parameter.
38-
render(&factory);
38+
render(factory);
3939
}

creational/builder/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,5 @@ fn main() {
3030

3131
// The final car manual.
3232
let manual: Manual = manual_builder.build();
33-
println!("Car manual built:\n{}", manual.to_string());
33+
println!("Car manual built:\n{}", manual);
3434
}

structural/decorator/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,5 @@ fn main() {
1414
print!("{}", char::from(byte));
1515
}
1616

17-
println!("");
17+
println!();
1818
}

structural/facade/main.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ use wallet_facade::WalletFacade;
99

1010
fn main() -> Result<(), String> {
1111
let mut wallet = WalletFacade::new("abc".into(), 1234);
12-
println!("");
12+
println!();
1313

1414
// Wallet Facade interacts with the account, code, wallet, notification and
1515
// ledger behind the scenes.
1616
wallet.add_money_to_wallet(&"abc".into(), 1234, 10)?;
17-
println!("");
17+
println!();
1818

1919
wallet.deduct_money_from_wallet(&"abc".into(), 1234, 5)
2020
}

structural/flyweight/forest.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ pub struct Forest {
2626

2727
impl Forest {
2828
pub fn plant_tree(&mut self, x: u32, y: u32, color: TreeColor, name: String, data: String) {
29-
let tree_kind = TreeKind::new(color, name.clone(), data);
29+
let tree_kind = TreeKind::new(color, name, data);
3030

3131
// Here is an essence of Flyweight: it's an internal cache,
3232
// there is always a single instance of a "tree kind" structure.

0 commit comments

Comments
 (0)