rich_sdl2_rust/audio/
driver.rs

1//! Provides methods that returns some driver names.
2
3use std::ffi::CStr;
4
5use crate::bind;
6
7/// Returns all of audio driver names recognized on now.
8#[must_use]
9pub fn all_audio_drivers() -> Vec<String> {
10    let num = unsafe { bind::SDL_GetNumAudioDrivers() };
11    (0..num)
12        .map(|index| {
13            let cstr = unsafe { CStr::from_ptr(bind::SDL_GetAudioDriver(index)) };
14            cstr.to_string_lossy().to_string()
15        })
16        .collect()
17}
18
19/// Returns the current audio driver name, or `None` if it does not exist.
20#[must_use]
21pub fn current_driver() -> Option<String> {
22    let ptr = unsafe { bind::SDL_GetCurrentAudioDriver() };
23    (!ptr.is_null()).then(|| {
24        let cstr = unsafe { CStr::from_ptr(ptr) };
25        cstr.to_string_lossy().to_string()
26    })
27}