#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct StringHandle(NonNull<__itt_string_handle >);
impl<'a> From<&'a str> for StringHandle
{
#[inline(always)]
fn from(name: &'a str) -> Self
{
Self::new(name)
}
}
impl StringHandle
{
#[cfg(unix)]
#[inline(always)]
pub fn new(name: &str) -> Self
{
let name = CString::new(name).unwrap();
let inner = unsafe { __itt_string_handle_create(name.as_ptr()) };
assert!(!inner.is_null());
StringHandle(unsafe { NonNull::new_unchecked(inner)})
}
#[cfg(windows)]
#[inline(always)]
pub fn new(name: &str) -> Result<Self, ()>
{
let name = CString::new(name).unwrap();
let inner = unsafe { __itt_string_handle_createA(name.as_ptr()) };
if inner.is_null()
{
Err(())
}
else
{
Ok(StringHandle(unsafe { NonNull::new_unchecked(inner)}))
}
}
#[inline(always)]
fn mutable_pointer(self) -> *mut __itt_string_handle
{
self.0.as_ptr()
}
}