Skip to content

Commit b225643

Browse files
committed
Try using get_mut() to get mutable reference.
1 parent adbbef7 commit b225643

File tree

2 files changed

+18
-7
lines changed

2 files changed

+18
-7
lines changed

src/bluetooth.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,6 @@ impl Device {
4444
Ok(())
4545
}
4646

47-
pub fn toggle_favorite(&mut self) -> () {
48-
self.is_favorite = !self.is_favorite;
49-
}
50-
5147
// https://specifications.freedesktop.org/icon-naming-spec/icon-naming-spec-latest.html
5248
pub fn get_icon(name: &str) -> Option<String> {
5349
match name {

src/handler.rs

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -550,10 +550,25 @@ pub async fn handle_key_events(
550550
if let Some(selected_controller) =
551551
app.controller_state.selected()
552552
{
553-
let controller = &app.controllers[selected_controller];
553+
let controller = app
554+
.controllers
555+
.get_mut(selected_controller)
556+
.expect("Selected controller should be valid");
557+
554558
if let Some(index) = app.paired_devices_state.selected() {
555-
let device = &controller.paired_devices[index];
556-
device.toggle_favorite();
559+
match controller.paired_devices.get_mut(index) {
560+
Some(device) => {
561+
device.is_favorite = !device.is_favorite;
562+
}
563+
None => {
564+
Notification::send(
565+
"Selected device should be valid"
566+
.to_string(),
567+
NotificationLevel::Error,
568+
sender.clone(),
569+
)?;
570+
}
571+
}
557572
}
558573
}
559574
}

0 commit comments

Comments
 (0)