use crate::config::{items::ItemsLayout, user_opts::ExpressionsOptions};
use serde::{Deserialize, Serialize};
#[derive(Debug, Copy, Clone)]
pub struct Expressions {
pub expr_brace_style: ExprBraceStyle,
pub trailing_semicolon: bool,
pub space_before_colon: bool,
pub space_after_colon: bool,
pub type_combinator_layout: TypeCombinatorLayout,
pub spaces_around_ranges: bool,
pub match_block_trailing_comma: bool,
pub match_arm_leading_pipe: MatchArmLeadingPipe,
pub force_multiline_blocks: bool,
pub fn_args_layout: ItemsLayout,
pub fn_single_line: bool,
}
impl Default for Expressions {
fn default() -> Self {
Self {
expr_brace_style: ExprBraceStyle::AlwaysSameLine,
trailing_semicolon: true,
space_before_colon: false,
space_after_colon: false,
type_combinator_layout: TypeCombinatorLayout::Wide,
spaces_around_ranges: false,
match_block_trailing_comma: false,
match_arm_leading_pipe: MatchArmLeadingPipe::Never,
force_multiline_blocks: false,
fn_args_layout: ItemsLayout::Tall,
fn_single_line: false,
}
}
}
impl Expressions {
pub fn from_opts(opts: &ExpressionsOptions) -> Self {
let default = Self::default();
Self {
expr_brace_style: opts.expr_brace_style.unwrap_or(default.expr_brace_style),
trailing_semicolon: opts
.trailing_semicolon
.unwrap_or(default.trailing_semicolon),
space_before_colon: opts
.space_before_colon
.unwrap_or(default.space_before_colon),
space_after_colon: opts.space_after_colon.unwrap_or(default.space_after_colon),
type_combinator_layout: opts
.type_combinator_layout
.unwrap_or(default.type_combinator_layout),
spaces_around_ranges: opts
.spaces_around_ranges
.unwrap_or(default.spaces_around_ranges),
match_block_trailing_comma: opts
.match_block_trailing_comma
.unwrap_or(default.match_block_trailing_comma),
match_arm_leading_pipe: opts
.match_arm_leading_pipe
.unwrap_or(default.match_arm_leading_pipe),
force_multiline_blocks: opts
.force_multiline_blocks
.unwrap_or(default.force_multiline_blocks),
fn_args_layout: opts.fn_args_layout.unwrap_or(default.fn_args_layout),
fn_single_line: opts.fn_single_line.unwrap_or(default.fn_single_line),
}
}
}
#[allow(clippy::enum_variant_names)]
#[derive(Serialize, Deserialize, Debug, Copy, Clone)]
pub enum ExprBraceStyle {
AlwaysSameLine,
ClosingNextLine,
AlwaysNextLine,
}
#[derive(Serialize, Deserialize, Debug, Copy, Clone)]
pub enum TypeCombinatorLayout {
Compressed,
Wide,
}
#[derive(Serialize, Deserialize, Debug, Copy, Clone)]
pub enum MatchArmLeadingPipe {
Always,
Never,
Preserve,
}