From 6309a544efc3db0833026d67c534a6e6400014ae Mon Sep 17 00:00:00 2001 From: Koen Bolhuis Date: Thu, 14 Jan 2021 23:48:27 +0100 Subject: [PATCH] Change all Client methods from &mut self to &self --- examples/delete_listen.rs | 2 +- examples/stats_sitewide_artists.rs | 2 +- examples/submit_listens.rs | 2 +- examples/user_activity.rs | 2 +- examples/user_artist_map.rs | 2 +- examples/user_listens.rs | 2 +- examples/user_stats.rs | 2 +- examples/users_recent_listens.rs | 2 +- examples/validate_token.rs | 2 +- src/client.rs | 40 +++++++++++++++--------------- 10 files changed, 29 insertions(+), 29 deletions(-) diff --git a/examples/delete_listen.rs b/examples/delete_listen.rs index bdf56a6..1fb71c3 100644 --- a/examples/delete_listen.rs +++ b/examples/delete_listen.rs @@ -7,7 +7,7 @@ fn main() { let listened_at = args.next().expect("No listened_at provided"); let recording_msid = args.next().expect("No recording_msid provided"); - let mut client = Client::new(); + let client = Client::new(); let delete = DeleteListen { listened_at: listened_at.parse().unwrap(), diff --git a/examples/stats_sitewide_artists.rs b/examples/stats_sitewide_artists.rs index d58bbd3..efda04a 100644 --- a/examples/stats_sitewide_artists.rs +++ b/examples/stats_sitewide_artists.rs @@ -1,7 +1,7 @@ use listenbrainz::Client; fn main() { - let mut client = Client::new(); + let client = Client::new(); let result = client.stats_sitewide_artists(None, None, Some("year")); println!("{:#?}", result); diff --git a/examples/submit_listens.rs b/examples/submit_listens.rs index 082741e..7376329 100644 --- a/examples/submit_listens.rs +++ b/examples/submit_listens.rs @@ -13,7 +13,7 @@ fn now() -> i64 { fn main() { let token = std::env::args().nth(1).expect("No token provided"); - let mut client = Client::new(); + let client = Client::new(); // Submit single diff --git a/examples/user_activity.rs b/examples/user_activity.rs index 24e8995..5366d6c 100644 --- a/examples/user_activity.rs +++ b/examples/user_activity.rs @@ -3,7 +3,7 @@ use listenbrainz::Client; fn main() { let user_name = std::env::args().nth(1).expect("No username provided"); - let mut client = Client::new(); + let client = Client::new(); let result = client.stats_user_listening_activity(&user_name, None); println!("{:#?}", result); diff --git a/examples/user_artist_map.rs b/examples/user_artist_map.rs index a6ed0fb..e390d62 100644 --- a/examples/user_artist_map.rs +++ b/examples/user_artist_map.rs @@ -3,7 +3,7 @@ use listenbrainz::Client; fn main() { let user_name = std::env::args().nth(1).expect("No username provided"); - let mut client = Client::new(); + let client = Client::new(); let result = client.stats_user_artist_map(&user_name, None, None); println!("{:#?}", result); diff --git a/examples/user_listens.rs b/examples/user_listens.rs index 1cc227c..c5e6cd1 100644 --- a/examples/user_listens.rs +++ b/examples/user_listens.rs @@ -3,7 +3,7 @@ use listenbrainz::Client; fn main() { let user_name = std::env::args().nth(1).expect("No username provided"); - let mut client = Client::new(); + let client = Client::new(); let result = client.user_listen_count(&user_name); println!("Listen count: {:#?}", result); diff --git a/examples/user_stats.rs b/examples/user_stats.rs index ec7b128..ea785f5 100644 --- a/examples/user_stats.rs +++ b/examples/user_stats.rs @@ -5,7 +5,7 @@ fn main() { let subject = args.next().expect("No subject provided"); let user_name = args.next().expect("No username provided"); - let mut client = Client::new(); + let client = Client::new(); match subject.as_str() { "recordings" => { diff --git a/examples/users_recent_listens.rs b/examples/users_recent_listens.rs index 337cc98..06dec71 100644 --- a/examples/users_recent_listens.rs +++ b/examples/users_recent_listens.rs @@ -4,7 +4,7 @@ fn main() { let users: Vec = std::env::args().skip(1).collect(); let users_ref: Vec<&str> = users.iter().map(String::as_str).collect(); - let mut client = Client::new(); + let client = Client::new(); let result = client.users_recent_listens(&users_ref); println!("{:#?}", result); diff --git a/examples/validate_token.rs b/examples/validate_token.rs index 753de58..61c19f3 100644 --- a/examples/validate_token.rs +++ b/examples/validate_token.rs @@ -3,7 +3,7 @@ use listenbrainz::Client; fn main() { let token = std::env::args().nth(1).expect("No token provided"); - let mut client = Client::new(); + let client = Client::new(); let result = client.validate_token(&token); println!("{:#?}", result); diff --git a/src/client.rs b/src/client.rs index 4aeffc2..9e9db21 100644 --- a/src/client.rs +++ b/src/client.rs @@ -26,7 +26,7 @@ impl Client { } } - fn get(&mut self, endpoint: Endpoint) -> Result { + fn get(&self, endpoint: Endpoint) -> Result { let endpoint = format!("{}{}", API_ROOT_URL, endpoint); self.agent @@ -37,7 +37,7 @@ impl Client { } fn get_stats( - &mut self, + &self, endpoint: Endpoint, count: Option, offset: Option, @@ -67,7 +67,7 @@ impl Client { } } - fn post(&mut self, endpoint: Endpoint, token: &str, data: D) -> Result + fn post(&self, endpoint: Endpoint, token: &str, data: D) -> Result where D: Serialize, R: DeserializeOwned, @@ -86,7 +86,7 @@ impl Client { /// Endpoint: [`submit-listens`](https://listenbrainz.readthedocs.io/en/production/dev/api/#post--1-submit-listens) pub fn submit_listens( - &mut self, + &self, token: &str, data: SubmitListens, ) -> Result { @@ -94,7 +94,7 @@ impl Client { } /// Endpoint: [`validate-token`](https://listenbrainz.readthedocs.io/en/production/dev/api/#get--1-validate-token) - pub fn validate_token(&mut self, token: &str) -> Result { + pub fn validate_token(&self, token: &str) -> Result { let endpoint = format!("{}{}", API_ROOT_URL, Endpoint::ValidateToken); self.agent @@ -107,7 +107,7 @@ impl Client { /// Endpoint: [`delete-listen`](https://listenbrainz.readthedocs.io/en/production/dev/api/#post--1-delete-listen) pub fn delete_listen( - &mut self, + &self, token: &str, data: DeleteListen, ) -> Result { @@ -116,25 +116,25 @@ impl Client { /// Endpoint: [`users/{user_list}/recent-listens`](https://listenbrainz.readthedocs.io/en/production/dev/api/#get--1-users-(user_list)-recent-listens) pub fn users_recent_listens( - &mut self, + &self, user_list: &[&str], ) -> Result { self.get(Endpoint::UsersRecentListens(user_list)) } /// Endpoint: [`user/{user_name}/listen-count`](https://listenbrainz.readthedocs.io/en/production/dev/api/#get--1-user-(user_name)-listen-count) - pub fn user_listen_count(&mut self, user_name: &str) -> Result { + pub fn user_listen_count(&self, user_name: &str) -> Result { self.get(Endpoint::UserListenCount(user_name)) } /// Endpoint: [`user/{user_name}/playing-now`](https://listenbrainz.readthedocs.io/en/production/dev/api/#get--1-user-(user_name)-playing-now) - pub fn user_playing_now(&mut self, user_name: &str) -> Result { + pub fn user_playing_now(&self, user_name: &str) -> Result { self.get(Endpoint::UserPlayingNow(user_name)) } /// Endpoint: [`user/{user_name}/listens`](https://listenbrainz.readthedocs.io/en/production/dev/api/#get--1-user-(user_name)-listens) pub fn user_listens( - &mut self, + &self, user_name: &str, min_ts: Option, max_ts: Option, @@ -162,7 +162,7 @@ impl Client { } /// Endpoint: [`latest-import`](https://listenbrainz.readthedocs.io/en/production/dev/api/#get--1-latest-import) (`GET`) - pub fn get_latest_import(&mut self, user_name: &str) -> Result { + pub fn get_latest_import(&self, user_name: &str) -> Result { let endpoint = format!("{}{}", API_ROOT_URL, Endpoint::LatestImport); self.agent @@ -175,7 +175,7 @@ impl Client { /// Endpoint: [`latest-import`](https://listenbrainz.readthedocs.io/en/production/dev/api/#post--1-latest-import) (`POST`) pub fn update_latest_import( - &mut self, + &self, token: &str, data: UpdateLatestImport, ) -> Result { @@ -184,7 +184,7 @@ impl Client { /// Endpoint: [`stats/sitewide/artists`](https://listenbrainz.readthedocs.io/en/production/dev/api/#get--1-stats-sitewide-artists) pub fn stats_sitewide_artists( - &mut self, + &self, count: Option, offset: Option, range: Option<&str>, @@ -194,7 +194,7 @@ impl Client { /// Endpoint: [`stats/user/{user_name}/listening-activity`](https://listenbrainz.readthedocs.io/en/production/dev/api/#get--1-stats-user-(user_name)-listening-activity) pub fn stats_user_listening_activity( - &mut self, + &self, user_name: &str, range: Option<&str>, ) -> Result, Error> { @@ -222,7 +222,7 @@ impl Client { /// Endpoint: [`stats/user/{user_name}/daily-activity`](https://listenbrainz.readthedocs.io/en/production/dev/api/#get--1-stats-user-(user_name)-daily-activity) pub fn stats_user_daily_activity( - &mut self, + &self, user_name: &str, range: Option<&str>, ) -> Result, Error> { @@ -250,7 +250,7 @@ impl Client { /// Endpoint: [`stats/user/{user_name}/recordings`](https://listenbrainz.readthedocs.io/en/production/dev/api/#get--1-stats-user-(user_name)-recordings) pub fn stats_user_recordings( - &mut self, + &self, user_name: &str, count: Option, offset: Option, @@ -266,7 +266,7 @@ impl Client { /// Endpoint: [`stats/user/{user_name}/artist-map`](https://listenbrainz.readthedocs.io/en/production/dev/api/#get--1-stats-user-(user_name)-artist-map) pub fn stats_user_artist_map( - &mut self, + &self, user_name: &str, range: Option<&str>, force_recalculate: Option, @@ -291,7 +291,7 @@ impl Client { /// Endpoint: [`stats/user/{user_name}/releases`](https://listenbrainz.readthedocs.io/en/production/dev/api/#get--1-stats-user-(user_name)-releases) pub fn stats_user_releases( - &mut self, + &self, user_name: &str, count: Option, offset: Option, @@ -302,7 +302,7 @@ impl Client { /// Endpoint: [`stats/user/{user_name}/artists`](https://listenbrainz.readthedocs.io/en/production/dev/api/#get--1-stats-user-(user_name)-artists) pub fn stats_user_artists( - &mut self, + &self, user_name: &str, count: Option, offset: Option, @@ -313,7 +313,7 @@ impl Client { /// Endpoint: [`status/get-dump-info`](https://listenbrainz.readthedocs.io/en/production/dev/api/#get--1-status-get-dump-info) pub fn status_get_dump_info( - &mut self, + &self, id: Option, ) -> Result { let endpoint = format!("{}{}", API_ROOT_URL, Endpoint::StatusGetDumpInfo);