1#[derive(Copy, Clone, Eq, Hash, PartialEq, PartialOrd, Ord)]
5pub struct Buffer<const SIZE: usize> {
6 pub(crate) length: u8,
8
9 pub(crate) bytes: [u8; SIZE],
11}
12
13impl<const SIZE: usize> Buffer<SIZE> {
14 pub const fn as_bytes(&self) -> &[u8] {
16 self.bytes.split_at(self.length as usize).0
17 }
18
19 pub const fn len(&self) -> usize {
21 self.length as usize
22 }
23
24 pub const fn eq(&self, rhs: &Self) -> bool {
26 if self.length != rhs.length {
27 return false;
28 }
29
30 let mut i = 0usize;
31
32 while i < self.len() {
33 if self.bytes[i] != rhs.bytes[i] {
34 return false;
35 }
36
37 #[allow(clippy::arithmetic_side_effects)]
39 {
40 i += 1;
41 }
42 }
43
44 true
45 }
46}
47
48impl<const SIZE: usize> AsRef<[u8]> for Buffer<SIZE> {
49 fn as_ref(&self) -> &[u8] {
50 self.as_bytes()
51 }
52}