• 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

68.82
/src/bool/bvec3.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 3-dimensional `bool` vector mask.
7
#[inline(always)]
8
#[must_use]
9
pub const fn bvec3(x: bool, y: bool, z: bool) -> BVec3 {
3✔
10
    BVec3::new(x, y, z)
3✔
11
}
12

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

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

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

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

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

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

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

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

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

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

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

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

103
    #[inline]
104
    #[must_use]
105
    fn into_bool_array(self) -> [bool; 3] {
6✔
106
        [self.x, self.y, self.z]
6✔
107
    }
108

109
    #[inline]
110
    #[must_use]
111
    fn into_u32_array(self) -> [u32; 3] {
6✔
112
        [
113
            MASK[self.x as usize],
6✔
114
            MASK[self.y as usize],
12✔
115
            MASK[self.z as usize],
12✔
116
        ]
117
    }
118
}
119

120
impl Default for BVec3 {
121
    #[inline]
122
    fn default() -> Self {
×
123
        Self::FALSE
3✔
124
    }
125
}
126

127
impl BitAnd for BVec3 {
128
    type Output = Self;
129
    #[inline]
130
    fn bitand(self, rhs: Self) -> Self {
3✔
131
        Self {
132
            x: self.x & rhs.x,
9✔
133
            y: self.y & rhs.y,
9✔
134
            z: self.z & rhs.z,
3✔
135
        }
136
    }
137
}
138

139
impl BitAnd<&Self> for BVec3 {
140
    type Output = Self;
141
    #[inline]
NEW
142
    fn bitand(self, rhs: &Self) -> Self {
×
NEW
143
        self.bitand(*rhs)
×
144
    }
145
}
146

147
impl BitAnd<&BVec3> for &BVec3 {
148
    type Output = BVec3;
149
    #[inline]
NEW
150
    fn bitand(self, rhs: &BVec3) -> BVec3 {
×
NEW
151
        (*self).bitand(*rhs)
×
152
    }
153
}
154

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

163
impl BitAndAssign for BVec3 {
164
    #[inline]
165
    fn bitand_assign(&mut self, rhs: Self) {
3✔
166
        *self = self.bitand(rhs);
3✔
167
    }
168
}
169

170
impl BitAndAssign<&Self> for BVec3 {
171
    #[inline]
NEW
172
    fn bitand_assign(&mut self, rhs: &Self) {
×
NEW
173
        self.bitand_assign(*rhs);
×
174
    }
175
}
176

177
impl BitOr for BVec3 {
178
    type Output = Self;
179
    #[inline]
180
    fn bitor(self, rhs: Self) -> Self {
3✔
181
        Self {
182
            x: self.x | rhs.x,
9✔
183
            y: self.y | rhs.y,
9✔
184
            z: self.z | rhs.z,
3✔
185
        }
186
    }
187
}
188

189
impl BitOr<&Self> for BVec3 {
190
    type Output = Self;
191
    #[inline]
NEW
192
    fn bitor(self, rhs: &Self) -> Self {
×
NEW
193
        self.bitor(*rhs)
×
194
    }
195
}
196

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

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

213
impl BitOrAssign for BVec3 {
214
    #[inline]
215
    fn bitor_assign(&mut self, rhs: Self) {
3✔
216
        *self = self.bitor(rhs);
3✔
217
    }
218
}
219

220
impl BitOrAssign<&Self> for BVec3 {
221
    #[inline]
NEW
222
    fn bitor_assign(&mut self, rhs: &Self) {
×
NEW
223
        self.bitor_assign(*rhs);
×
224
    }
225
}
226

227
impl BitXor for BVec3 {
228
    type Output = Self;
229
    #[inline]
230
    fn bitxor(self, rhs: Self) -> Self {
3✔
231
        Self {
232
            x: self.x ^ rhs.x,
9✔
233
            y: self.y ^ rhs.y,
9✔
234
            z: self.z ^ rhs.z,
3✔
235
        }
236
    }
237
}
238

239
impl BitXor<&Self> for BVec3 {
240
    type Output = Self;
241
    #[inline]
NEW
242
    fn bitxor(self, rhs: &Self) -> Self {
×
NEW
243
        self.bitxor(*rhs)
×
244
    }
245
}
246

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

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

263
impl BitXorAssign for BVec3 {
264
    #[inline]
265
    fn bitxor_assign(&mut self, rhs: Self) {
3✔
266
        *self = self.bitxor(rhs);
3✔
267
    }
268
}
269

270
impl BitXorAssign<&Self> for BVec3 {
271
    #[inline]
NEW
272
    fn bitxor_assign(&mut self, rhs: &Self) {
×
NEW
273
        self.bitxor_assign(*rhs);
×
274
    }
275
}
276

277
impl Not for BVec3 {
278
    type Output = Self;
279
    #[inline]
280
    fn not(self) -> Self {
3✔
281
        Self {
282
            x: !self.x,
6✔
283
            y: !self.y,
6✔
284
            z: !self.z,
3✔
285
        }
286
    }
287
}
288

289
impl Not for &BVec3 {
290
    type Output = BVec3;
291
    #[inline]
NEW
292
    fn not(self) -> BVec3 {
×
NEW
293
        (*self).not()
×
294
    }
295
}
296

297
impl fmt::Debug for BVec3 {
298
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
3✔
299
        let arr = self.into_u32_array();
3✔
300
        write!(
3✔
301
            f,
302
            "{}({:#x}, {:#x}, {:#x})",
303
            stringify!(BVec3),
304
            arr[0],
305
            arr[1],
306
            arr[2]
307
        )
308
    }
309
}
310

311
impl fmt::Display for BVec3 {
312
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
3✔
313
        let arr = self.into_bool_array();
3✔
314
        write!(f, "[{}, {}, {}]", arr[0], arr[1], arr[2])
3✔
315
    }
316
}
317

318
impl From<[bool; 3]> for BVec3 {
319
    #[inline]
320
    fn from(a: [bool; 3]) -> Self {
3✔
321
        Self::from_array(a)
3✔
322
    }
323
}
324

325
impl From<BVec3> for [bool; 3] {
326
    #[inline]
327
    fn from(mask: BVec3) -> Self {
3✔
328
        mask.into_bool_array()
3✔
329
    }
330
}
331

332
impl From<BVec3> for [u32; 3] {
333
    #[inline]
334
    fn from(mask: BVec3) -> Self {
3✔
335
        mask.into_u32_array()
3✔
336
    }
337
}
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