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
const BUFFER_SIZE: usize = 8192;

pub struct ConstStr {
	data: [u8; BUFFER_SIZE],
	len: usize,
}

impl ConstStr {
	pub const fn empty() -> ConstStr {
		ConstStr {
			data: [0u8; BUFFER_SIZE],
			len: 0,
		}
	}

	pub const fn append_str(mut self, s: &str) -> Self {
		let b = s.as_bytes();
		let mut index = 0;
		while index < b.len() {
			self.data[self.len] = b[index];
			self.len += 1;
			index += 1;
		}

		self
	}

	pub const fn as_str(&self) -> &str {
		let mut data: &[u8] = &self.data;
		let mut n = data.len() - self.len;
		while n > 0 {
			n -= 1;
			match data.split_last() {
				Some((_, rest)) => data = rest,
				None => panic!(),
			}
		}
		unsafe { std::str::from_utf8_unchecked(data) }
	}
}