diff options
| author | William Venner <[email protected]> | 2021-04-24 00:06:58 +0100 |
|---|---|---|
| committer | William Venner <[email protected]> | 2021-04-24 00:06:58 +0100 |
| commit | 02438a6a85fe3452e33a638816487cdad478e283 (patch) | |
| tree | 83c26794c895727404eb93d8dfb66cc2c767978f | |
| parent | Merge pull request #45 from WilliamVenner/fix/macos_builds (diff) | |
| download | steamworks-rs-02438a6a85fe3452e33a638816487cdad478e283.tar.xz steamworks-rs-02438a6a85fe3452e33a638816487cdad478e283.zip | |
Add safe wrapper for sys::SteamParamStringArray_t
| -rw-r--r-- | src/utils.rs | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/src/utils.rs b/src/utils.rs index 5120f40..5b853ab 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -100,3 +100,24 @@ impl <Manager> Utils<Manager> { } } } + +pub(crate) struct SteamParamStringArray(Vec<*mut i8>); +impl Drop for SteamParamStringArray { + fn drop(&mut self) { + for c_string in &self.0 { + unsafe { CString::from_raw(*c_string) }; + } + } +} +impl SteamParamStringArray { + pub(crate) fn new<S: AsRef<str>>(vec: &[S]) -> SteamParamStringArray { + SteamParamStringArray(vec.into_iter().map(|s| CString::new(s.as_ref()).expect("String passed could not be converted to a c string").into_raw()).collect()) + } + + pub(crate) fn as_raw(&mut self) -> sys::SteamParamStringArray_t { + sys::SteamParamStringArray_t { + m_nNumStrings: self.0.len() as i32, + m_ppStrings: self.0.as_mut_ptr() as *mut *const i8 + } + } +} |