use crate::{
config::{lists::ListTactic, user_opts::ItemsOptions},
constants::{DEFAULT_BLANK_LINES_LOWER_BOUND, DEFAULT_BLANK_LINES_UPPER_BOUND},
};
use serde::{Deserialize, Serialize};
#[derive(Debug, Copy, Clone)]
pub struct Items {
pub item_brace_style: ItemBraceStyle,
pub blank_lines_upper_bound: usize,
pub blank_lines_lower_bound: usize,
pub empty_item_single_line: bool,
}
impl Default for Items {
fn default() -> Self {
Self {
item_brace_style: ItemBraceStyle::SameLineWhere,
blank_lines_upper_bound: DEFAULT_BLANK_LINES_UPPER_BOUND,
blank_lines_lower_bound: DEFAULT_BLANK_LINES_LOWER_BOUND,
empty_item_single_line: true,
}
}
}
impl Items {
pub fn from_opts(opts: &ItemsOptions) -> Self {
let default = Self::default();
Self {
item_brace_style: opts.item_brace_style.unwrap_or(default.item_brace_style),
blank_lines_upper_bound: opts
.blank_lines_upper_bound
.unwrap_or(default.blank_lines_upper_bound),
blank_lines_lower_bound: opts
.blank_lines_lower_bound
.unwrap_or(default.blank_lines_lower_bound),
empty_item_single_line: opts
.empty_item_single_line
.unwrap_or(default.empty_item_single_line),
}
}
}
#[derive(Serialize, Deserialize, Debug, Copy, Clone)]
pub enum ItemsLayout {
Compressed,
Tall,
Vertical,
}
impl ItemsLayout {
pub fn to_list_tactic(self, len: usize) -> ListTactic {
match self {
ItemsLayout::Compressed => ListTactic::Mixed,
ItemsLayout::Tall => ListTactic::HorizontalVertical,
ItemsLayout::Vertical if len == 1 => ListTactic::Horizontal,
ItemsLayout::Vertical => ListTactic::Vertical,
}
}
}
#[derive(Serialize, Deserialize, Debug, Copy, Clone)]
pub enum ItemBraceStyle {
AlwaysNextLine,
PreferSameLine,
SameLineWhere,
}