rich_sdl2_rust/
file.rs

1//! A file handing on SDL2.
2
3use std::ffi::{CStr, CString};
4
5use crate::bind;
6
7pub mod mode;
8mod rw;
9
10pub use rw::*;
11
12/// Returns the base path of your application.
13#[must_use]
14pub fn base_path() -> String {
15    let cstr = unsafe { CStr::from_ptr(bind::SDL_GetBasePath()) };
16    cstr.to_string_lossy().to_string()
17}
18
19/// Returns the preferences path for your application.
20///
21/// # Panics
22///
23/// Panics if `org` or `app` contains a null character.
24#[must_use]
25pub fn pref_path(org: &str, app: &str) -> String {
26    let org_cstr = CString::new(org).unwrap();
27    let app_cstr = CString::new(app).unwrap();
28    let cstr =
29        unsafe { CStr::from_ptr(bind::SDL_GetPrefPath(org_cstr.as_ptr(), app_cstr.as_ptr())) };
30    cstr.to_string_lossy().to_string()
31}