diff options
| author | Matthew Collins <[email protected]> | 2020-09-02 20:16:20 +0100 |
|---|---|---|
| committer | Matthew Collins <[email protected]> | 2020-09-02 20:16:20 +0100 |
| commit | 8ded00a828d25e48bc0782e116c5e084cd42ecc3 (patch) | |
| tree | 01b6d6ce278708fd56245e4ab473bbeda19b9083 /src | |
| parent | Use `Fn` instead of `FnMut` for call results as they will be called at most once (diff) | |
| download | steamworks-rs-8ded00a828d25e48bc0782e116c5e084cd42ecc3.tar.xz steamworks-rs-8ded00a828d25e48bc0782e116c5e084cd42ecc3.zip | |
Use FnOnce instead of Fn for callresults
Diffstat (limited to 'src')
| -rw-r--r-- | src/callback.rs | 2 | ||||
| -rw-r--r-- | src/lib.rs | 2 | ||||
| -rw-r--r-- | src/matchmaking.rs | 6 | ||||
| -rw-r--r-- | src/ugc.rs | 10 | ||||
| -rw-r--r-- | 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<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, 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| { @@ -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 Fn(*mut libc::c_void, bool) + Send + 'static>>, + call_results: HashMap<sys::SteamAPICall_t, Box<dyn FnOnce(*mut libc::c_void, bool) + Send + 'static>>, } unsafe impl <Manager: Send + Sync> Send for Inner<Manager> {} 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 <Manager> Matchmaking<Manager> { pub fn request_lobby_list<F>(&self, cb: F) - where F: Fn(SResult<Vec<LobbyId>>) + 'static + Send + where F: FnOnce(SResult<Vec<LobbyId>>) + 'static + Send { unsafe { let api_call = sys::SteamAPI_ISteamMatchmaking_RequestLobbyList(self.mm); @@ -77,7 +77,7 @@ impl <Manager> Matchmaking<Manager> { /// * `LobbyEnter` /// * `LobbyCreated` pub fn create_lobby<F>(&self, ty: LobbyType, max_members: u32, cb: F) - where F: Fn(SResult<LobbyId>) + 'static + Send + where F: FnOnce(SResult<LobbyId>) + 'static + Send { assert!(max_members <= 250); // Steam API limits unsafe { @@ -105,7 +105,7 @@ impl <Manager> Matchmaking<Manager> { /// Tries to join the lobby with the given ID pub fn join_lobby<F>(&self, lobby: LobbyId, cb: F) - where F: Fn(Result<LobbyId, ()>) + 'static + Send + where F: FnOnce(Result<LobbyId, ()>) + 'static + Send { unsafe { let api_call = sys::SteamAPI_ISteamMatchmaking_JoinLobby(self.mm, lobby.0); @@ -255,7 +255,7 @@ impl <Manager> UGC<Manager> { /// Creates a workshop item pub fn create_item<F>(&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 <Manager> UGC<Manager> { /// Subscribes to a workshop item pub fn subscribe_item<F>(&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 <Manager> UGC<Manager> { } pub fn unsubscribe_item<F>(&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 <Manager> UpdateHandle<Manager> { } pub fn submit<F>(self, change_note: Option<&str>, cb: F) -> UpdateWatchHandle<Manager> - 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 <Manager> UserListQuery<Manager> { /// Runs the query pub fn fetch<F>(mut self, cb: F) - where F: for<'a> Fn(Result<QueryResults<'a>,SteamError>) + 'static + Send + where F: for<'a> FnOnce(Result<QueryResults<'a>,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 <Manager> UserStats<Manager> { pub fn find_leaderboard<F>(&self, name: &str, cb: F) - where F: Fn(Result<Option<Leaderboard>, SteamError>) + 'static + Send + where F: FnOnce(Result<Option<Leaderboard>, SteamError>) + 'static + Send { unsafe { let name = CString::new(name).unwrap(); @@ -39,7 +39,7 @@ impl <Manager> UserStats<Manager> { } 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 + where F: FnOnce(Result<Option<Leaderboard>, SteamError>) + 'static + Send { unsafe { let name = CString::new(name).unwrap(); @@ -74,7 +74,7 @@ impl <Manager> UserStats<Manager> { } 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 + where F: FnOnce(Result<Option<LeaderboardScoreUploaded>, SteamError>) + 'static + Send { unsafe { let method = match method { @@ -110,7 +110,7 @@ impl <Manager> UserStats<Manager> { max_details_len: usize, cb: F ) - where F: Fn(Result<Vec<LeaderboardEntry>, SteamError>) + 'static + Send + where F: FnOnce(Result<Vec<LeaderboardEntry>, SteamError>) + 'static + Send { unsafe { let request = match request { |