use super::JsonPrettyError;
use super::JsonPrettyOptions;
#[must_use = "store the updated builder or call build to use the formatting options"]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct JsonPrettyOptionsBuilder {
indent_width: usize,
max_indent_levels: Option<usize>,
trailing_newline: bool,
}
impl Default for JsonPrettyOptionsBuilder {
fn default() -> Self {
Self {
indent_width: 2,
max_indent_levels: None,
trailing_newline: false,
}
}
}
impl JsonPrettyOptionsBuilder {
pub fn indent_width(mut self, spaces: usize) -> Self {
self.indent_width = spaces;
self
}
pub fn max_indent_levels(mut self, maximum: Option<usize>) -> Self {
self.max_indent_levels = maximum;
self
}
pub fn trailing_newline(mut self, enabled: bool) -> Self {
self.trailing_newline = enabled;
self
}
pub fn build(self) -> Result<JsonPrettyOptions, JsonPrettyError> {
Ok(JsonPrettyOptions {
indent_width: self.indent_width,
max_indent_levels: self.max_indent_levels,
trailing_newline: self.trailing_newline,
})
}
}