Skip to content

Commit eb73a89

Browse files
committed
Simplify sample_type_impls!.
- The first `@single_rule` rule just repeats the contents of the subsequent four `@single_rule` rules. So just call them. - The subsequent four `@single_rule` rules don't need to handle repetition, because the first rule handles that.
1 parent 34f1030 commit eb73a89

File tree

1 file changed

+13
-41
lines changed

1 file changed

+13
-41
lines changed

crates/spirv-std/src/image/params.rs

Lines changed: 13 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -20,74 +20,46 @@ pub trait SampleType<const FORMAT: u32, const COMPONENTS: u32>: Scalar {
2020
/// Helper macro to implement `SampleType` of various formats for various scalar types.
2121
macro_rules! sample_type_impls {
2222
($($fmt:ident : $n:tt*$s:ty => ($v1:ty, $v2:ty, $v3:ty, $v4:ty)),+ $(,)?) => {
23-
$(sample_type_impls!{@single_rule, $fmt : $n*$s => ($v1,$v2,$v3,$v4)})+
23+
$(sample_type_impls! { @single_rule, $fmt : $n*$s => ($v1,$v2,$v3,$v4) })+
2424
};
2525
(@single_rule, $fmt:ident : n*$s:ty => ($v1:ty, $v2:ty, $v3:ty, $v4:ty)) => {
26+
sample_type_impls! { @single_rule, $fmt: 1*$s => ($v1, $v2, $v3, $v4) }
27+
sample_type_impls! { @single_rule, $fmt: 2*$s => ($v1, $v2, $v3, $v4) }
28+
sample_type_impls! { @single_rule, $fmt: 3*$s => ($v1, $v2, $v3, $v4) }
29+
sample_type_impls! { @single_rule, $fmt: 4*$s => ($v1, $v2, $v3, $v4) }
30+
};
31+
(@single_rule, $fmt:ident : 1*$s:ty => ($v1:ty, $v2:ty, $v3:ty, $v4:ty)) => {
2632
impl SampleType<{ ImageFormat::$fmt as u32 }, 1> for $s {
2733
type SampleResult = $v1;
2834
type Vec2 = $v2;
2935
type Vec3 = $v3;
3036
type Vec4 = $v4;
3137
}
38+
};
39+
(@single_rule, $fmt:ident : 2*$s:ty => ($v1:ty, $v2:ty, $v3:ty, $v4:ty)) => {
3240
impl SampleType<{ ImageFormat::$fmt as u32 }, 2> for $s {
3341
type SampleResult = $v2;
3442
type Vec2 = $v2;
3543
type Vec3 = $v3;
3644
type Vec4 = $v4;
3745
}
46+
};
47+
(@single_rule, $fmt:ident : 3*$s:ty => ($v1:ty, $v2:ty, $v3:ty, $v4:ty)) => {
3848
impl SampleType<{ ImageFormat::$fmt as u32 }, 3> for $s {
3949
type SampleResult = $v3;
4050
type Vec2 = $v2;
4151
type Vec3 = $v3;
4252
type Vec4 = $v4;
4353
}
54+
};
55+
(@single_rule, $fmt:ident : 4*$s:ty => ($v1:ty, $v2:ty, $v3:ty, $v4:ty)) => {
4456
impl SampleType<{ ImageFormat::$fmt as u32 }, 4> for $s {
4557
type SampleResult = $v4;
4658
type Vec2 = $v2;
4759
type Vec3 = $v3;
4860
type Vec4 = $v4;
4961
}
5062
};
51-
(@single_rule, $($fmt:ident : 1*$s:ty => ($v1:ty, $v2:ty, $v3:ty, $v4:ty)),+ $(,)?) => {
52-
$(
53-
impl SampleType<{ ImageFormat::$fmt as u32 }, 1> for $s {
54-
type SampleResult = $v1;
55-
type Vec2 = $v2;
56-
type Vec3 = $v3;
57-
type Vec4 = $v4;
58-
}
59-
)+
60-
};
61-
(@single_rule, $($fmt:ident : 2*$s:ty => ($v1:ty, $v2:ty, $v3:ty, $v4:ty)),+ $(,)?) => {
62-
$(
63-
impl SampleType<{ ImageFormat::$fmt as u32 }, 2> for $s {
64-
type SampleResult = $v2;
65-
type Vec2 = $v2;
66-
type Vec3 = $v3;
67-
type Vec4 = $v4;
68-
}
69-
)+
70-
};
71-
(@single_rule, $($fmt:ident : 3*$s:ty => ($v1:ty, $v2:ty, $v3:ty, $v4:ty)),+ $(,)?) => {
72-
$(
73-
impl SampleType<{ ImageFormat::$fmt as u32 }, 3> for $s {
74-
type SampleResult = $v3;
75-
type Vec2 = $v2;
76-
type Vec3 = $v3;
77-
type Vec4 = $v4;
78-
}
79-
)+
80-
};
81-
(@single_rule, $($fmt:ident : 4*$s:ty => ($v1:ty, $v2:ty, $v3:ty, $v4:ty)),+ $(,)?) => {
82-
$(
83-
impl SampleType<{ ImageFormat::$fmt as u32 }, 4> for $s {
84-
type SampleResult = $v4;
85-
type Vec2 = $v2;
86-
type Vec3 = $v3;
87-
type Vec4 = $v4;
88-
}
89-
)+
90-
};
9163
}
9264

9365
sample_type_impls! {

0 commit comments

Comments
 (0)