Use .last / .last_mut in stack

This commit is contained in:
Sergey Pepyakin 2018-06-20 19:37:39 +03:00
parent 26ff4c5982
commit 6647bc4090
1 changed files with 2 additions and 4 deletions

View File

@ -43,16 +43,14 @@ impl<T> StackWithLimit<T> where T: Clone {
}
pub fn top(&self) -> Result<&T, Error> {
let len = self.values.len();
self.values
.get(len - 1)
.last()
.ok_or_else(|| Error("non-empty stack expected".into()))
}
pub fn top_mut(&mut self) -> Result<&mut T, Error> {
let len = self.values.len();
self.values
.get_mut(len - 1)
.last_mut()
.ok_or_else(|| Error("non-empty stack expected".into()))
}