use core::ffi::CStr;
use core::ptr::NonNull;
use crate::core::*;
use crate::sys;
extern crate alloc;
use alloc::string::{String, ToString};
impl World {
#[inline(always)]
pub fn doc_name(&self, entity: impl IntoEntity) -> Option<String> {
let cstr = NonNull::new(unsafe {
sys::ecs_doc_get_name(self.world_ptr(), *entity.into_entity(self))
} as *mut _)
.map(|s| unsafe { CStr::from_ptr(s.as_ptr()) });
cstr.and_then(|s| s.to_str().ok().map(ToString::to_string))
}
#[inline(always)]
pub fn doc_brief(&self, entity: impl IntoEntity) -> Option<String> {
let cstr = NonNull::new(unsafe {
sys::ecs_doc_get_brief(self.world_ptr(), *entity.into_entity(self))
} as *mut _)
.map(|s| unsafe { CStr::from_ptr(s.as_ptr()) });
cstr.and_then(|s| s.to_str().ok().map(ToString::to_string))
}
#[inline(always)]
pub fn doc_detail(&self, entity: impl IntoEntity) -> Option<String> {
let cstr = NonNull::new(unsafe {
sys::ecs_doc_get_detail(self.world_ptr(), *entity.into_entity(self))
} as *mut _)
.map(|s| unsafe { CStr::from_ptr(s.as_ptr()) });
cstr.and_then(|s| s.to_str().ok().map(ToString::to_string))
}
#[inline(always)]
pub fn doc_link(&self, entity: impl IntoEntity) -> Option<String> {
let cstr = NonNull::new(unsafe {
sys::ecs_doc_get_link(self.world_ptr(), *entity.into_entity(self))
} as *mut _)
.map(|s| unsafe { CStr::from_ptr(s.as_ptr()) });
cstr.and_then(|s| s.to_str().ok().map(ToString::to_string))
}
#[inline(always)]
pub fn doc_color(&self, entity: impl IntoEntity) -> Option<String> {
let cstr = NonNull::new(unsafe {
sys::ecs_doc_get_color(self.world_ptr(), *entity.into_entity(self))
} as *mut _)
.map(|s| unsafe { CStr::from_ptr(s.as_ptr()) });
cstr.and_then(|s| s.to_str().ok().map(ToString::to_string))
}
pub fn doc_uuid(&self, entity: impl IntoEntity) -> Option<String> {
let cstr = NonNull::new(unsafe {
sys::ecs_doc_get_uuid(self.world_ptr(), *entity.into_entity(self))
} as *mut _)
.map(|s| unsafe { CStr::from_ptr(s.as_ptr()) });
cstr.and_then(|s| s.to_str().ok().map(ToString::to_string))
}
#[inline(always)]
pub fn set_doc_name(&self, entity: impl IntoEntity, name: &str) {
let name = compact_str::format_compact!("{}\0", name);
unsafe {
sys::ecs_doc_set_name(
self.ptr_mut(),
*entity.into_entity(self),
name.as_ptr() as *const _,
);
};
}
#[inline(always)]
pub fn set_doc_brief(&self, entity: impl IntoEntity, brief: &str) {
let brief = compact_str::format_compact!("{}\0", brief);
unsafe {
sys::ecs_doc_set_brief(
self.ptr_mut(),
*entity.into_entity(self),
brief.as_ptr() as *const _,
);
};
}
#[inline(always)]
pub fn set_doc_detail(&self, entity: impl IntoEntity, detail: &str) {
let detail = compact_str::format_compact!("{}\0", detail);
unsafe {
sys::ecs_doc_set_detail(
self.ptr_mut(),
*entity.into_entity(self),
detail.as_ptr() as *const _,
);
};
}
#[inline(always)]
pub fn set_doc_link(&self, entity: impl IntoEntity, link: &str) {
let link = compact_str::format_compact!("{}\0", link);
unsafe {
sys::ecs_doc_set_link(
self.ptr_mut(),
*entity.into_entity(self),
link.as_ptr() as *const _,
);
};
}
#[inline(always)]
pub fn set_doc_color(&self, entity: impl IntoEntity, color: &str) {
let color = compact_str::format_compact!("{}\0", color);
unsafe {
sys::ecs_doc_set_color(
self.ptr_mut(),
*entity.into_entity(self),
color.as_ptr() as *const _,
);
};
}
pub fn set_doc_uuid(&self, entity: impl IntoEntity, uuid: &str) {
let uuid = compact_str::format_compact!("{}\0", uuid);
unsafe {
sys::ecs_doc_set_uuid(
self.ptr_mut(),
*entity.into_entity(self),
uuid.as_ptr() as *const _,
);
};
}
}