From a8eec1dee66715a3be3ec3072c7876150ad0f3d8 Mon Sep 17 00:00:00 2001 From: Chris Cochrun Date: Tue, 16 May 2023 21:33:03 -0500 Subject: [PATCH] condition around getting a song --- src/rust/song_model.rs | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/rust/song_model.rs b/src/rust/song_model.rs index 1b565fd..4d608c2 100644 --- a/src/rust/song_model.rs +++ b/src/rust/song_model.rs @@ -263,11 +263,14 @@ mod song_model { .execute(db); match result { Ok(_i) => { - let song = self.as_mut().songs_mut().get_mut(index as usize).unwrap(); - song.title = updated_title.to_string(); - self.as_mut() - .emit_data_changed(model_index, model_index, &vector_roles); - true + if let Some(song) = self.as_mut().songs_mut().get_mut(index as usize) { + song.title = updated_title.to_string(); + self.as_mut() + .emit_data_changed(model_index, model_index, &vector_roles); + true + } else { + false + } } Err(_e) => false, }