use super::Class;
use crate::core::Arc;
use std::{cell::UnsafeCell, fmt, marker::PhantomData, panic::RefUnwindSafe, ptr::NonNull};
#[allow(non_camel_case_types)]
pub type id<'data> = Arc<ObjCObject<'data>>;
#[repr(C)]
pub struct ObjCObject<'data> {
_marker: PhantomData<&'data ()>,
_data: UnsafeCell<[u8; 0]>,
}
impl crate::core::ObjectType for ObjCObject<'_> {
#[inline]
#[doc(alias = "objc_retain")]
fn retain(obj: &Self) -> Arc<Self> {
extern "C" {
fn objc_retain<'data>(obj: &ObjCObject<'data>) -> Arc<ObjCObject<'data>>;
}
unsafe { objc_retain(obj) }
}
#[inline]
#[doc(alias = "objc_release")]
unsafe fn release(obj: NonNull<Self>) {
extern "C" {
fn objc_release(obj: NonNull<ObjCObject<'_>>);
}
objc_release(obj);
}
}
impl<'data> super::ObjectType<'data> for ObjCObject<'data> {
#[inline]
fn class<'s>(&'s self) -> &'s Class
where
'data: 's,
{
unsafe { _msg_send_strict_cached![self, class] }
}
}
impl<'data> AsRef<ObjCObject<'data>> for ObjCObject<'data> {
#[inline]
fn as_ref(&self) -> &Self {
self
}
}
unsafe impl Sync for ObjCObject<'_> {}
unsafe impl Send for ObjCObject<'_> {}
impl RefUnwindSafe for ObjCObject<'_> {}
impl fmt::Debug for ObjCObject<'_> {
#[inline]
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
(self as *const Self).fmt(f)
}
}