blob: dae1024978333958139fd0ca677a53af655c50db (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
pub struct ReadOnlyTextBuffer {
chars: Vec<u8>,
pointer: usize,
}
impl ReadOnlyTextBuffer {
pub fn from_text(text: &str) -> Self {
Self {
chars: text.bytes().collect(),
pointer: 0,
}
}
pub fn read_byte(&mut self) -> u8 {
let option = self.chars.get(self.pointer);
self.pointer += 1;
*option.unwrap_or(&0)
}
pub fn reset_pointer(&mut self) {
self.pointer = 0;
}
}
|