use std::{ffi::CStr, fmt, marker::PhantomData, os::raw::c_char, ptr::NonNull};
#[repr(C)]
#[derive(Copy, Clone)]
pub struct PropertyAttribute<'a> {
name: NonNull<c_char>,
value: NonNull<c_char>,
_marker: PhantomData<&'a CStr>,
}
impl fmt::Debug for PropertyAttribute<'_> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.debug_struct("PropertyAttribute")
.field("name", &self.name())
.field("value", &self.value())
.finish()
}
}
impl PartialEq for PropertyAttribute<'_> {
#[inline]
fn eq(&self, other: &Self) -> bool {
self.name() == other.name() && self.value() == other.value()
}
}
impl Eq for PropertyAttribute<'_> {}
impl<'a> PropertyAttribute<'a> {
#[inline]
pub fn name(&self) -> &'a CStr {
unsafe { CStr::from_ptr(self.name_ptr()) }
}
#[inline]
pub fn name_ptr(&self) -> *const c_char {
self.name.as_ptr()
}
#[inline]
pub fn value(&self) -> &'a CStr {
unsafe { CStr::from_ptr(self.value_ptr()) }
}
#[inline]
pub fn value_ptr(&self) -> *const c_char {
self.value.as_ptr()
}
}