Skip to content

Commit 1031387

Browse files
Dmytro Lysaipingw33n
authored andcommitted
Fix clippy issues
1 parent 992cf8a commit 1031387

File tree

5 files changed

+11
-13
lines changed

5 files changed

+11
-13
lines changed

src/game/inventory.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ impl Inventory {
5252
}
5353

5454
pub fn handle(&mut self, cmd: UiCommand, rpg: &Rpg, ui: &mut Ui) {
55-
match cmd.data {
56-
UiCommandData::Inventory(c) => match c {
55+
if let UiCommandData::Inventory(c) = cmd.data {
56+
match c {
5757
Command::Show => {
5858
self.show(rpg, ui);
5959
}
@@ -77,7 +77,6 @@ impl Inventory {
7777
self.internal.as_mut().unwrap().toggle_mouse_mode(ui);
7878
}
7979
}
80-
_ => {}
8180
}
8281
}
8382

@@ -259,7 +258,7 @@ impl Internal {
259258
let obj = world.objects().get(self.obj);
260259
for item in &obj.inventory.items {
261260
let item_obj = &world.objects().get(item.object);
262-
let inv_list_item = Self::to_inv_list_item(item, item_obj);
261+
let inv_list_item = Self::make_list_item(item, item_obj);
263262
match () {
264263
_ if item_obj.flags.contains(Flag::Worn) => {
265264
assert!(wearing.items().is_empty());
@@ -283,7 +282,7 @@ impl Internal {
283282
}
284283

285284
// display_inventory_info
286-
fn to_inv_list_item(item: &InventoryItem, obj: &Object) -> inventory_list::Item {
285+
fn make_list_item(item: &InventoryItem, obj: &Object) -> inventory_list::Item {
287286
let proto = obj.proto().unwrap();
288287
let count = if obj.item_kind() == Some(ItemKind::Ammo) {
289288
obj.proto().unwrap().max_ammo_count().unwrap() * (item.count - 1)
@@ -521,9 +520,9 @@ impl Internal {
521520
};
522521
let msg = BString::concat(&[
523522
name.as_bytes(),
524-
"\n--------------------\n".as_bytes(),
523+
b"\n--------------------\n",
525524
description.as_bytes(),
526-
"\n".as_bytes(),
525+
b"\n",
527526
weight_msg.as_bytes()]);
528527
ui.widget_mut::<Panel>(self.item_descr).text_mut().unwrap().text = msg;
529528
self.switch_text_panels(false, ui);

src/game/object.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1106,7 +1106,6 @@ impl Objects {
11061106
/// 1. There's a path between them which is not sight-blocked (see `sight_blocker_for_object()`).
11071107
/// 2. Screen distance between objects is within the limit.
11081108
// action_can_talk_to()
1109-
#[must_use]
11101109
pub fn can_talk(&self, obj1: Handle, obj2: Handle) -> Result<(), CantTalkSpatial> {
11111110
let o1 = self.get(obj1);
11121111
let o2 = self.get(obj2);

src/game/state.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ impl GameState {
116116

117117
let world_view_rect = Rect::with_size(0, 0, 640, 379);
118118
let world_view = {
119-
let win = ui.new_window(world_view_rect.clone(), None);
119+
let win = ui.new_window(world_view_rect, None);
120120
ui.new_widget(win, world_view_rect, None, None, WorldView::new(world.clone()))
121121
};
122122
let message_panel = hud::create(ui);

src/game/ui/action_menu.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ pub fn show(actions: Vec<(Action, UiCommandData)>, win: Handle, ui: &mut Ui) ->
2121
};
2222

2323
ui.show_cursor_ghost();
24-
ui.set_cursor_constraint(placement.rect.clone());
24+
ui.set_cursor_constraint(placement.rect);
2525
ui.set_cursor_pos(placement.rect.top_left());
2626

2727
let action_menu = ui.new_widget(win, placement.rect, Some(Cursor::Hidden), None,

src/game/ui/inventory_list.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ impl InventoryList {
7777

7878
pub fn can_scroll(&self, scroll: Scroll) -> bool {
7979
match scroll {
80-
Scroll::Down => self.scroll_idx + 1 <= self.max_scroll_idx(),
80+
Scroll::Down => self.scroll_idx < self.max_scroll_idx(),
8181
Scroll::Up => self.scroll_idx > 0,
8282
}
8383
}
@@ -89,7 +89,7 @@ impl InventoryList {
8989
pub fn scroll(&mut self, scroll: Scroll) {
9090
self.set_scroll_idx(match scroll {
9191
Scroll::Down => self.scroll_idx + 1,
92-
Scroll::Up => self.scroll_idx.checked_sub(1).unwrap_or(0),
92+
Scroll::Up => self.scroll_idx.saturating_sub(1),
9393
});
9494
}
9595

@@ -106,7 +106,7 @@ impl InventoryList {
106106
}
107107

108108
fn max_scroll_idx(&self) -> usize {
109-
self.items.len().checked_sub(self.visible_items).unwrap_or(0)
109+
self.items.len().saturating_sub(self.visible_items)
110110
}
111111

112112
fn item_index_at(&self, rect: Rect, pos: Point) -> Option<usize> {

0 commit comments

Comments
 (0)