From 7b87d7185fc93b92606fcacbc1ea3d7a8e02cb20 Mon Sep 17 00:00:00 2001 From: Rose Hogenson Date: Sat, 11 May 2024 22:15:46 -0700 Subject: Use strings for errors. --- bytecode/src/heap.rs | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) (limited to 'bytecode/src/heap.rs') diff --git a/bytecode/src/heap.rs b/bytecode/src/heap.rs index 970db7d..d956e2e 100644 --- a/bytecode/src/heap.rs +++ b/bytecode/src/heap.rs @@ -1,5 +1,4 @@ use crate::value::Value; -use std::error::Error; pub const NUM_LOCALS: usize = 256; @@ -108,9 +107,9 @@ impl Heap { self.buf.resize(new_size * 2, 0); } - pub fn alloc(&mut self, size: i64) -> Result> { + pub fn alloc(&mut self, size: i64) -> Result { if size <= 0 { - return Err(Box::from("alloc of zero size")); + return Err(String::from("alloc of zero size")); } let usize = usize::try_from(size).expect("32 bits in 2024 LULW"); self.collect_garbage(); @@ -125,16 +124,16 @@ impl Heap { Ok(p) } - pub fn peek(&self, p: usize) -> Result> { + pub fn peek(&self, p: usize) -> Result { if p >= self.buf.len() { - return Err(Box::from("peek: out of range")); + return Err(String::from("peek: out of range")); } Ok(Value(self.buf[p])) } - pub fn poke(&mut self, p: usize, val: Value) -> Result<(), Box> { + pub fn poke(&mut self, p: usize, val: Value) -> Result<(), String> { if p >= self.buf.len() { - return Err(Box::from("poke: out of range")); + return Err(String::from("poke: out of range")); } self.buf[p] = val.repr(); Ok(()) -- cgit v1.3.1