diff options
| author | Matthew Collins <[email protected]> | 2020-06-21 20:10:56 +0100 |
|---|---|---|
| committer | Matthew Collins <[email protected]> | 2020-06-21 20:10:56 +0100 |
| commit | f0a4d2472820d5592cef9d3f4cb57c8ba17e5b2b (patch) | |
| tree | 1c72dd026e7015da9a45f32a4427834bc23d9d09 /src | |
| parent | Merge pull request #23 from wyozi/patch-1 (diff) | |
| download | steamworks-rs-f0a4d2472820d5592cef9d3f4cb57c8ba17e5b2b.tar.xz steamworks-rs-f0a4d2472820d5592cef9d3f4cb57c8ba17e5b2b.zip | |
Use `Fn` instead of `FnMut` for call results as they will be called at most once
Diffstat (limited to 'src')
| -rw-r--r-- | src/callback.rs | 4 | ||||
| -rw-r--r-- | src/lib.rs | 4 | ||||
| -rw-r--r-- | src/matchmaking.rs | 12 | ||||
| -rw-r--r-- | src/ugc.rs | 28 | ||||
| -rw-r--r-- | src/user_stats.rs | 16 |
5 files changed, 32 insertions, 32 deletions
diff --git a/src/callback.rs b/src/callback.rs index caa1a4b..1552611 100644 --- a/src/callback.rs +++ b/src/callback.rs @@ -47,8 +47,8 @@ pub(crate) unsafe fn register_callback<C, F, Manager>(inner: &Arc<Inner<Manager> } } -pub(crate) unsafe fn register_call_result<C, F, Manager>(inner: &Arc<Inner<Manager>>, api_call: sys::SteamAPICall_t, _callback_id: i32, mut f: F) - where F: for <'a> FnMut(&'a C, bool) + 'static + Send +pub(crate) unsafe fn register_call_result<C, F, Manager>(inner: &Arc<Inner<Manager>>, api_call: sys::SteamAPICall_t, _callback_id: i32, f: F) + where F: for <'a> Fn(&'a C, bool) + 'static + Send { let mut callbacks = inner.callbacks.lock().unwrap(); callbacks.call_results.insert(api_call, Box::new(move |param, failed| { @@ -83,7 +83,7 @@ struct Inner<Manager> { struct Callbacks { callbacks: HashMap<i32, Box<dyn FnMut(*mut libc::c_void) + Send + 'static>>, - call_results: HashMap<sys::SteamAPICall_t, Box<dyn FnMut(*mut libc::c_void, bool) + Send + 'static>>, + call_results: HashMap<sys::SteamAPICall_t, Box<dyn Fn(*mut libc::c_void, bool) + Send + 'static>>, } unsafe impl <Manager: Send + Sync> Send for Inner<Manager> {} @@ -173,7 +173,7 @@ impl <M> SingleClient<M> where M: Manager { apicall_result.as_mut_ptr() as *mut _, apicall.m_cubParam as _, apicall.m_iCallback, &mut failed ) { - if let Some(mut cb) = callbacks.call_results.remove(&apicall.m_hAsyncCall) { + if let Some(cb) = callbacks.call_results.remove(&apicall.m_hAsyncCall) { cb(apicall_result.as_mut_ptr() as *mut _, failed); } } diff --git a/src/matchmaking.rs b/src/matchmaking.rs index ed4cd57..3145e2f 100644 --- a/src/matchmaking.rs +++ b/src/matchmaking.rs @@ -44,8 +44,8 @@ impl LobbyId { impl <Manager> Matchmaking<Manager> { - pub fn request_lobby_list<F>(&self, mut cb: F) - where F: FnMut(SResult<Vec<LobbyId>>) + 'static + Send + pub fn request_lobby_list<F>(&self, cb: F) + where F: Fn(SResult<Vec<LobbyId>>) + 'static + Send { unsafe { let api_call = sys::SteamAPI_ISteamMatchmaking_RequestLobbyList(self.mm); @@ -76,8 +76,8 @@ impl <Manager> Matchmaking<Manager> { /// /// * `LobbyEnter` /// * `LobbyCreated` - pub fn create_lobby<F>(&self, ty: LobbyType, max_members: u32, mut cb: F) - where F: FnMut(SResult<LobbyId>) + 'static + Send + pub fn create_lobby<F>(&self, ty: LobbyType, max_members: u32, cb: F) + where F: Fn(SResult<LobbyId>) + 'static + Send { assert!(max_members <= 250); // Steam API limits unsafe { @@ -104,8 +104,8 @@ impl <Manager> Matchmaking<Manager> { } /// Tries to join the lobby with the given ID - pub fn join_lobby<F>(&self, lobby: LobbyId, mut cb: F) - where F: FnMut(Result<LobbyId, ()>) + 'static + Send + pub fn join_lobby<F>(&self, lobby: LobbyId, cb: F) + where F: Fn(Result<LobbyId, ()>) + 'static + Send { unsafe { let api_call = sys::SteamAPI_ISteamMatchmaking_JoinLobby(self.mm, lobby.0); @@ -254,8 +254,8 @@ impl <Manager> UGC<Manager> { } /// Creates a workshop item - pub fn create_item<F>(&self, app_id: AppId, file_type: FileType, mut cb: F) - where F: FnMut(Result<(PublishedFileId, bool), SteamError>) + 'static + Send + pub fn create_item<F>(&self, app_id: AppId, file_type: FileType, cb: F) + where F: Fn(Result<(PublishedFileId, bool), SteamError>) + 'static + Send { unsafe { let api_call = sys::SteamAPI_ISteamUGC_CreateItem(self.ugc, app_id.0, file_type.into()); @@ -291,8 +291,8 @@ impl <Manager> UGC<Manager> { } /// Subscribes to a workshop item - pub fn subscribe_item<F>(&self, published_file_id: PublishedFileId, mut cb: F) - where F: FnMut(Result<(), SteamError>) + 'static + Send + pub fn subscribe_item<F>(&self, published_file_id: PublishedFileId, cb: F) + where F: Fn(Result<(), SteamError>) + 'static + Send { unsafe { let api_call = sys::SteamAPI_ISteamUGC_SubscribeItem(self.ugc, published_file_id.0); @@ -310,8 +310,8 @@ impl <Manager> UGC<Manager> { } } - pub fn unsubscribe_item<F>(&self, published_file_id: PublishedFileId, mut cb: F) - where F: FnMut(Result<(), SteamError>) + 'static + Send + pub fn unsubscribe_item<F>(&self, published_file_id: PublishedFileId, cb: F) + where F: Fn(Result<(), SteamError>) + 'static + Send { unsafe { let api_call = sys::SteamAPI_ISteamUGC_UnsubscribeItem(self.ugc, published_file_id.0); @@ -466,8 +466,8 @@ impl <Manager> UpdateHandle<Manager> { self } - pub fn submit<F>(self, change_note: Option<&str>, mut cb: F) -> UpdateWatchHandle<Manager> - where F: FnMut(Result<(PublishedFileId, bool), SteamError>) + 'static + Send + pub fn submit<F>(self, change_note: Option<&str>, cb: F) -> UpdateWatchHandle<Manager> + where F: Fn(Result<(PublishedFileId, bool), SteamError>) + 'static + Send { use std::ptr; unsafe { @@ -650,8 +650,8 @@ impl <Manager> UserListQuery<Manager> { } /// Runs the query - pub fn fetch<F>(mut self, mut cb: F) - where F: for<'a> FnMut(Result<QueryResults<'a>,SteamError>) + 'static + Send + pub fn fetch<F>(mut self, cb: F) + where F: for<'a> Fn(Result<QueryResults<'a>,SteamError>) + 'static + Send { let ugc = self.ugc; let inner = Arc::clone(&self.inner); @@ -688,8 +688,8 @@ impl <Manager> UserListQuery<Manager> { } /// Runs the query, only fetching the total number of results. - pub fn fetch_total<F>(self, mut cb: F) - where F: FnMut(Result<u32, SteamError>) + 'static + Send + pub fn fetch_total<F>(self, cb: F) + where F: Fn(Result<u32, SteamError>) + 'static + Send { unsafe { let ok = sys::SteamAPI_ISteamUGC_SetReturnTotalOnly(self.ugc, self.handle.unwrap(), true); @@ -700,8 +700,8 @@ impl <Manager> UserListQuery<Manager> { } /// Runs the query, only fetchind the IDs. - pub fn fetch_ids<F>(self, mut cb: F) - where F: FnMut(Result<Vec<PublishedFileId>, SteamError>) + 'static + Send + pub fn fetch_ids<F>(self, cb: F) + where F: Fn(Result<Vec<PublishedFileId>, SteamError>) + 'static + Send { unsafe { let ok = sys::SteamAPI_ISteamUGC_SetReturnOnlyIDs(self.ugc, self.handle.unwrap(), true); diff --git a/src/user_stats.rs b/src/user_stats.rs index 000ffab..d085313 100644 --- a/src/user_stats.rs +++ b/src/user_stats.rs @@ -16,8 +16,8 @@ const CALLBACK_BASE_ID: i32 = 1100; impl <Manager> UserStats<Manager> { - pub fn find_leaderboard<F>(&self, name: &str, mut cb: F) - where F: FnMut(Result<Option<Leaderboard>, SteamError>) + 'static + Send + pub fn find_leaderboard<F>(&self, name: &str, cb: F) + where F: Fn(Result<Option<Leaderboard>, SteamError>) + 'static + Send { unsafe { let name = CString::new(name).unwrap(); @@ -38,8 +38,8 @@ impl <Manager> UserStats<Manager> { } } - pub fn find_or_create_leaderboard<F>(&self, name: &str, sort_method: LeaderboardSortMethod, display_type: LeaderboardDisplayType, mut cb: F) - where F: FnMut(Result<Option<Leaderboard>, SteamError>) + 'static + Send + pub fn find_or_create_leaderboard<F>(&self, name: &str, sort_method: LeaderboardSortMethod, display_type: LeaderboardDisplayType, cb: F) + where F: Fn(Result<Option<Leaderboard>, SteamError>) + 'static + Send { unsafe { let name = CString::new(name).unwrap(); @@ -73,8 +73,8 @@ impl <Manager> UserStats<Manager> { } } - pub fn upload_leaderboard_score<F>(&self, leaderboard: &Leaderboard, method: UploadScoreMethod, score: i32, details: &[i32], mut cb: F) - where F: FnMut(Result<Option<LeaderboardScoreUploaded>, SteamError>) + 'static + Send + pub fn upload_leaderboard_score<F>(&self, leaderboard: &Leaderboard, method: UploadScoreMethod, score: i32, details: &[i32], cb: F) + where F: Fn(Result<Option<LeaderboardScoreUploaded>, SteamError>) + 'static + Send { unsafe { let method = match method { @@ -108,9 +108,9 @@ impl <Manager> UserStats<Manager> { leaderboard: &Leaderboard, request: LeaderboardDataRequest, start: usize, end: usize, max_details_len: usize, - mut cb: F + cb: F ) - where F: FnMut(Result<Vec<LeaderboardEntry>, SteamError>) + 'static + Send + where F: Fn(Result<Vec<LeaderboardEntry>, SteamError>) + 'static + Send { unsafe { let request = match request { |