From 2f660f74ecf66bc15cf18ea7bf317ed3a942eb8d Mon Sep 17 00:00:00 2001 From: johannesd3 Date: Tue, 9 Feb 2021 09:15:55 +0100 Subject: [PATCH] Small refactor --- playback/src/player.rs | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/playback/src/player.rs b/playback/src/player.rs index e3fb037e..8585a957 100644 --- a/playback/src/player.rs +++ b/playback/src/player.rs @@ -652,15 +652,23 @@ impl PlayerTrackLoader { ], }; - let (format, file_id) = formats - .iter() - .find_map(|format| Some((format, *audio.files.get(&format)?))) - .or_else(|| { - warn!("<{}> is not available in any supported format", audio.name); + let entry = formats.iter().find_map(|format| { + if let Some(&file_id) = audio.files.get(format) { + Some((*format, file_id)) + } else { None - })?; + } + }); - let bytes_per_second = self.stream_data_rate(*format); + let (format, file_id) = match entry { + Some(t) => t, + None => { + warn!("<{}> is not available in any supported format", audio.name); + return None; + } + }; + + let bytes_per_second = self.stream_data_rate(format); let play_from_beginning = position_ms == 0; let key = self.session.audio_key().request(spotify_id, file_id);