1use std::fmt;
2
3#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
4#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
5#[cfg_attr(feature = "serde", serde(rename_all = "kebab-case"))]
6pub struct RenderOpts {
7 pub indent_width: usize,
9 pub ident_count: usize,
11}
12
13impl Default for RenderOpts {
14 fn default() -> Self {
15 Self {
16 indent_width: 2,
17 ident_count: 0,
18 }
19 }
20}
21
22impl RenderOpts {
23 pub fn indent(&self) -> Self {
27 Self {
28 indent_width: self.indent_width,
29 ident_count: self.ident_count + 1,
30 }
31 }
32
33 pub fn outdent(&self) -> Self {
37 Self {
38 indent_width: self.indent_width,
39 ident_count: self.ident_count - 1,
40 }
41 }
42
43 pub fn spaces(&self) -> String {
45 let space_count = self.indent_width * self.ident_count;
46 " ".repeat(space_count)
47 }
48}
49
50pub trait Render {
51 fn render(&self, f: &mut fmt::Formatter<'_>, options: &RenderOpts) -> fmt::Result;
52}