diff options
author | Ben Bridle <ben@derelict.engineering> | 2025-03-25 12:46:49 +1300 |
---|---|---|
committer | Ben Bridle <ben@derelict.engineering> | 2025-03-25 12:48:49 +1300 |
commit | ab84ad75629b0a4124221023ca91411d2cd62a32 (patch) | |
tree | 0c333f06bec5270084aaec71cf173c798420207b /src/types/read_buffer.rs | |
parent | 07ae3438917fd854a46924a410f6890cd0651f1b (diff) | |
download | bedrock-pc-ab84ad75629b0a4124221023ca91411d2cd62a32.zip |
Restructure program
This commit also includes changes to devices according to the latest
devices specification, in particular the math and system devices.
Diffstat (limited to 'src/types/read_buffer.rs')
-rw-r--r-- | src/types/read_buffer.rs | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/src/types/read_buffer.rs b/src/types/read_buffer.rs new file mode 100644 index 0000000..7128048 --- /dev/null +++ b/src/types/read_buffer.rs @@ -0,0 +1,34 @@ +pub struct ReadBuffer { + pub bytes: Vec<u8>, + pub pointer: usize, +} + +impl ReadBuffer { + pub fn new() -> Self { + Self { + bytes: Vec::new(), + pointer: 0, + } + } + + pub fn from_str(text: &str) -> Self { + Self { + bytes: text.bytes().collect(), + pointer: 0, + } + } + + pub fn set_str(&mut self, text: &str) { + self.bytes = text.bytes().collect(); + self.pointer = 0; + } + + pub fn read(&mut self) -> u8 { + let pointer = self.pointer; + self.pointer += 1; + match self.bytes.get(pointer) { + Some(byte) => *byte, + None => 0, + } + } +} |