easy_configuration_format/
data.rs

1/// Describes the layout of a loaded settings file line-by-line
2#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
3pub enum LayoutEntry {
4	/// Empty line
5	Empty,
6	/// Key-value pair
7	Key (String),
8	/// Comment
9	Comment (String),
10}
11
12
13
14/// Represents a setting value
15#[derive(Debug, Clone, PartialEq, PartialOrd)]
16pub enum Value {
17	/// Intentionally empty value
18	Empty,
19	/// Int value
20	I64 (i64),
21	/// Float value
22	F64 (f64),
23	/// Bool value
24	Bool (bool),
25	/// String value, can be any number of lines
26	String (String),
27}
28
29impl Value {
30	/// Used for formatting ecf files
31	pub fn format(&self) -> String {
32		match self {
33			Self::Empty => String::from("empty"),
34			Self::I64 (i64_value) => i64_value.to_string(),
35			Self::F64 (f64_value) => f64_value.to_string(),
36			Self::Bool (true) => String::from("true"),
37			Self::Bool (false) => String::from("false"),
38			Self::String (string_value) => {
39				if string_value.contains("\n") {
40					let mut output = String::from("\"\n");
41					for line in string_value.split('\n') {
42						output.push('"');
43						output += line;
44						output.push('\n');
45					}
46					output
47				} else {
48					format!("\"{string_value}\"")
49				}
50			}
51		}
52	}
53	/// Returns "Empty", "String", "Int", "Float", or "Bool" according to enum state
54	pub const fn type_as_string(&self) -> &'static str {
55		match self {
56			Self::Empty => "Empty",
57			Self::I64 (_) => "Int",
58			Self::F64 (_) => "Float",
59			Self::Bool (_) => "Bool",
60			Self::String (_) => "String",
61		}
62	}
63	/// Returns "an Empty", "a String", "an Int", "a Float", or "a Bool" according to enum state
64	pub const fn type_as_singular_string(&self) -> &'static str {
65		match self {
66			Self::Empty => "an Empty",
67			Self::I64 (_) => "an Int",
68			Self::F64 (_) => "a Float",
69			Self::Bool (_) => "a Bool",
70			Self::String (_) => "a String",
71		}
72	}
73}
74
75
76
77/// Output type for `File::from_str`
78pub type DidRunUpdaters = bool;