use super::BOOL;
use std::{
ffi::CStr,
fmt,
os::raw::{c_char, c_void},
ptr::NonNull,
};
#[macro_use]
mod macros;
#[repr(transparent)]
#[derive(Copy, Clone)]
pub struct SEL(NonNull<c_void>);
unsafe impl Send for SEL {}
unsafe impl Sync for SEL {}
impl PartialEq for SEL {
#[inline]
fn eq(&self, other: &Self) -> bool {
extern "C" {
fn sel_isEqual(lhs: SEL, rhs: SEL) -> BOOL;
}
unsafe { sel_isEqual(*self, *other) != 0 }
}
}
impl Eq for SEL {}
impl fmt::Debug for SEL {
#[inline]
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
self.name().fmt(f)
}
}
impl SEL {
#[inline]
pub unsafe fn register(name: *const c_char) -> Self {
sel_registerName(name)
}
#[inline]
pub fn name(self) -> &'static CStr {
unsafe { CStr::from_ptr(sel_getName(self)) }
}
}
extern "C" {
fn sel_registerName(name: *const c_char) -> SEL;
fn sel_getName(sel: SEL) -> *const c_char;
}