pub trait Layout: Sized + 'static {
fn v_open() -> Self;
fn v_close() -> Self;
fn v_sep() -> Self;
}
#[derive(Clone, Copy, Debug, Default, Eq, PartialEq)]
pub enum LayoutMode {
#[default]
Lazy,
Eager,
}
#[derive(Clone)]
pub struct LayoutConfig<T: Layout> {
pub is_opener: fn(&T) -> bool,
pub is_explicit_open: Option<fn(&T) -> bool>,
pub is_explicit_close: Option<fn(&T) -> bool>,
pub mode: LayoutMode,
pub tab_width: usize,
_marker: std::marker::PhantomData<fn() -> T>,
}
impl<T: Layout> LayoutConfig<T> {
#[must_use]
pub fn new(is_opener: fn(&T) -> bool) -> Self {
Self {
is_opener,
is_explicit_open: None,
is_explicit_close: None,
mode: LayoutMode::Lazy,
tab_width: 1,
_marker: std::marker::PhantomData,
}
}
#[must_use]
pub fn with_explicit_braces(mut self, open: fn(&T) -> bool, close: fn(&T) -> bool) -> Self {
self.is_explicit_open = Some(open);
self.is_explicit_close = Some(close);
self
}
#[must_use]
pub const fn with_mode(mut self, mode: LayoutMode) -> Self {
self.mode = mode;
self
}
#[must_use]
pub const fn with_tab_width(mut self, tab_width: usize) -> Self {
self.tab_width = tab_width;
self
}
}
impl<T: Layout> std::fmt::Debug for LayoutConfig<T> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("LayoutConfig")
.field("mode", &self.mode)
.field("tab_width", &self.tab_width)
.field("has_explicit_open", &self.is_explicit_open.is_some())
.field("has_explicit_close", &self.is_explicit_close.is_some())
.finish_non_exhaustive()
}
}