mtl_gpu/argument/
type_info.rs1use std::ffi::c_void;
4use std::ptr::NonNull;
5
6use mtl_foundation::Referencing;
7use mtl_sys::{msg_send_0, sel};
8
9use crate::enums::DataType;
10
11#[repr(transparent)]
15pub struct Type(pub(crate) NonNull<c_void>);
16
17impl Type {
18 #[inline]
24 pub unsafe fn from_raw(ptr: *mut c_void) -> Option<Self> {
25 NonNull::new(ptr).map(Self)
26 }
27
28 #[inline]
30 pub fn as_raw(&self) -> *mut c_void {
31 self.0.as_ptr()
32 }
33
34 #[inline]
38 pub fn data_type(&self) -> DataType {
39 unsafe { msg_send_0(self.as_ptr(), sel!(dataType)) }
40 }
41}
42
43impl Clone for Type {
44 fn clone(&self) -> Self {
45 unsafe {
46 msg_send_0::<*mut c_void>(self.as_ptr(), sel!(retain));
47 }
48 Self(self.0)
49 }
50}
51
52impl Drop for Type {
53 fn drop(&mut self) {
54 unsafe {
55 msg_send_0::<()>(self.as_ptr(), sel!(release));
56 }
57 }
58}
59
60impl Referencing for Type {
61 #[inline]
62 fn as_ptr(&self) -> *const c_void {
63 self.0.as_ptr()
64 }
65}
66
67unsafe impl Send for Type {}
68unsafe impl Sync for Type {}