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
//! Traits related to scalars.

use crate::vector::{create_dim, VectorOrScalar};
use core::num::NonZeroUsize;

/// Abstract trait representing a SPIR-V scalar type.
///
/// # Safety
/// Implementing this trait on non-scalar types breaks assumptions of other unsafe code, and should
/// not be done.
pub unsafe trait Scalar:
    VectorOrScalar<Scalar = Self> + Copy + Default + crate::sealed::Sealed
{
}

macro_rules! impl_scalar {
    ($($ty:ty),+) => {
        $(
            unsafe impl VectorOrScalar for $ty {
                type Scalar = Self;
                const DIM: NonZeroUsize = create_dim(1);
            }
            unsafe impl Scalar for $ty {}
        )+
    };
}

impl_scalar!(bool, f32, f64, u8, u16, u32, u64, i8, i16, i32, i64);