1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
use std::convert::TryFrom;
use std::fmt;

#[macro_use]
mod support;
mod generated;
pub mod platform;

#[cfg(feature = "mint")]
mod mint_impls;

// Hand-written bindings for cases which are too few or weird to bother automating

wrapper! {
    #[derive(Copy, Clone, Eq, PartialEq, Default)]
    Bool32(u32)
}
pub const TRUE: Bool32 = Bool32(1);
pub const FALSE: Bool32 = Bool32(0);
impl fmt::Display for Bool32 {
    fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
        (*self != FALSE).fmt(fmt)
    }
}

impl fmt::Debug for Bool32 {
    fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
        (*self != FALSE).fmt(fmt)
    }
}

impl From<Bool32> for bool {
    fn from(x: Bool32) -> Self {
        x != FALSE
    }
}

impl From<bool> for Bool32 {
    fn from(x: bool) -> Self {
        Self(x as _)
    }
}

#[derive(Copy, Clone, Eq, PartialEq)]
#[repr(transparent)]
pub struct Time(i64);
impl Time {
    pub fn from_nanos(x: i64) -> Self {
        Self(x)
    }

    pub fn as_nanos(self) -> i64 {
        self.0
    }
}

impl fmt::Debug for Time {
    fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
        self.0.fmt(fmt)
    }
}

impl std::ops::Sub<Time> for Time {
    type Output = Duration;

    fn sub(self, other: Time) -> Duration {
        Duration(self.0.wrapping_sub(other.0))
    }
}

#[derive(Copy, Clone, Eq, PartialEq)]
#[repr(transparent)]
pub struct Duration(i64);
impl Duration {
    pub fn from_nanos(x: i64) -> Self {
        Self(x)
    }

    pub fn as_nanos(self) -> i64 {
        self.0
    }
}

impl Duration {
    pub const NONE: Self = Self(0);
    pub const INFINITE: Self = Self(i64::max_value());
    pub const MIN_HAPTIC: Self = Self(-1);
}

impl fmt::Debug for Duration {
    fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
        std::time::Duration::from_nanos(self.0 as u64).fmt(fmt)
    }
}

impl From<Duration> for std::time::Duration {
    fn from(x: Duration) -> Self {
        Self::from_nanos(x.0.abs() as u64)
    }
}

impl TryFrom<std::time::Duration> for Duration {
    type Error = std::num::TryFromIntError;
    fn try_from(x: std::time::Duration) -> std::result::Result<Self, Self::Error> {
        Ok(Self::from_nanos(i64::try_from(x.as_nanos())?))
    }
}

wrapper! {
    #[derive(Debug, Copy, Clone, Default, Eq, PartialEq, Ord, PartialOrd, Hash)]
    Path(u64)
}

impl Path {
    pub const NULL: Path = Path(0);
}

wrapper! {
    #[derive(Debug, Copy, Clone, Default, Eq, PartialEq, Ord, PartialOrd, Hash)]
    SystemId(u64)
}

impl SystemId {
    pub const NULL: SystemId = SystemId(0);
}

wrapper! {
    #[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
    Version(u64)
}

impl Version {
    #[inline]
    pub const fn new(major: u16, minor: u16, patch: u32) -> Self {
        Self((major as u64) << 48 | (minor as u64) << 32 | patch as u64)
    }

    #[inline]
    pub const fn major(self) -> u16 {
        (self.0 >> 48) as u16
    }

    #[inline]
    pub const fn minor(self) -> u16 {
        (self.0 >> 32) as u16
    }

    #[inline]
    pub const fn patch(self) -> u32 {
        self.0 as u32
    }
}

impl From<(u16, u16, u32)> for Version {
    fn from(other: (u16, u16, u32)) -> Self {
        Self::new(other.0, other.1, other.2)
    }
}

impl fmt::Display for Version {
    fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
        write!(fmt, "{}.{}.{}", self.major(), self.minor(), self.patch())
    }
}

pub const FREQUENCY_UNSPECIFIED: f32 = 0.0;

impl Quaternionf {
    pub const IDENTITY: Quaternionf = Quaternionf {
        x: 0.0,
        y: 0.0,
        z: 0.0,
        w: 1.0,
    };
}

impl Posef {
    pub const IDENTITY: Posef = Posef {
        orientation: Quaternionf::IDENTITY,
        position: Vector3f {
            x: 0.0,
            y: 0.0,
            z: 0.0,
        },
    };
}

pub const HAND_JOINT_COUNT_EXT: u32 = 26;

pub use generated::*;

impl<T> std::ops::Index<HandJointEXT> for [T] {
    type Output = T;
    fn index(&self, joint: HandJointEXT) -> &T {
        &self[joint.into_raw() as usize]
    }
}

impl<T> std::ops::IndexMut<HandJointEXT> for [T] {
    fn index_mut(&mut self, joint: HandJointEXT) -> &mut T {
        &mut self[joint.into_raw() as usize]
    }
}