spirv_std/
scalar.rs

1//! Traits related to scalars.
2
3use crate::vector::{VectorOrScalar, create_dim};
4use core::num::NonZeroUsize;
5
6/// Abstract trait representing a SPIR-V scalar type.
7///
8/// # Safety
9/// Implementing this trait on non-scalar types breaks assumptions of other unsafe code, and should
10/// not be done.
11pub unsafe trait Scalar: VectorOrScalar<Scalar = Self> + crate::sealed::Sealed {}
12
13macro_rules! impl_scalar {
14    ($($ty:ty),+) => {
15        $(
16            unsafe impl VectorOrScalar for $ty {
17                type Scalar = Self;
18                const DIM: NonZeroUsize = create_dim(1);
19            }
20            unsafe impl Scalar for $ty {}
21        )+
22    };
23}
24
25impl_scalar!(bool, f32, f64, u8, u16, u32, u64, i8, i16, i32, i64);