mtl_gpu/library/
function_reflection.rs1use std::ffi::c_void;
4use std::ptr::NonNull;
5
6use mtl_foundation::Referencing;
7use mtl_sys::{msg_send_0, sel};
8
9#[repr(transparent)]
15pub struct FunctionReflection(pub(crate) NonNull<c_void>);
16
17impl FunctionReflection {
18 pub fn alloc() -> Option<Self> {
22 unsafe {
23 let cls = mtl_sys::Class::get("MTLFunctionReflection")?;
24 let ptr: *mut c_void = msg_send_0(cls.as_ptr(), sel!(alloc));
25 Self::from_raw(ptr)
26 }
27 }
28
29 pub fn init(&self) -> Option<Self> {
33 unsafe {
34 let ptr: *mut c_void = msg_send_0(self.as_ptr(), sel!(init));
35 Self::from_raw(ptr)
36 }
37 }
38
39 pub fn new() -> Option<Self> {
41 Self::alloc()?.init()
42 }
43
44 #[inline]
50 pub unsafe fn from_raw(ptr: *mut c_void) -> Option<Self> {
51 NonNull::new(ptr).map(Self)
52 }
53
54 #[inline]
56 pub fn as_raw(&self) -> *mut c_void {
57 self.0.as_ptr()
58 }
59
60 pub fn bindings_raw(&self) -> *mut c_void {
64 unsafe { msg_send_0(self.as_ptr(), sel!(bindings)) }
65 }
66}
67
68impl Clone for FunctionReflection {
69 fn clone(&self) -> Self {
70 unsafe {
71 msg_send_0::<*mut c_void>(self.as_ptr(), sel!(retain));
72 }
73 Self(self.0)
74 }
75}
76
77impl Drop for FunctionReflection {
78 fn drop(&mut self) {
79 unsafe {
80 msg_send_0::<()>(self.as_ptr(), sel!(release));
81 }
82 }
83}
84
85impl Referencing for FunctionReflection {
86 #[inline]
87 fn as_ptr(&self) -> *const c_void {
88 self.0.as_ptr()
89 }
90}
91
92unsafe impl Send for FunctionReflection {}
93unsafe impl Sync for FunctionReflection {}
94
95impl std::fmt::Debug for FunctionReflection {
96 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
97 f.debug_struct("FunctionReflection").finish()
98 }
99}