mtl_gpu/argument/
array_type.rs1use std::ffi::c_void;
4use std::ptr::NonNull;
5
6use mtl_foundation::{Referencing, UInteger};
7use mtl_sys::{msg_send_0, sel};
8
9use crate::enums::DataType;
10
11use super::{PointerType, StructType, TensorReferenceType, TextureReferenceType};
12
13#[repr(transparent)]
17pub struct ArrayType(pub(crate) NonNull<c_void>);
18
19impl ArrayType {
20 #[inline]
26 pub unsafe fn from_raw(ptr: *mut c_void) -> Option<Self> {
27 NonNull::new(ptr).map(Self)
28 }
29
30 #[inline]
32 pub fn as_raw(&self) -> *mut c_void {
33 self.0.as_ptr()
34 }
35
36 #[inline]
40 pub fn data_type(&self) -> DataType {
41 unsafe { msg_send_0(self.as_ptr(), sel!(dataType)) }
42 }
43
44 #[inline]
48 pub fn argument_index_stride(&self) -> UInteger {
49 unsafe { msg_send_0(self.as_ptr(), sel!(argumentIndexStride)) }
50 }
51
52 #[inline]
56 pub fn array_length(&self) -> UInteger {
57 unsafe { msg_send_0(self.as_ptr(), sel!(arrayLength)) }
58 }
59
60 #[inline]
64 pub fn element_type(&self) -> DataType {
65 unsafe { msg_send_0(self.as_ptr(), sel!(elementType)) }
66 }
67
68 #[inline]
72 pub fn stride(&self) -> UInteger {
73 unsafe { msg_send_0(self.as_ptr(), sel!(stride)) }
74 }
75
76 pub fn element_array_type(&self) -> Option<ArrayType> {
80 unsafe {
81 let ptr: *mut c_void = msg_send_0(self.as_ptr(), sel!(elementArrayType));
82 ArrayType::from_raw(ptr)
83 }
84 }
85
86 pub fn element_pointer_type(&self) -> Option<PointerType> {
90 unsafe {
91 let ptr: *mut c_void = msg_send_0(self.as_ptr(), sel!(elementPointerType));
92 PointerType::from_raw(ptr)
93 }
94 }
95
96 pub fn element_struct_type(&self) -> Option<StructType> {
100 unsafe {
101 let ptr: *mut c_void = msg_send_0(self.as_ptr(), sel!(elementStructType));
102 StructType::from_raw(ptr)
103 }
104 }
105
106 pub fn element_texture_reference_type(&self) -> Option<TextureReferenceType> {
110 unsafe {
111 let ptr: *mut c_void = msg_send_0(self.as_ptr(), sel!(elementTextureReferenceType));
112 TextureReferenceType::from_raw(ptr)
113 }
114 }
115
116 pub fn element_tensor_reference_type(&self) -> Option<TensorReferenceType> {
120 unsafe {
121 let ptr: *mut c_void = msg_send_0(self.as_ptr(), sel!(elementTensorReferenceType));
122 TensorReferenceType::from_raw(ptr)
123 }
124 }
125}
126
127impl Clone for ArrayType {
128 fn clone(&self) -> Self {
129 unsafe {
130 msg_send_0::<*mut c_void>(self.as_ptr(), sel!(retain));
131 }
132 Self(self.0)
133 }
134}
135
136impl Drop for ArrayType {
137 fn drop(&mut self) {
138 unsafe {
139 msg_send_0::<()>(self.as_ptr(), sel!(release));
140 }
141 }
142}
143
144impl Referencing for ArrayType {
145 #[inline]
146 fn as_ptr(&self) -> *const c_void {
147 self.0.as_ptr()
148 }
149}
150
151unsafe impl Send for ArrayType {}
152unsafe impl Sync for ArrayType {}