Fix unsafe unwrap in rewind

master
trivernis 4 years ago
parent e316d063f8
commit 5712ec2320

@ -1,6 +1,6 @@
[package] [package]
name = "charred" name = "charred"
version = "0.2.1" version = "0.2.2"
authors = ["trivernis <trivernis@protonmail.com>"] authors = ["trivernis <trivernis@protonmail.com>"]
edition = "2018" edition = "2018"
license-file = "LICENSE" license-file = "LICENSE"

@ -91,8 +91,10 @@ impl CharTapeMachine {
/// Rewinds to a given index /// Rewinds to a given index
#[inline] #[inline]
pub fn rewind(&mut self, index: usize) { pub fn rewind(&mut self, index: usize) {
self.index = index; if self.text.len() > index {
self.current_char = *self.text.get(index).unwrap(); self.index = index;
self.current_char = *self.text.get(index).unwrap();
}
} }
/// Rewinds to a given index and returns an error /// Rewinds to a given index and returns an error

Loading…
Cancel
Save