use crate::value::{Ident, Key, Value};
use std::collections::HashSet;
pub type SortFn = Box<dyn Fn(&mut Vec<Key>, &[(Key, Value)])>;
pub type CustomFn = Box<dyn Fn(&str, &str, &str, &str, usize) -> String>;
#[derive(Default)]
pub struct Options {
pub name: Option<String>,
pub indent: Option<String>,
pub compact: bool,
pub sparse: bool,
pub fatal: bool,
pub maxnum: Option<usize>,
pub maxlevel: Option<usize>,
pub maxlength: Option<i64>,
pub nocode: bool,
pub nohuge: bool,
pub comment: Option<usize>,
pub sortkeys: bool,
pub sortfn: Option<SortFn>,
pub fixradix: bool,
pub metatostring: Option<bool>,
pub numformat: Option<String>,
pub valignore: Option<HashSet<Ident>>,
pub valignore_scalar: Option<Vec<Value>>,
pub keyallow: Option<Vec<Key>>,
pub keyignore: Option<Vec<Key>>,
pub valtypeignore: Option<HashSet<String>>,
pub custom: Option<CustomFn>,
}
impl Options {
#[must_use]
pub fn dump() -> Self {
Options {
name: Some("_".to_string()),
compact: true,
sparse: true,
..Options::default()
}
}
#[must_use]
pub fn line() -> Self {
Options {
sortkeys: true,
comment: Some(usize::MAX),
..Options::default()
}
}
#[must_use]
pub fn block() -> Self {
Options {
indent: Some(" ".to_string()),
sortkeys: true,
comment: Some(usize::MAX),
..Options::default()
}
}
#[must_use]
pub fn serialize() -> Self {
Options::default()
}
}