From 8ded00a828d25e48bc0782e116c5e084cd42ecc3 Mon Sep 17 00:00:00 2001 From: Matthew Collins Date: Wed, 2 Sep 2020 20:16:20 +0100 Subject: Use FnOnce instead of Fn for callresults --- src/callback.rs | 2 +- src/lib.rs | 2 +- src/matchmaking.rs | 6 +++--- src/ugc.rs | 10 +++++----- src/user_stats.rs | 8 ++++---- 5 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/callback.rs b/src/callback.rs index 1552611..6af5087 100644 --- a/src/callback.rs +++ b/src/callback.rs @@ -48,7 +48,7 @@ pub(crate) unsafe fn register_callback(inner: &Arc } pub(crate) unsafe fn register_call_result(inner: &Arc>, api_call: sys::SteamAPICall_t, _callback_id: i32, f: F) - where F: for <'a> Fn(&'a C, bool) + 'static + Send + where F: for <'a> FnOnce(&'a C, bool) + 'static + Send { let mut callbacks = inner.callbacks.lock().unwrap(); callbacks.call_results.insert(api_call, Box::new(move |param, failed| { diff --git a/src/lib.rs b/src/lib.rs index db442f9..8c272a8 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -83,7 +83,7 @@ struct Inner { struct Callbacks { callbacks: HashMap>, - call_results: HashMap>, + call_results: HashMap>, } unsafe impl Send for Inner {} diff --git a/src/matchmaking.rs b/src/matchmaking.rs index 3145e2f..056d5ca 100644 --- a/src/matchmaking.rs +++ b/src/matchmaking.rs @@ -45,7 +45,7 @@ impl LobbyId { impl Matchmaking { pub fn request_lobby_list(&self, cb: F) - where F: Fn(SResult>) + 'static + Send + where F: FnOnce(SResult>) + 'static + Send { unsafe { let api_call = sys::SteamAPI_ISteamMatchmaking_RequestLobbyList(self.mm); @@ -77,7 +77,7 @@ impl Matchmaking { /// * `LobbyEnter` /// * `LobbyCreated` pub fn create_lobby(&self, ty: LobbyType, max_members: u32, cb: F) - where F: Fn(SResult) + 'static + Send + where F: FnOnce(SResult) + 'static + Send { assert!(max_members <= 250); // Steam API limits unsafe { @@ -105,7 +105,7 @@ impl Matchmaking { /// Tries to join the lobby with the given ID pub fn join_lobby(&self, lobby: LobbyId, cb: F) - where F: Fn(Result) + 'static + Send + where F: FnOnce(Result) + 'static + Send { unsafe { let api_call = sys::SteamAPI_ISteamMatchmaking_JoinLobby(self.mm, lobby.0); diff --git a/src/ugc.rs b/src/ugc.rs index a2a774e..e680601 100644 --- a/src/ugc.rs +++ b/src/ugc.rs @@ -255,7 +255,7 @@ impl UGC { /// Creates a workshop item pub fn create_item(&self, app_id: AppId, file_type: FileType, cb: F) - where F: Fn(Result<(PublishedFileId, bool), SteamError>) + 'static + Send + where F: FnOnce(Result<(PublishedFileId, bool), SteamError>) + 'static + Send { unsafe { let api_call = sys::SteamAPI_ISteamUGC_CreateItem(self.ugc, app_id.0, file_type.into()); @@ -292,7 +292,7 @@ impl UGC { /// Subscribes to a workshop item pub fn subscribe_item(&self, published_file_id: PublishedFileId, cb: F) - where F: Fn(Result<(), SteamError>) + 'static + Send + where F: FnOnce(Result<(), SteamError>) + 'static + Send { unsafe { let api_call = sys::SteamAPI_ISteamUGC_SubscribeItem(self.ugc, published_file_id.0); @@ -311,7 +311,7 @@ impl UGC { } pub fn unsubscribe_item(&self, published_file_id: PublishedFileId, cb: F) - where F: Fn(Result<(), SteamError>) + 'static + Send + where F: FnOnce(Result<(), SteamError>) + 'static + Send { unsafe { let api_call = sys::SteamAPI_ISteamUGC_UnsubscribeItem(self.ugc, published_file_id.0); @@ -467,7 +467,7 @@ impl UpdateHandle { } pub fn submit(self, change_note: Option<&str>, cb: F) -> UpdateWatchHandle - where F: Fn(Result<(PublishedFileId, bool), SteamError>) + 'static + Send + where F: FnOnce(Result<(PublishedFileId, bool), SteamError>) + 'static + Send { use std::ptr; unsafe { @@ -651,7 +651,7 @@ impl UserListQuery { /// Runs the query pub fn fetch(mut self, cb: F) - where F: for<'a> Fn(Result,SteamError>) + 'static + Send + where F: for<'a> FnOnce(Result,SteamError>) + 'static + Send { let ugc = self.ugc; let inner = Arc::clone(&self.inner); diff --git a/src/user_stats.rs b/src/user_stats.rs index d085313..e6313d6 100644 --- a/src/user_stats.rs +++ b/src/user_stats.rs @@ -17,7 +17,7 @@ const CALLBACK_BASE_ID: i32 = 1100; impl UserStats { pub fn find_leaderboard(&self, name: &str, cb: F) - where F: Fn(Result, SteamError>) + 'static + Send + where F: FnOnce(Result, SteamError>) + 'static + Send { unsafe { let name = CString::new(name).unwrap(); @@ -39,7 +39,7 @@ impl UserStats { } pub fn find_or_create_leaderboard(&self, name: &str, sort_method: LeaderboardSortMethod, display_type: LeaderboardDisplayType, cb: F) - where F: Fn(Result, SteamError>) + 'static + Send + where F: FnOnce(Result, SteamError>) + 'static + Send { unsafe { let name = CString::new(name).unwrap(); @@ -74,7 +74,7 @@ impl UserStats { } pub fn upload_leaderboard_score(&self, leaderboard: &Leaderboard, method: UploadScoreMethod, score: i32, details: &[i32], cb: F) - where F: Fn(Result, SteamError>) + 'static + Send + where F: FnOnce(Result, SteamError>) + 'static + Send { unsafe { let method = match method { @@ -110,7 +110,7 @@ impl UserStats { max_details_len: usize, cb: F ) - where F: Fn(Result, SteamError>) + 'static + Send + where F: FnOnce(Result, SteamError>) + 'static + Send { unsafe { let request = match request { -- cgit v1.2.3