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
//! Static helpers called from generated code
use std::fmt;

macro_rules! wrapper {
    {$(#[$meta: meta])* $ident:ident($ty:ty)} => {
        $(#[$meta])* #[repr(transparent)]
        pub struct $ident($ty);
        impl $ident {
            pub fn from_raw(x: $ty) -> Self { Self(x) }
            pub fn into_raw(self) -> $ty { self.0 }
        }
    }
}

macro_rules! bitmask {
    ($name:ident) => {
        impl $name {
            pub const EMPTY: Self = Self(0);

            #[inline]
            pub fn from_raw(x: u64) -> Self {
                Self(x)
            }

            #[inline]
            pub fn into_raw(self) -> u64 {
                self.0
            }

            #[inline]
            pub fn is_empty(self) -> bool {
                self == $name::EMPTY
            }

            #[inline]
            pub fn intersects(self, other: $name) -> bool {
                self & other != $name::EMPTY
            }

            /// Returns whether `other` is a subset of `self`
            #[inline]
            pub fn contains(self, other: $name) -> bool {
                self & other == other
            }
        }

        impl Default for $name {
            fn default() -> Self {
                Self::EMPTY
            }
        }

        impl std::ops::BitOr for $name {
            type Output = $name;

            #[inline]
            fn bitor(self, rhs: $name) -> $name {
                $name(self.0 | rhs.0)
            }
        }

        impl std::ops::BitOrAssign for $name {
            #[inline]
            fn bitor_assign(&mut self, rhs: $name) {
                *self = *self | rhs
            }
        }

        impl std::ops::BitAnd for $name {
            type Output = $name;

            #[inline]
            fn bitand(self, rhs: $name) -> $name {
                $name(self.0 & rhs.0)
            }
        }

        impl std::ops::BitAndAssign for $name {
            #[inline]
            fn bitand_assign(&mut self, rhs: $name) {
                *self = *self & rhs
            }
        }

        impl std::ops::BitXor for $name {
            type Output = $name;

            #[inline]
            fn bitxor(self, rhs: $name) -> $name {
                $name(self.0 ^ rhs.0)
            }
        }

        impl std::ops::BitXorAssign for $name {
            #[inline]
            fn bitxor_assign(&mut self, rhs: $name) {
                *self = *self ^ rhs
            }
        }

        impl std::ops::Not for $name {
            type Output = $name;

            #[inline]
            fn not(self) -> $name {
                Self(!self.0)
            }
        }
    };
}

macro_rules! handle {
    ($name:ident) => {
        impl $name {
            pub const NULL: Self = Self(0);
            #[inline]
            pub fn from_raw(x: u64) -> Self {
                Self(x)
            }
            #[inline]
            pub fn into_raw(self) -> u64 {
                self.0
            }
        }
        impl Default for $name {
            fn default() -> Self {
                Self::NULL
            }
        }
    };
}

pub fn fmt_enum(f: &mut fmt::Formatter, value: i32, name: Option<&'static str>) -> fmt::Result {
    match name {
        Some(x) => f.pad(x),
        None => <i32 as fmt::Debug>::fmt(&value, f),
    }
}

#[cfg(feature = "ash")]
pub use ash::vk;