use std::{ffi::CStr, fmt, os::raw::c_char};
mod attribute;
pub use attribute::*;
#[cfg(feature = "malloced")]
use malloced::Malloced;
#[repr(C)]
pub struct Property {
data: [u8; 0],
}
impl fmt::Debug for Property {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.debug_struct("Property")
.field("name", &self.name())
.field("attributes", &self.attributes())
.finish()
}
}
impl Property {
#[inline]
#[doc(alias = "property_getName")]
pub fn name(&self) -> &CStr {
unsafe { CStr::from_ptr(self.name_ptr()) }
}
#[inline]
#[doc(alias = "property_getName")]
pub fn name_ptr(&self) -> *const c_char {
extern "C" {
fn property_getName(property: &Property) -> *const c_char;
}
unsafe { property_getName(self) }
}
#[inline]
#[doc(alias = "property_getAttributes")]
pub fn attributes(&self) -> &CStr {
unsafe { CStr::from_ptr(self.attributes_ptr()) }
}
#[inline]
#[doc(alias = "property_getAttributes")]
pub fn attributes_ptr(&self) -> *const c_char {
extern "C" {
fn property_getAttributes(property: &Property) -> *const c_char;
}
unsafe { property_getAttributes(self) }
}
#[cfg(feature = "malloced")]
#[inline]
#[doc(alias = "property_copyAttributeList")]
pub fn copy_attributes_list<'a>(&'a self) -> Option<Malloced<[PropertyAttribute<'a>]>> {
use std::{mem::MaybeUninit, os::raw::c_uint};
extern "C" {
fn property_copyAttributeList<'a>(
property: &'a Property,
out_count: *mut c_uint,
) -> *mut PropertyAttribute<'a>;
}
let mut len = MaybeUninit::<c_uint>::uninit();
unsafe {
let data = property_copyAttributeList(self, len.as_mut_ptr());
if data.is_null() {
None
} else {
Some(Malloced::slice_from_raw_parts(
data,
len.assume_init() as usize,
))
}
}
}
}