d1e137d0a747c8fc4fe586ba960923675ab179c0
[vector-math.git] / src / scalar.rs
1 use crate::traits::{Context, Make};
2
3 #[derive(Clone, Copy, PartialEq, Eq, Hash, Debug, Default)]
4 pub struct Scalar;
5
6 macro_rules! impl_context {
7 (
8 impl Context for Scalar {
9 $(type $name:ident = $ty:ty;)*
10 #[vec]
11 $(type $vec_name:ident = $vec_ty:ty;)*
12 }
13 ) => {
14 impl Context for Scalar {
15 $(type $name = $ty;)*
16 $(type $vec_name = $vec_ty;)*
17 }
18
19 $(
20 impl Make for $ty {
21 type Prim = $ty;
22 type Context = Scalar;
23 fn ctx(self) -> Self::Context {
24 Scalar
25 }
26 fn make(_ctx: Self::Context, v: Self::Prim) -> Self {
27 v
28 }
29 }
30 )*
31 };
32 }
33
34 impl_context! {
35 impl Context for Scalar {
36 type Bool = bool;
37
38 type U8 = u8;
39
40 type I8 = i8;
41
42 type U16 = u16;
43
44 type I16 = i16;
45
46 type F16 = crate::f16::F16;
47
48 type U32 = u32;
49
50 type I32 = i32;
51
52 type F32 = f32;
53
54 type U64 = u64;
55
56 type I64 = i64;
57
58 type F64 = f64;
59
60 #[vec]
61
62 type VecBool = bool;
63
64 type VecU8 = u8;
65
66 type VecI8 = i8;
67
68 type VecU16 = u16;
69
70 type VecI16 = i16;
71
72 type VecF16 = crate::f16::F16;
73
74 type VecU32 = u32;
75
76 type VecI32 = i32;
77
78 type VecF32 = f32;
79
80 type VecU64 = u64;
81
82 type VecI64 = i64;
83
84 type VecF64 = f64;
85 }
86 }