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
pub struct TinyAsciiString {
buf: [u8; 512],
}
impl TinyAsciiString {
pub fn new() -> Self {
Self { buf: [0_u8; 512] }
}
pub unsafe fn as_str(&self) -> &str {
crate::str::from_utf8_unchecked(&self.buf)
}
}
impl crate::fmt::Write for TinyAsciiString {
fn write_str(&mut self, s: &str) -> Result<(), crate::fmt::Error> {
for (idx, b) in s.bytes().enumerate() {
if let Some(v) = self.buf.get_mut(idx) {
*v = b;
} else {
return Err(crate::fmt::Error);
}
}
Ok(())
}
}
macro_rules! tiny_str {
($($t:tt)*) => (
{
use crate::fmt::Write;
let mut s: crate::macros::TinyAsciiString
= crate::macros::TinyAsciiString::new();
write!(&mut s, $($t)*).unwrap();
s
}
)
}