mirror of
https://github.com/YGGverse/Yoda.git
synced 2026-04-02 01:25:27 +00:00
fix borrow panic
This commit is contained in:
parent
cefdcdc859
commit
d3d6e859f0
1 changed files with 13 additions and 8 deletions
|
|
@ -77,22 +77,27 @@ impl History {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn back(&self, follow_to_index: bool) -> Option<GString> {
|
pub fn back(&self, follow_to_index: bool) -> Option<GString> {
|
||||||
if let Some(index) = self.index.borrow().as_ref() {
|
let index = self.index.borrow().clone(); // keep outside as borrow
|
||||||
if let Some(memory) = self.memory.borrow().get(index - 1) {
|
if let Some(usize) = index {
|
||||||
if follow_to_index {
|
// Make sure value positive to prevent panic
|
||||||
self.index.replace(Some(index - 1));
|
if usize > 0 {
|
||||||
|
if let Some(memory) = self.memory.borrow().get(usize - 1) {
|
||||||
|
if follow_to_index {
|
||||||
|
self.index.replace(Some(usize - 1));
|
||||||
|
}
|
||||||
|
return Some(memory.request.clone());
|
||||||
}
|
}
|
||||||
return Some(memory.request.clone());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn forward(&self, follow_to_index: bool) -> Option<GString> {
|
pub fn forward(&self, follow_to_index: bool) -> Option<GString> {
|
||||||
if let Some(index) = self.index.borrow().as_ref() {
|
let index = self.index.borrow().clone(); // keep outside as borrow
|
||||||
if let Some(memory) = self.memory.borrow().get(index + 1) {
|
if let Some(usize) = index {
|
||||||
|
if let Some(memory) = self.memory.borrow().get(usize + 1) {
|
||||||
if follow_to_index {
|
if follow_to_index {
|
||||||
self.index.replace(Some(index + 1));
|
self.index.replace(Some(usize + 1));
|
||||||
}
|
}
|
||||||
return Some(memory.request.clone());
|
return Some(memory.request.clone());
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue