Skip to content

Commit ed7801a

Browse files
committed
spirv-std: modernize const code
1 parent 3daedd4 commit ed7801a

File tree

2 files changed

+3
-11
lines changed

2 files changed

+3
-11
lines changed

crates/spirv-std/src/scalar.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//! Traits related to scalars.
22
3-
use crate::vector::{VectorOrScalar, create_dim};
3+
use crate::vector::VectorOrScalar;
44
use core::num::NonZeroUsize;
55

66
/// Abstract trait representing a SPIR-V scalar type.
@@ -21,7 +21,7 @@ macro_rules! impl_scalar {
2121
$(
2222
unsafe impl VectorOrScalar for $ty {
2323
type Scalar = Self;
24-
const DIM: NonZeroUsize = create_dim(1);
24+
const DIM: NonZeroUsize = NonZeroUsize::new(1).unwrap();
2525
}
2626
unsafe impl Scalar for $ty {}
2727
)+

crates/spirv-std/src/vector.rs

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,6 @@ pub unsafe trait VectorOrScalar: Copy + Default + Send + Sync + 'static {
1616
const DIM: NonZeroUsize;
1717
}
1818

19-
/// replace with `NonZeroUsize::new(n).unwrap()` once `unwrap()` is const stabilized
20-
pub(crate) const fn create_dim(n: usize) -> NonZeroUsize {
21-
match NonZeroUsize::new(n) {
22-
None => panic!("dim must not be 0"),
23-
Some(n) => n,
24-
}
25-
}
26-
2719
/// Abstract trait representing a SPIR-V vector type.
2820
///
2921
/// To implement this trait, your struct must be marked with:
@@ -71,7 +63,7 @@ macro_rules! impl_vector {
7163
$($(
7264
unsafe impl VectorOrScalar for $vec {
7365
type Scalar = $scalar;
74-
const DIM: NonZeroUsize = create_dim($dim);
66+
const DIM: NonZeroUsize = NonZeroUsize::new($dim).unwrap();
7567
}
7668
unsafe impl Vector<$scalar, $dim> for $vec {}
7769
)+)+

0 commit comments

Comments
 (0)