use crate::Component;
use flecs_sys::*;
use once_cell::sync::Lazy;
pub(crate) static NAME_SEP: Lazy<std::ffi::CString> =
Lazy::new(|| std::ffi::CString::new("::").unwrap());
pub unsafe fn ecs_field<T: Component>(it: *const ecs_iter_t, index: i32) -> *mut T {
let size = std::mem::size_of::<T>();
ecs_field_w_size(it, size, index) as *mut T
}
pub unsafe fn flecs_to_rust_str(cstr: *const ::std::os::raw::c_char) -> &'static str {
if cstr.is_null() {
return "";
}
let r_str = std::ffi::CStr::from_ptr(cstr);
if let Ok(r_str) = r_str.to_str() {
return r_str;
}
"Error"
}
pub unsafe fn flecs_to_rust_string(cstr: *const ::std::os::raw::c_char) -> String {
if cstr.is_null() {
return "".into();
}
let r_str = std::ffi::CStr::from_ptr(cstr);
if let Ok(r_str) = r_str.to_str() {
return r_str.into();
}
"".into()
}