From c0e6f9ec34e8c6291b26689dfbc211426ef5d99e Mon Sep 17 00:00:00 2001 From: Henrik Friedrichsen Date: Wed, 20 Mar 2019 23:38:17 +0100 Subject: [PATCH] cargo fmt --- src/spotify.rs | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/src/spotify.rs b/src/spotify.rs index e21c91c..83f208d 100644 --- a/src/spotify.rs +++ b/src/spotify.rs @@ -10,8 +10,8 @@ use librespot::playback::audio_backend; use librespot::playback::config::Bitrate; use librespot::playback::player::Player; -use rspotify::spotify::client::Spotify as SpotifyAPI; use rspotify::spotify::client::ApiError; +use rspotify::spotify::client::Spotify as SpotifyAPI; use rspotify::spotify::model::page::Page; use rspotify::spotify::model::playlist::{PlaylistTrack, SimplifiedPlaylist}; use rspotify::spotify::model::search::SearchTracks; @@ -284,7 +284,9 @@ impl Spotify { /// retries once when rate limits are hit fn api_with_retry(&self, cb: F) -> Option - where F: Fn(&SpotifyAPI) -> Result { + where + F: Fn(&SpotifyAPI) -> Result, + { match cb(&self.api) { Ok(v) => Some(v), Err(e) => { @@ -294,17 +296,19 @@ impl Spotify { debug!("rate limit hit. waiting {:?} seconds", d); thread::sleep(Duration::from_secs(d.unwrap_or(0) as u64)); cb(&self.api).ok() + } else { + None } - else { None } + } else { + None } - else { None } } } } pub fn search(&self, query: &str, limit: u32, offset: u32) -> Option { //let res = self.api.search_track(query, limit, offset, None); - self.api_with_retry(|api| api.search_track(query, limit, offset, None) ) + self.api_with_retry(|api| api.search_track(query, limit, offset, None)) } pub fn current_user_playlist( @@ -312,7 +316,7 @@ impl Spotify { limit: u32, offset: u32, ) -> Option> { - self.api_with_retry(|api| api.current_user_playlists(limit, offset) ) + self.api_with_retry(|api| api.current_user_playlists(limit, offset)) } pub fn user_playlist_tracks( @@ -321,8 +325,9 @@ impl Spotify { limit: u32, offset: u32, ) -> Option> { - self.api_with_retry(|api| api - .user_playlist_tracks(&self.user, playlist_id, None, limit, offset, None)) + self.api_with_retry(|api| { + api.user_playlist_tracks(&self.user, playlist_id, None, limit, offset, None) + }) } pub fn load(&self, track: &Track) {