1use core::slice::{Chunks, Iter, IterMut};
2use core::{borrow, cmp, default, fmt, hash, ops, slice};
3
4#[derive(Copy, Clone)]
12pub struct Tile(pub [u8; 64]);
13
14impl fmt::Debug for Tile {
15 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
16 fmt::Debug::fmt(&self.0[..], f)
17 }
18}
19
20impl<'a> IntoIterator for &'a Tile {
21 type Item = &'a u8;
22 type IntoIter = Iter<'a, u8>;
23
24 fn into_iter(self) -> Iter<'a, u8> {
25 self.0.iter()
26 }
27}
28
29impl<'a> IntoIterator for &'a mut Tile {
30 type Item = &'a mut u8;
31 type IntoIter = IterMut<'a, u8>;
32
33 fn into_iter(self) -> IterMut<'a, u8> {
34 self.0.iter_mut()
35 }
36}
37
38impl cmp::PartialEq for Tile {
39 fn eq(&self, rhs: &Self) -> bool {
40 cmp::PartialEq::eq(&self.0[..], &rhs.0[..])
41 }
42}
43
44impl cmp::Eq for Tile {}
45
46impl hash::Hash for Tile {
47 fn hash<H: hash::Hasher>(&self, state: &mut H) {
48 hash::Hash::hash(&self.0[..], state)
49 }
50}
51
52impl AsRef<[u8]> for Tile {
53 #[inline]
54 fn as_ref(&self) -> &[u8] {
55 &self.0[..]
56 }
57}
58
59impl AsMut<[u8]> for Tile {
60 #[inline]
61 fn as_mut(&mut self) -> &mut [u8] {
62 &mut self.0[..]
63 }
64}
65
66impl borrow::Borrow<[u8]> for Tile {
67 fn borrow(&self) -> &[u8] {
68 &self.0
69 }
70}
71
72impl borrow::BorrowMut<[u8]> for Tile {
73 fn borrow_mut(&mut self) -> &mut [u8] {
74 &mut self.0
75 }
76}
77
78impl default::Default for Tile {
79 fn default() -> Self {
80 Tile([0; 64])
81 }
82}
83
84impl ops::Index<usize> for Tile {
85 type Output = u8;
86 #[inline]
87 fn index(&self, i: usize) -> &u8 {
88 &self.0[i]
89 }
90}
91
92impl Tile {
93 pub fn iter(&self) -> Iter<u8> {
94 slice::SliceExt::iter(&self.0[..])
95 }
96
97 pub fn chunks(&self, n: usize) -> Chunks<u8> {
98 self.0.chunks(n)
99 }
100}