anyreader_walker/
utils.rs1use crate::EntryDetails;
2use std::path::{Path, PathBuf};
3
4#[derive(Debug, Default)]
24pub struct ArchiveStack {
25 stack: smallvec::SmallVec<[EntryDetails; 6]>,
26}
27
28impl ArchiveStack {
29 pub fn new() -> Self {
30 Self::default()
31 }
32
33 pub fn last_entry(&self) -> Option<&EntryDetails> {
34 self.stack.last()
35 }
36
37 pub fn push_details(&mut self, details: EntryDetails) {
38 self.stack.push(details);
39 }
40
41 pub fn pop_details(&mut self) -> Option<EntryDetails> {
42 self.stack.pop()
43 }
44
45 pub fn current_depth(&self) -> usize {
46 self.stack.len()
47 }
48
49 pub fn is_empty(&self) -> bool {
50 self.stack.is_empty()
51 }
52
53 pub fn full_path(&self) -> PathBuf {
54 PathBuf::from_iter(self.stack.iter().map(|d| d.path.as_path()))
55 }
56
57 pub fn root_path(&self) -> &Path {
58 self.stack
59 .first()
60 .map(|d| d.path.as_path())
61 .unwrap_or(Path::new(""))
62 }
63
64 pub fn nested_path(&self) -> PathBuf {
65 PathBuf::from_iter(self.nested_path_iter())
66 }
67
68 pub fn nested_path_iter(&self) -> impl Iterator<Item = &Path> {
69 self.stack.iter().skip(1).map(|d| d.path.as_path())
70 }
71}