openxr_sys/
lib.rs

1use std::{convert::TryFrom, fmt};
2
3#[macro_use]
4mod support;
5mod generated;
6pub mod loader;
7pub mod platform;
8
9#[cfg(feature = "mint")]
10mod mint_impls;
11
12// Hand-written bindings for cases which are too few or weird to bother automating
13
14wrapper! {
15    #[derive(Copy, Clone, Eq, PartialEq, Default)]
16    Bool32(u32)
17}
18pub const TRUE: Bool32 = Bool32(1);
19pub const FALSE: Bool32 = Bool32(0);
20impl fmt::Display for Bool32 {
21    fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
22        (*self != FALSE).fmt(fmt)
23    }
24}
25
26impl fmt::Debug for Bool32 {
27    fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
28        (*self != FALSE).fmt(fmt)
29    }
30}
31
32impl From<Bool32> for bool {
33    fn from(x: Bool32) -> Self {
34        x != FALSE
35    }
36}
37
38impl From<bool> for Bool32 {
39    fn from(x: bool) -> Self {
40        Self(x as _)
41    }
42}
43
44#[derive(Copy, Clone, Eq, PartialEq)]
45#[repr(transparent)]
46pub struct Time(i64);
47impl Time {
48    pub fn from_nanos(x: i64) -> Self {
49        Self(x)
50    }
51
52    pub fn as_nanos(self) -> i64 {
53        self.0
54    }
55}
56
57impl fmt::Debug for Time {
58    fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
59        self.0.fmt(fmt)
60    }
61}
62
63impl std::ops::Sub<Time> for Time {
64    type Output = Duration;
65
66    fn sub(self, other: Time) -> Duration {
67        Duration(self.0.wrapping_sub(other.0))
68    }
69}
70
71#[derive(Copy, Clone, Default, Eq, PartialEq)]
72#[repr(transparent)]
73pub struct Duration(i64);
74impl Duration {
75    pub fn from_nanos(x: i64) -> Self {
76        Self(x)
77    }
78
79    pub fn as_nanos(self) -> i64 {
80        self.0
81    }
82}
83
84impl Duration {
85    pub const NONE: Self = Self(0);
86    pub const INFINITE: Self = Self(i64::MAX);
87    pub const MIN_HAPTIC: Self = Self(-1);
88}
89
90impl fmt::Debug for Duration {
91    fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
92        std::time::Duration::from_nanos(self.0 as u64).fmt(fmt)
93    }
94}
95
96impl From<Duration> for std::time::Duration {
97    fn from(x: Duration) -> Self {
98        Self::from_nanos(x.0.unsigned_abs())
99    }
100}
101
102impl TryFrom<std::time::Duration> for Duration {
103    type Error = std::num::TryFromIntError;
104    fn try_from(x: std::time::Duration) -> std::result::Result<Self, Self::Error> {
105        Ok(Self::from_nanos(i64::try_from(x.as_nanos())?))
106    }
107}
108
109wrapper! {
110    #[derive(Debug, Copy, Clone, Default, Eq, PartialEq, Ord, PartialOrd, Hash)]
111    AsyncRequestIdFB(u64)
112}
113
114wrapper! {
115    #[derive(Debug, Copy, Clone, Default, Eq, PartialEq, Ord, PartialOrd, Hash)]
116    Path(u64)
117}
118
119impl Path {
120    pub const NULL: Path = Path(0);
121}
122
123wrapper! {
124    #[derive(Debug, Copy, Clone, Default, Eq, PartialEq, Ord, PartialOrd, Hash)]
125    SystemId(u64)
126}
127
128impl SystemId {
129    pub const NULL: SystemId = SystemId(0);
130}
131
132wrapper! {
133    #[derive(Debug, Copy, Clone, Default, Eq, PartialEq, Ord, PartialOrd, Hash)]
134    ControllerModelKeyMSFT(u64)
135}
136
137impl ControllerModelKeyMSFT {
138    pub const NULL: ControllerModelKeyMSFT = ControllerModelKeyMSFT(0);
139}
140
141wrapper! {
142    #[derive(Debug, Copy, Clone, Default, Eq, PartialEq, Ord, PartialOrd, Hash)]
143    RenderModelKeyFB(u64)
144}
145
146impl RenderModelKeyFB {
147    pub const NULL: RenderModelKeyFB = RenderModelKeyFB(0);
148}
149
150wrapper! {
151    #[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
152    MarkerML(u64)
153}
154
155wrapper! {
156    #[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
157    Version(u64)
158}
159
160impl Version {
161    #[inline]
162    pub const fn new(major: u16, minor: u16, patch: u32) -> Self {
163        Self((major as u64) << 48 | (minor as u64) << 32 | patch as u64)
164    }
165
166    #[inline]
167    pub const fn major(self) -> u16 {
168        (self.0 >> 48) as u16
169    }
170
171    #[inline]
172    pub const fn minor(self) -> u16 {
173        (self.0 >> 32) as u16
174    }
175
176    #[inline]
177    pub const fn patch(self) -> u32 {
178        self.0 as u32
179    }
180}
181
182impl From<(u16, u16, u32)> for Version {
183    fn from(other: (u16, u16, u32)) -> Self {
184        Self::new(other.0, other.1, other.2)
185    }
186}
187
188impl fmt::Display for Version {
189    fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
190        write!(fmt, "{}.{}.{}", self.major(), self.minor(), self.patch())
191    }
192}
193
194impl fmt::Debug for Version {
195    fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
196        write!(fmt, "{}.{}.{}", self.major(), self.minor(), self.patch())
197    }
198}
199
200pub const FREQUENCY_UNSPECIFIED: f32 = 0.0;
201
202impl Quaternionf {
203    pub const IDENTITY: Quaternionf = Quaternionf {
204        x: 0.0,
205        y: 0.0,
206        z: 0.0,
207        w: 1.0,
208    };
209}
210
211impl Posef {
212    pub const IDENTITY: Posef = Posef {
213        orientation: Quaternionf::IDENTITY,
214        position: Vector3f {
215            x: 0.0,
216            y: 0.0,
217            z: 0.0,
218        },
219    };
220}
221
222pub const HAND_JOINT_COUNT_EXT: u32 = 26;
223
224pub use generated::*;
225
226impl<T> std::ops::Index<HandJointEXT> for [T] {
227    type Output = T;
228    fn index(&self, joint: HandJointEXT) -> &T {
229        &self[joint.into_raw() as usize]
230    }
231}
232
233impl<T> std::ops::IndexMut<HandJointEXT> for [T] {
234    fn index_mut(&mut self, joint: HandJointEXT) -> &mut T {
235        &mut self[joint.into_raw() as usize]
236    }
237}
238
239// Magic Leap
240#[derive(Copy, Clone, Debug)]
241#[repr(C)]
242pub struct MLCoordinateFrameUID {
243    pub data: [u64; 2],
244}
245
246// Hacky constants originating from enums
247pub const EYE_POSITION_COUNT_FB: usize = 2;
248pub const MAX_VIRTUAL_KEYBOARD_COMMIT_TEXT_SIZE_META: usize = 3992;
249
250pub type SpaceUserIdFB = u64;
251pub type FutureEXT = u64;