Skip to main content

mtl_gpu/enums/
io.rs

1//! IO command buffer and queue enumerations.
2//!
3//! Corresponds to `Metal/MTLIOCommandBuffer.hpp`, `Metal/MTLIOCommandQueue.hpp`,
4//! and `Metal/MTLIOCompressor.hpp`.
5
6use mtl_foundation::Integer;
7
8/// IO command buffer status.
9///
10/// C++ equivalent: `MTL::IOStatus`
11#[repr(transparent)]
12#[derive(Copy, Clone, Debug, Default, PartialEq, Eq, Hash)]
13pub struct IOStatus(pub Integer);
14
15impl IOStatus {
16    pub const PENDING: Self = Self(0);
17    pub const CANCELLED: Self = Self(1);
18    pub const ERROR: Self = Self(2);
19    pub const COMPLETE: Self = Self(3);
20}
21
22/// IO command queue priority.
23///
24/// C++ equivalent: `MTL::IOPriority`
25#[repr(transparent)]
26#[derive(Copy, Clone, Debug, Default, PartialEq, Eq, Hash)]
27pub struct IOPriority(pub Integer);
28
29impl IOPriority {
30    pub const HIGH: Self = Self(0);
31    pub const NORMAL: Self = Self(1);
32    pub const LOW: Self = Self(2);
33}
34
35/// IO command queue type.
36///
37/// C++ equivalent: `MTL::IOCommandQueueType`
38#[repr(transparent)]
39#[derive(Copy, Clone, Debug, Default, PartialEq, Eq, Hash)]
40pub struct IOCommandQueueType(pub Integer);
41
42impl IOCommandQueueType {
43    pub const CONCURRENT: Self = Self(0);
44    pub const SERIAL: Self = Self(1);
45}
46
47/// IO error codes.
48///
49/// C++ equivalent: `MTL::IOError`
50#[repr(transparent)]
51#[derive(Copy, Clone, Debug, Default, PartialEq, Eq, Hash)]
52pub struct IOError(pub Integer);
53
54impl IOError {
55    pub const URL_INVALID: Self = Self(1);
56    pub const INTERNAL: Self = Self(2);
57}
58
59/// IO compression status.
60///
61/// C++ equivalent: `MTL::IOCompressionStatus`
62#[repr(transparent)]
63#[derive(Copy, Clone, Debug, Default, PartialEq, Eq, Hash)]
64pub struct IOCompressionStatus(pub Integer);
65
66impl IOCompressionStatus {
67    pub const COMPLETE: Self = Self(0);
68    pub const ERROR: Self = Self(1);
69}
70
71// Note: IOCompressionMethod is defined in device.rs as it's part of MTLDevice.hpp
72
73#[cfg(test)]
74mod tests {
75    use super::*;
76
77    #[test]
78    fn test_io_status_values() {
79        assert_eq!(IOStatus::PENDING.0, 0);
80        assert_eq!(IOStatus::CANCELLED.0, 1);
81        assert_eq!(IOStatus::ERROR.0, 2);
82        assert_eq!(IOStatus::COMPLETE.0, 3);
83    }
84
85    #[test]
86    fn test_io_priority_values() {
87        assert_eq!(IOPriority::HIGH.0, 0);
88        assert_eq!(IOPriority::NORMAL.0, 1);
89        assert_eq!(IOPriority::LOW.0, 2);
90    }
91
92    #[test]
93    fn test_io_command_queue_type_values() {
94        assert_eq!(IOCommandQueueType::CONCURRENT.0, 0);
95        assert_eq!(IOCommandQueueType::SERIAL.0, 1);
96    }
97
98    #[test]
99    fn test_io_error_values() {
100        assert_eq!(IOError::URL_INVALID.0, 1);
101        assert_eq!(IOError::INTERNAL.0, 2);
102    }
103
104    #[test]
105    fn test_io_compression_status_values() {
106        assert_eq!(IOCompressionStatus::COMPLETE.0, 0);
107        assert_eq!(IOCompressionStatus::ERROR.0, 1);
108    }
109}