#[derive(Debug, Clone, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(feature = "serde", serde(default))]
pub struct Config {
pub tab_spaces: usize,
pub max_width: usize,
pub blank_lines_upper_bound: usize,
pub collapse_markup_spaces: bool,
pub reorder_import_items: bool,
pub wrap_text: bool,
}
impl Default for Config {
fn default() -> Self {
Self {
tab_spaces: 2,
max_width: 80,
blank_lines_upper_bound: 1,
reorder_import_items: true,
collapse_markup_spaces: false,
wrap_text: false,
}
}
}
impl Config {
pub fn new() -> Self {
Default::default()
}
pub fn with_width(mut self, max_width: usize) -> Self {
self.max_width = max_width;
self
}
pub fn with_tab_spaces(mut self, tab_spaces: usize) -> Self {
self.tab_spaces = tab_spaces;
self
}
pub fn chain_width(&self) -> usize {
const CHAIN_WIDTH_RATIO: f32 = 0.6;
(self.max_width as f32 * CHAIN_WIDTH_RATIO) as usize
}
pub fn with_wrap_text(mut self, wrap_text: bool) -> Self {
self.wrap_text = wrap_text;
self
}
}