aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthew Collins <[email protected]>2018-03-01 13:21:58 +0000
committerMatthew Collins <[email protected]>2018-03-01 13:21:58 +0000
commit87f12035204ac34a0c394e3770ec0f3048900702 (patch)
tree7cc6a57a49de1c46e48c2d4685255a273ee00bab
parentDon't require the manager to implement Clone for the client to be clonable (diff)
downloadsteamworks-rs-87f12035204ac34a0c394e3770ec0f3048900702.tar.xz
steamworks-rs-87f12035204ac34a0c394e3770ec0f3048900702.zip
Replace Cow<str> with String in the API
The steamworks API states that returned strings may be freed at any time and must not be stored. Also adds a way to get the current user's name.
-rw-r--r--Cargo.toml4
-rw-r--r--src/app.rs4
-rw-r--r--src/friends.rs14
-rw-r--r--src/lib.rs1
-rw-r--r--src/utils.rs4
-rw-r--r--steamworks-sys/Cargo.toml2
-rw-r--r--steamworks-sys/src/lib.rs1
7 files changed, 20 insertions, 10 deletions
diff --git a/Cargo.toml b/Cargo.toml
index 9e06f6d..67073fc 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -1,6 +1,6 @@
[package]
name = "steamworks"
-version = "0.2.1"
+version = "0.3.0"
authors = ["Thinkofname"]
description = "Provides rust friendly bindings to the steamworks sdk"
license = "MIT / Apache-2.0"
@@ -20,7 +20,7 @@ members = [
]
[dependencies]
-steamworks-sys = {path = "./steamworks-sys", version = "0.2.0"}
+steamworks-sys = {path = "./steamworks-sys", version = "0.2.1"}
failure = "0.1.1"
bitflags = "1.0.1"
libc = "0.2.36"
diff --git a/src/app.rs b/src/app.rs
index d6e787f..99f7557 100644
--- a/src/app.rs
+++ b/src/app.rs
@@ -123,11 +123,11 @@ impl <Manager> Apps<Manager> {
///
/// If the language hasn't been set this returns the language
/// used for the steam UI.
- pub fn current_game_language(&self) -> Cow<str> {
+ pub fn current_game_language(&self) -> String {
unsafe {
let lang = sys::SteamAPI_ISteamApps_GetCurrentGameLanguage(self.apps);
let lang = CStr::from_ptr(lang);
- lang.to_string_lossy()
+ lang.to_string_lossy().into_owned()
}
}
diff --git a/src/friends.rs b/src/friends.rs
index c57d54d..1759158 100644
--- a/src/friends.rs
+++ b/src/friends.rs
@@ -49,6 +49,16 @@ pub struct Friends<Manager> {
}
impl <Manager> Friends<Manager> {
+
+ /// Returns the (display) name of the current user
+ pub fn name(&self) -> String {
+ unsafe {
+ let name = sys::SteamAPI_ISteamFriends_GetPersonaName(self.friends);
+ let name = CStr::from_ptr(name);
+ name.to_string_lossy().into_owned()
+ }
+ }
+
pub fn get_friends(&self, flags: FriendFlags) -> Vec<Friend<Manager>> {
unsafe {
let count = sys::SteamAPI_ISteamFriends_GetFriendCount(self.friends, flags.bits() as _);
@@ -121,11 +131,11 @@ impl <Manager> Friend<Manager> {
self.id
}
- pub fn name(&self) -> Cow<str> {
+ pub fn name(&self) -> String {
unsafe {
let name = sys::SteamAPI_ISteamFriends_GetFriendPersonaName(self.friends, self.id.0);
let name = CStr::from_ptr(name);
- name.to_string_lossy()
+ name.to_string_lossy().into_owned()
}
}
diff --git a/src/lib.rs b/src/lib.rs
index b359b70..4d8ab32 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -24,7 +24,6 @@ pub use user::*;
use std::sync::{Arc, Mutex, Weak};
use std::ffi::{CString, CStr};
-use std::borrow::Cow;
use std::fmt::{
Debug, Formatter, self
};
diff --git a/src/utils.rs b/src/utils.rs
index eb10d8b..5c5ae10 100644
--- a/src/utils.rs
+++ b/src/utils.rs
@@ -26,11 +26,11 @@ impl <Manager> Utils<Manager> {
/// running in.
///
/// Generally you want `Apps::current_game_language` instead of this
- pub fn ui_language(&self) -> Cow<str> {
+ pub fn ui_language(&self) -> String {
unsafe {
let lang = sys::SteamAPI_ISteamUtils_GetSteamUILanguage(self.utils);
let lang = CStr::from_ptr(lang);
- lang.to_string_lossy()
+ lang.to_string_lossy().into_owned()
}
}
diff --git a/steamworks-sys/Cargo.toml b/steamworks-sys/Cargo.toml
index d3b22cb..2d89333 100644
--- a/steamworks-sys/Cargo.toml
+++ b/steamworks-sys/Cargo.toml
@@ -1,6 +1,6 @@
[package]
name = "steamworks-sys"
-version = "0.2.0"
+version = "0.2.1"
authors = ["Thinkofname"]
build = "build.rs"
description = "Provides raw bindings to the steamworks sdk"
diff --git a/steamworks-sys/src/lib.rs b/steamworks-sys/src/lib.rs
index 42b5049..768cddc 100644
--- a/steamworks-sys/src/lib.rs
+++ b/steamworks-sys/src/lib.rs
@@ -311,6 +311,7 @@ extern "C" {
pub fn SteamAPI_ISteamFriends_GetFriendPersonaState(instance: *mut ISteamFriends, friend: u64) -> PersonaState;
pub fn SteamAPI_ISteamFriends_RequestUserInformation(instance: *mut ISteamFriends, user_id: u64, name_only: u8) -> u8;
pub fn SteamAPI_ISteamFriends_ActivateGameOverlayToWebPage(instance: *mut ISteamFriends, url: *const c_char);
+ pub fn SteamAPI_ISteamFriends_GetPersonaName(instance: *mut ISteamFriends) -> *const c_char;
pub fn SteamAPI_ISteamMatchmaking_CreateLobby(instance: *mut ISteamMatchmaking, lobby_ty: LobbyType, max_members: c_int) -> SteamAPICall;
pub fn SteamAPI_ISteamMatchmaking_RequestLobbyList(instance: *mut ISteamMatchmaking) -> SteamAPICall;