summaryrefslogtreecommitdiffstats
path: root/vendor/tinyvec/gen-array-impls.sh
blob: 234f771bccbc093c8723ad0574c35ba31d7b13a3 (plain)
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/usr/bin/env bash

gen_impl() {
	local len=$1
	cat <<-END
		impl<T: Default> Array for [T; $len] {
		  type Item = T;
		  const CAPACITY: usize = $len;

		  #[inline(always)]
		  #[must_use]
		  fn as_slice(&self) -> &[T] {
		    &*self
		  }

		  #[inline(always)]
		  #[must_use]
		  fn as_slice_mut(&mut self) -> &mut [T] {
		    &mut *self
		  }

		  #[inline(always)]
		  fn default() -> Self {
		    [
		$(for ((i = 0; i < $len; i += 6))
		do
			echo -n '     '
			for ((j = 0; j < 6 && j + i < $len; j++))
			do
				echo -n ' T::default(),'
			done
			echo
		done)
		    ]
		  }
		}

		END
}

cat <<-END
	// Generated file, to regenerate run
	//     ./gen-array-impls.sh > src/array/generated_impl.rs
	// from the repo root

	use super::Array;

	$(for ((i = 0; i <= 33; i++)); do gen_impl $i; done)

	$(for ((i = 64; i <= 4096; i *= 2)); do gen_impl $i; done)
END

# vim: noet