Radish alpha
r
Radicle terminal user interface
Radicle
Git (anonymous pull)
Log in to clone via SSH
lib: Introduce a stack for page identifiers
Erik Kundt committed 2 years ago
commit 8f3e907abafe4cc3868049752efe54737ee54640
parent b38d6e576512576f2becb6b2b4d80f9337aa50c8
1 file changed +30 -0
modified src/lib.rs
@@ -67,3 +67,33 @@ where
        state.end()
    }
}
+

+
/// A 'PageStack' for applications. Page identifier can be pushed to and
+
/// popped from the stack.
+
#[derive(Clone, Default, Debug)]
+
pub struct PageStack<T> {
+
    pages: Vec<T>,
+
}
+

+
impl<T> PageStack<T> {
+
    pub fn new(pages: Vec<T>) -> Self {
+
        Self { pages }
+
    }
+

+
    pub fn push(&mut self, page: T) {
+
        self.pages.push(page);
+
    }
+

+
    pub fn pop(&mut self) -> Option<T> {
+
        self.pages.pop()
+
    }
+

+
    pub fn peek(&self) -> Result<&T> {
+
        match self.pages.last() {
+
            Some(page) => Ok(page),
+
            None => Err(anyhow::anyhow!(
+
                "Could not peek active page. Page stack is empty."
+
            )),
+
        }
+
    }
+
}