Use .last / .last_mut in stack
This commit is contained in:
parent
26ff4c5982
commit
6647bc4090
|
@ -43,16 +43,14 @@ impl<T> StackWithLimit<T> where T: Clone {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn top(&self) -> Result<&T, Error> {
|
pub fn top(&self) -> Result<&T, Error> {
|
||||||
let len = self.values.len();
|
|
||||||
self.values
|
self.values
|
||||||
.get(len - 1)
|
.last()
|
||||||
.ok_or_else(|| Error("non-empty stack expected".into()))
|
.ok_or_else(|| Error("non-empty stack expected".into()))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn top_mut(&mut self) -> Result<&mut T, Error> {
|
pub fn top_mut(&mut self) -> Result<&mut T, Error> {
|
||||||
let len = self.values.len();
|
|
||||||
self.values
|
self.values
|
||||||
.get_mut(len - 1)
|
.last_mut()
|
||||||
.ok_or_else(|| Error("non-empty stack expected".into()))
|
.ok_or_else(|| Error("non-empty stack expected".into()))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue