use crate::level::Level;
#[derive(Copy, Clone, Eq, PartialEq, Debug)]
pub struct Config<T = fn(usize) -> char>
where
T: Fn(usize) -> char,
{
pub tabwidth: usize,
pub skip: usize,
pub depthmap: T,
pub level: Level,
}
impl Config {
#[must_use]
pub fn new() -> Self {
Self::default()
}
}
impl<T> Config<T>
where
T: Fn(usize) -> char,
{
#[must_use]
pub fn with_depthmap<U: Fn(usize) -> char>(self, depthmap: U) -> Config<U> {
Config {
tabwidth: self.tabwidth,
skip: self.skip,
depthmap,
level: self.level,
}
}
#[must_use]
pub fn with_skip(self, skip: usize) -> Self {
Self { skip, ..self }
}
#[must_use]
pub fn with_level(self, level: Level) -> Self {
Self { level, ..self }
}
}
impl Default for Config {
fn default() -> Self {
Self {
tabwidth: 2,
skip: 2,
depthmap: default_depthmap,
level: Level::Info,
}
}
}
const fn default_depthmap(depth: usize) -> char {
const DEPTHMAP: [char; 4] = ['|', '¦', '┆', '┊'];
DEPTHMAP[depth % DEPTHMAP.len()]
}