#![deny(missing_docs)]
use {std::collections::HashMap, std::collections::HashSet, std::hash::Hash, std::hash::Hasher};
#[derive(Clone, Debug)]
pub enum PathOption {
TrailingCommas(bool),
CollapseContainersOfOne(bool),
SortArrayItems(bool),
PropertyNameOrder(Vec<&'static str>),
}
impl PartialEq for PathOption {
fn eq(&self, other: &Self) -> bool {
use PathOption::*;
match (self, other) {
(&TrailingCommas(..), &TrailingCommas(..)) => true,
(&CollapseContainersOfOne(..), &CollapseContainersOfOne(..)) => true,
(&SortArrayItems(..), &SortArrayItems(..)) => true,
(&PropertyNameOrder(..), &PropertyNameOrder(..)) => true,
_ => false,
}
}
}
impl Eq for PathOption {}
impl Hash for PathOption {
fn hash<H: Hasher>(&self, state: &mut H) {
use PathOption::*;
state.write_u32(match self {
TrailingCommas(..) => 1,
CollapseContainersOfOne(..) => 2,
SortArrayItems(..) => 3,
PropertyNameOrder(..) => 4,
});
state.finish();
}
}
#[derive(Clone, Debug)]
pub struct FormatOptions {
pub indent_by: usize,
pub trailing_commas: bool,
pub collapse_containers_of_one: bool,
pub sort_array_items: bool,
pub options_by_path: HashMap<&'static str, HashSet<PathOption>>,
}
impl Default for FormatOptions {
fn default() -> Self {
FormatOptions {
indent_by: 4,
trailing_commas: true,
collapse_containers_of_one: false,
sort_array_items: false,
options_by_path: HashMap::new(),
}
}
}