Skip to content

Commit

Permalink
stack: Fix pop_two_operands, don't pop one and lost it
Browse files Browse the repository at this point in the history
  • Loading branch information
Kerollmops committed Jan 6, 2017
1 parent b258144 commit 1b4558d
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,10 @@ pub use stack::Stack;
/// Removes the last two elements from a stack and return them,
/// or `None` if there is not enough element.
pub fn pop_two_operands<T>(stack: &mut Stack<T>) -> Option<(T, T)> {
match (stack.pop(), stack.pop()) {
(Some(a), Some(b)) => Some((b, a)),
_ => None,
if stack.len() >= 2 {
let (a, b) = (stack.pop().unwrap(), stack.pop().unwrap());
Some((b, a))
} else {
None
}
}

0 comments on commit 1b4558d

Please sign in to comment.