From 3415a382a1121920849d5e8a38621d4713c07db4 Mon Sep 17 00:00:00 2001 From: Manos Pitsidianakis Date: Wed, 1 May 2019 13:47:08 +0300 Subject: [PATCH] ui: make StackVec return an Option --- ui/src/conf/accounts.rs | 3 +-- ui/src/types.rs | 9 ++++++--- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/ui/src/conf/accounts.rs b/ui/src/conf/accounts.rs index b38bded1f..1661ca636 100644 --- a/ui/src/conf/accounts.rs +++ b/ui/src/conf/accounts.rs @@ -153,8 +153,7 @@ impl Account { for &c in f.children() { stack.push(c); } - while !stack.is_empty() { - let next = stack.pop(); + while let Some(next) = stack.pop() { folders_order.push(next); for c in ref_folders[&next].children() { stack.push(*c); diff --git a/ui/src/types.rs b/ui/src/types.rs index 2521c3462..ab6de7bf6 100644 --- a/ui/src/types.rs +++ b/ui/src/types.rs @@ -162,14 +162,17 @@ impl StackVec { } self.len += 1; } - pub(crate) fn pop(&mut self) -> T { + pub(crate) fn pop(&mut self) -> Option { + if self.len == 0 { + return None; + } if self.len >= self.array.len() { self.len -= 1; - self.heap_vec.pop().unwrap() + self.heap_vec.pop() } else { let ret = self.array[self.len - 1]; self.len = self.len - 1; - ret + Some(ret) } } pub(crate) fn len(&self) -> usize {