Skip to content

Commit 5a3c3fa

Browse files
committed
Try using get_mut() to get mutable reference.
1 parent d3abe13 commit 5a3c3fa

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
@@ -518,10 +518,25 @@ pub async fn handle_key_events(
518518
if let Some(selected_controller) =
519519
app.controller_state.selected()
520520
{
521-
let controller = &app.controllers[selected_controller];
521+
let controller = app
522+
.controllers
523+
.get_mut(selected_controller)
524+
.expect("Selected controller should be valid");
525+
522526
if let Some(index) = app.paired_devices_state.selected() {
523-
let device = &controller.paired_devices[index];
524-
device.toggle_favorite();
527+
match controller.paired_devices.get_mut(index) {
528+
Some(device) => {
529+
device.is_favorite = !device.is_favorite;
530+
}
531+
None => {
532+
Notification::send(
533+
"Selected device should be valid"
534+
.to_string(),
535+
NotificationLevel::Error,
536+
sender.clone(),
537+
)?;
538+
}
539+
}
525540
}
526541
}
527542
}

0 commit comments

Comments
 (0)