use std::fmt;
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(feature = "serde", serde(rename_all = "kebab-case"))]
pub struct RenderOpts {
pub indent_width: usize,
pub ident_count: usize,
}
impl Default for RenderOpts {
fn default() -> Self {
Self {
indent_width: 2,
ident_count: 0,
}
}
}
impl RenderOpts {
pub fn indent(&self) -> Self {
Self {
indent_width: self.indent_width,
ident_count: self.ident_count + 1,
}
}
pub fn outdent(&self) -> Self {
Self {
indent_width: self.indent_width,
ident_count: self.ident_count - 1,
}
}
pub fn spaces(&self) -> String {
let space_count = self.indent_width * self.ident_count;
" ".repeat(space_count)
}
}
pub trait Render {
fn render(&self, f: &mut fmt::Formatter<'_>, options: &RenderOpts) -> fmt::Result;
}