tree_formatter/
format.rs

1pub struct ContextFormat<'a> {
2  pub(super) empty: &'a str,
3  pub(super) level: &'a str,
4}
5
6impl<'a> ContextFormat<'a> {
7  const LEVEL_CONTEXT: &'static str = "│   ";
8  const EMPTY_CONTEXT: &'static str = "    ";
9
10  pub fn new(empty_context: &'a str, level_context: &'a str) -> Self {
11    ContextFormat { empty: empty_context, level: level_context }
12  }
13
14  #[inline(always)]
15  pub(super) fn context(&self, is_last: bool) -> &'a str {
16    match is_last {
17      true => self.empty,
18      false => self.level,
19    }
20  }
21
22  pub const fn default() -> Self {
23    Self { empty: Self::EMPTY_CONTEXT, level: Self::LEVEL_CONTEXT }
24  }
25}
26
27pub struct ItemPrefixFormat<'a> {
28  item: &'a str,
29  last: &'a str,
30}
31
32impl<'a> ItemPrefixFormat<'a> {
33  const DEFAULT_ITEM_PREFIX: &'static str = "├── ";
34  const DEFAULT_LAST_ITEM_PREFIX: &'static str = "└── ";
35
36  pub fn new(item_prefix: &'a str, last_item_prefix: &'a str) -> Self {
37    Self { item: item_prefix, last: last_item_prefix }
38  }
39
40  #[inline(always)]
41  pub(super) fn prefix(&self, is_last: bool) -> &'_ str {
42    match is_last {
43      true => self.last,
44      false => self.item,
45    }
46  }
47
48  pub const fn default() -> Self {
49    Self {
50      item: Self::DEFAULT_ITEM_PREFIX,
51      last: Self::DEFAULT_LAST_ITEM_PREFIX,
52    }
53  }
54}