• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

bitshifter / glam-rs / 15533894541

09 Jun 2025 11:54AM UTC coverage: 81.646% (-14.5%) from 96.128%
15533894541

push

github

web-flow
Implement std::ops traits on references (#644)

9962 of 18030 new or added lines in 109 files covered. (55.25%)

39 existing lines in 13 files now uncovered.

43937 of 53814 relevant lines covered (81.65%)

3.02 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

71.0
/src/bool/bvec4.rs
1
// Generated from vec_mask.rs.tera template. Edit the template, not the generated file.
2

3
use core::fmt;
4
use core::ops::*;
5

6
/// Creates a 4-dimensional `bool` vector mask.
7
#[inline(always)]
8
#[must_use]
9
pub const fn bvec4(x: bool, y: bool, z: bool, w: bool) -> BVec4 {
3✔
10
    BVec4::new(x, y, z, w)
3✔
11
}
12

13
/// A 4-dimensional `bool` vector mask.
14
#[derive(Clone, Copy, PartialEq, Eq, Hash)]
15
#[repr(C, align(1))]
16
pub struct BVec4 {
17
    pub x: bool,
18
    pub y: bool,
19
    pub z: bool,
20
    pub w: bool,
21
}
22

23
const MASK: [u32; 2] = [0, 0xff_ff_ff_ff];
24

25
impl BVec4 {
26
    /// All false.
27
    pub const FALSE: Self = Self::splat(false);
28

29
    /// All true.
30
    pub const TRUE: Self = Self::splat(true);
31

32
    /// Creates a new vector mask.
33
    #[inline(always)]
34
    #[must_use]
35
    pub const fn new(x: bool, y: bool, z: bool, w: bool) -> Self {
26✔
36
        Self { x, y, z, w }
37
    }
38

39
    /// Creates a vector mask with all elements set to `v`.
40
    #[inline]
41
    #[must_use]
42
    pub const fn splat(v: bool) -> Self {
3✔
43
        Self::new(v, v, v, v)
3✔
44
    }
45

46
    /// Creates a new vector mask from a bool array.
47
    #[inline]
48
    #[must_use]
49
    pub const fn from_array(a: [bool; 4]) -> Self {
3✔
50
        Self::new(a[0], a[1], a[2], a[3])
6✔
51
    }
52

53
    /// Returns a bitmask with the lowest 4 bits set from the elements of `self`.
54
    ///
55
    /// A true element results in a `1` bit and a false element in a `0` bit.  Element `x` goes
56
    /// into the first lowest bit, element `y` into the second, etc.
57
    #[inline]
58
    #[must_use]
59
    pub fn bitmask(self) -> u32 {
3✔
60
        (self.x as u32) | ((self.y as u32) << 1) | ((self.z as u32) << 2) | ((self.w as u32) << 3)
3✔
61
    }
62

63
    /// Returns true if any of the elements are true, false otherwise.
64
    #[inline]
65
    #[must_use]
66
    pub fn any(self) -> bool {
3✔
67
        self.x || self.y || self.z || self.w
3✔
68
    }
69

70
    /// Returns true if all the elements are true, false otherwise.
71
    #[inline]
72
    #[must_use]
73
    pub fn all(self) -> bool {
17✔
74
        self.x && self.y && self.z && self.w
17✔
75
    }
76

77
    /// Tests the value at `index`.
78
    ///
79
    /// Panics if `index` is greater than 3.
80
    #[inline]
81
    #[must_use]
82
    pub fn test(&self, index: usize) -> bool {
3✔
83
        match index {
3✔
84
            0 => self.x,
3✔
85
            1 => self.y,
3✔
86
            2 => self.z,
3✔
87
            3 => self.w,
3✔
88
            _ => panic!("index out of bounds"),
×
89
        }
90
    }
91

92
    /// Sets the element at `index`.
93
    ///
94
    /// Panics if `index` is greater than 3.
95
    #[inline]
96
    pub fn set(&mut self, index: usize, value: bool) {
3✔
97
        match index {
3✔
98
            0 => self.x = value,
3✔
99
            1 => self.y = value,
3✔
100
            2 => self.z = value,
3✔
101
            3 => self.w = value,
3✔
102
            _ => panic!("index out of bounds"),
×
103
        }
104
    }
105

106
    #[inline]
107
    #[must_use]
108
    fn into_bool_array(self) -> [bool; 4] {
6✔
109
        [self.x, self.y, self.z, self.w]
6✔
110
    }
111

112
    #[inline]
113
    #[must_use]
114
    fn into_u32_array(self) -> [u32; 4] {
6✔
115
        [
116
            MASK[self.x as usize],
6✔
117
            MASK[self.y as usize],
12✔
118
            MASK[self.z as usize],
12✔
119
            MASK[self.w as usize],
12✔
120
        ]
121
    }
122
}
123

124
impl Default for BVec4 {
125
    #[inline]
126
    fn default() -> Self {
×
127
        Self::FALSE
3✔
128
    }
129
}
130

131
impl BitAnd for BVec4 {
132
    type Output = Self;
133
    #[inline]
134
    fn bitand(self, rhs: Self) -> Self {
3✔
135
        Self {
136
            x: self.x & rhs.x,
3✔
137
            y: self.y & rhs.y,
3✔
138
            z: self.z & rhs.z,
3✔
139
            w: self.w & rhs.w,
3✔
140
        }
141
    }
142
}
143

144
impl BitAnd<&Self> for BVec4 {
145
    type Output = Self;
146
    #[inline]
NEW
147
    fn bitand(self, rhs: &Self) -> Self {
×
NEW
148
        self.bitand(*rhs)
×
149
    }
150
}
151

152
impl BitAnd<&BVec4> for &BVec4 {
153
    type Output = BVec4;
154
    #[inline]
NEW
155
    fn bitand(self, rhs: &BVec4) -> BVec4 {
×
NEW
156
        (*self).bitand(*rhs)
×
157
    }
158
}
159

160
impl BitAnd<BVec4> for &BVec4 {
161
    type Output = BVec4;
162
    #[inline]
NEW
163
    fn bitand(self, rhs: BVec4) -> BVec4 {
×
NEW
164
        (*self).bitand(rhs)
×
165
    }
166
}
167

168
impl BitAndAssign for BVec4 {
169
    #[inline]
170
    fn bitand_assign(&mut self, rhs: Self) {
3✔
171
        *self = self.bitand(rhs);
3✔
172
    }
173
}
174

175
impl BitAndAssign<&Self> for BVec4 {
176
    #[inline]
NEW
177
    fn bitand_assign(&mut self, rhs: &Self) {
×
NEW
178
        self.bitand_assign(*rhs);
×
179
    }
180
}
181

182
impl BitOr for BVec4 {
183
    type Output = Self;
184
    #[inline]
185
    fn bitor(self, rhs: Self) -> Self {
3✔
186
        Self {
187
            x: self.x | rhs.x,
3✔
188
            y: self.y | rhs.y,
3✔
189
            z: self.z | rhs.z,
3✔
190
            w: self.w | rhs.w,
3✔
191
        }
192
    }
193
}
194

195
impl BitOr<&Self> for BVec4 {
196
    type Output = Self;
197
    #[inline]
NEW
198
    fn bitor(self, rhs: &Self) -> Self {
×
NEW
199
        self.bitor(*rhs)
×
200
    }
201
}
202

203
impl BitOr<&BVec4> for &BVec4 {
204
    type Output = BVec4;
205
    #[inline]
NEW
206
    fn bitor(self, rhs: &BVec4) -> BVec4 {
×
NEW
207
        (*self).bitor(*rhs)
×
208
    }
209
}
210

211
impl BitOr<BVec4> for &BVec4 {
212
    type Output = BVec4;
213
    #[inline]
NEW
214
    fn bitor(self, rhs: BVec4) -> BVec4 {
×
NEW
215
        (*self).bitor(rhs)
×
216
    }
217
}
218

219
impl BitOrAssign for BVec4 {
220
    #[inline]
221
    fn bitor_assign(&mut self, rhs: Self) {
3✔
222
        *self = self.bitor(rhs);
3✔
223
    }
224
}
225

226
impl BitOrAssign<&Self> for BVec4 {
227
    #[inline]
NEW
228
    fn bitor_assign(&mut self, rhs: &Self) {
×
NEW
229
        self.bitor_assign(*rhs);
×
230
    }
231
}
232

233
impl BitXor for BVec4 {
234
    type Output = Self;
235
    #[inline]
236
    fn bitxor(self, rhs: Self) -> Self {
3✔
237
        Self {
238
            x: self.x ^ rhs.x,
3✔
239
            y: self.y ^ rhs.y,
3✔
240
            z: self.z ^ rhs.z,
3✔
241
            w: self.w ^ rhs.w,
3✔
242
        }
243
    }
244
}
245

246
impl BitXor<&Self> for BVec4 {
247
    type Output = Self;
248
    #[inline]
NEW
249
    fn bitxor(self, rhs: &Self) -> Self {
×
NEW
250
        self.bitxor(*rhs)
×
251
    }
252
}
253

254
impl BitXor<&BVec4> for &BVec4 {
255
    type Output = BVec4;
256
    #[inline]
NEW
257
    fn bitxor(self, rhs: &BVec4) -> BVec4 {
×
NEW
258
        (*self).bitxor(*rhs)
×
259
    }
260
}
261

262
impl BitXor<BVec4> for &BVec4 {
263
    type Output = BVec4;
264
    #[inline]
NEW
265
    fn bitxor(self, rhs: BVec4) -> BVec4 {
×
NEW
266
        (*self).bitxor(rhs)
×
267
    }
268
}
269

270
impl BitXorAssign for BVec4 {
271
    #[inline]
272
    fn bitxor_assign(&mut self, rhs: Self) {
3✔
273
        *self = self.bitxor(rhs);
3✔
274
    }
275
}
276

277
impl BitXorAssign<&Self> for BVec4 {
278
    #[inline]
NEW
279
    fn bitxor_assign(&mut self, rhs: &Self) {
×
NEW
280
        self.bitxor_assign(*rhs);
×
281
    }
282
}
283

284
impl Not for BVec4 {
285
    type Output = Self;
286
    #[inline]
287
    fn not(self) -> Self {
3✔
288
        Self {
289
            x: !self.x,
3✔
290
            y: !self.y,
3✔
291
            z: !self.z,
3✔
292
            w: !self.w,
3✔
293
        }
294
    }
295
}
296

297
impl Not for &BVec4 {
298
    type Output = BVec4;
299
    #[inline]
NEW
300
    fn not(self) -> BVec4 {
×
NEW
301
        (*self).not()
×
302
    }
303
}
304

305
impl fmt::Debug for BVec4 {
306
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
3✔
307
        let arr = self.into_u32_array();
3✔
308
        write!(
3✔
309
            f,
310
            "{}({:#x}, {:#x}, {:#x}, {:#x})",
311
            stringify!(BVec4),
312
            arr[0],
313
            arr[1],
314
            arr[2],
315
            arr[3]
316
        )
317
    }
318
}
319

320
impl fmt::Display for BVec4 {
321
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
3✔
322
        let arr = self.into_bool_array();
3✔
323
        write!(f, "[{}, {}, {}, {}]", arr[0], arr[1], arr[2], arr[3])
3✔
324
    }
325
}
326

327
impl From<[bool; 4]> for BVec4 {
328
    #[inline]
329
    fn from(a: [bool; 4]) -> Self {
3✔
330
        Self::from_array(a)
3✔
331
    }
332
}
333

334
impl From<BVec4> for [bool; 4] {
335
    #[inline]
336
    fn from(mask: BVec4) -> Self {
3✔
337
        mask.into_bool_array()
3✔
338
    }
339
}
340

341
impl From<BVec4> for [u32; 4] {
342
    #[inline]
343
    fn from(mask: BVec4) -> Self {
3✔
344
        mask.into_u32_array()
3✔
345
    }
346
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc