hocon_rs/
config_options.rs1use std::{fmt::Debug, rc::Rc};
2
3use crate::syntax::Syntax;
4
5pub(crate) const MAX_DEPTH: usize = 64;
6
7pub(crate) const MAX_INCLUDE_DEPTH: usize = 64;
8
9pub type CompareFn = Rc<dyn Fn(&Syntax, &Syntax) -> std::cmp::Ordering>;
10
11#[derive(Clone)]
12pub struct ConfigOptions {
13 pub use_system_environment: bool,
14 pub compare: CompareFn,
15 pub classpath: Rc<Vec<String>>,
16 pub max_depth: usize,
17 pub max_include_depth: usize,
18}
19
20impl ConfigOptions {
21 pub fn new(use_system_env: bool, classpath: Vec<String>) -> Self {
22 Self {
23 use_system_environment: use_system_env,
24 compare: Rc::new(Syntax::cmp),
25 classpath: Rc::new(classpath),
26 ..Default::default()
27 }
28 }
29
30 pub fn with_compare<C>(use_system_env: bool, classpath: Vec<String>, compare: C) -> Self
31 where
32 C: Fn(&Syntax, &Syntax) -> std::cmp::Ordering + 'static,
33 {
34 Self {
35 use_system_environment: use_system_env,
36 compare: Rc::new(compare),
37 classpath: Rc::new(classpath),
38 ..Default::default()
39 }
40 }
41}
42
43impl Default for ConfigOptions {
44 fn default() -> Self {
45 Self {
46 use_system_environment: false,
47 compare: Rc::new(Syntax::cmp),
48 classpath: Default::default(),
49 max_depth: MAX_DEPTH,
50 max_include_depth: MAX_INCLUDE_DEPTH,
51 }
52 }
53}
54
55impl Debug for ConfigOptions {
56 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
57 f.debug_struct("ConfigOptions")
58 .field("use_system_environment", &self.use_system_environment)
59 .field("classpath", &self.classpath)
60 .finish_non_exhaustive()
61 }
62}
63
64impl PartialEq for ConfigOptions {
65 fn eq(&self, other: &Self) -> bool {
66 self.use_system_environment == other.use_system_environment
67 && Rc::ptr_eq(&self.compare, &other.compare)
68 && self.classpath == other.classpath
69 }
70}
71
72impl Eq for ConfigOptions {}