use crate::HashProvider;
#[derive(Debug, Clone, Copy)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct WrapConfig {
pub line_width: usize,
pub inline_structs: bool,
pub inline_lists: bool,
}
impl WrapConfig {
pub fn line_width(mut self, line_width: usize) -> Self {
self.line_width = line_width;
self
}
pub fn inline_structs(mut self, inline_structs: bool) -> Self {
self.inline_structs = inline_structs;
self
}
pub fn inline_lists(mut self, inline_lists: bool) -> Self {
self.inline_lists = inline_lists;
self
}
}
impl Default for WrapConfig {
fn default() -> Self {
Self {
line_width: 120,
inline_structs: false,
inline_lists: true,
}
}
}
#[derive(Debug, Clone, Copy)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct PrintConfig<Hashes: HashProvider> {
pub indent_size: usize,
pub wrap: WrapConfig,
#[cfg_attr(feature = "serde", serde(skip, default))]
pub hashes: Hashes,
}
impl Default for PrintConfig<()> {
fn default() -> Self {
Self {
indent_size: 4,
wrap: Default::default(),
hashes: (),
}
}
}
impl<H: HashProvider> PrintConfig<H> {
pub fn wrap(mut self, wrap: WrapConfig) -> Self {
self.wrap = wrap;
self
}
pub fn indent_size(mut self, indent_size: usize) -> Self {
self.indent_size = indent_size;
self
}
pub fn with_hashes<H2: HashProvider>(self, hashes: H2) -> PrintConfig<H2> {
PrintConfig {
indent_size: self.indent_size,
wrap: self.wrap,
hashes,
}
}
pub fn take_hashes(self) -> (PrintConfig<()>, H) {
(
PrintConfig {
indent_size: self.indent_size,
wrap: self.wrap,
hashes: (),
},
self.hashes,
)
}
}