use libc::c_char;
use std::ffi::{CStr, CString};
use std::ptr;
use vks;
#[inline]
pub fn from_vk_bool(v: vks::VkBool32) -> bool {
v != vks::VK_FALSE
}
#[inline]
pub fn to_vk_bool(v: bool) -> vks::VkBool32 {
if v {
vks::VK_TRUE
}
else {
vks::VK_FALSE
}
}
#[inline]
pub unsafe fn string_from_cstr(cstr: *const c_char) -> Option<String> {
if !cstr.is_null() {
Some(CStr::from_ptr(cstr).to_str().unwrap().to_owned())
}
else {
None
}
}
#[inline]
pub fn cstr_from_string(string: Option<String>) -> (Option<CString>, *const c_char) {
match string {
Some(string) => {
let cstr = CString::new(string).unwrap();
let ptr = cstr.as_ptr();
(Some(cstr), ptr)
}
None => (None, ptr::null()),
}
}
#[inline]
pub fn cstr_from_str(string: Option<&str>) -> (Option<CString>, *const c_char) {
match string {
Some(string) => {
let cstr = CString::new(string).unwrap();
let ptr = cstr.as_ptr();
(Some(cstr), ptr)
}
None => (None, ptr::null()),
}
}