cargo_wizard/
toml.rs

1use toml_edit::Formatted;
2
3/// Representation of a numeric, boolean or a string TOML value.
4#[derive(Clone, Debug, Eq, PartialEq)]
5pub enum TomlValue {
6    Int(i64),
7    Bool(bool),
8    String(String),
9}
10
11impl TomlValue {
12    pub fn int(value: i64) -> Self {
13        TomlValue::Int(value)
14    }
15
16    pub fn bool(value: bool) -> Self {
17        TomlValue::Bool(value)
18    }
19
20    pub fn string(value: &str) -> Self {
21        TomlValue::String(value.to_string())
22    }
23
24    pub fn to_toml_value(&self) -> toml_edit::Value {
25        match self {
26            TomlValue::Int(value) => toml_edit::Value::Integer(Formatted::new(*value)),
27            TomlValue::Bool(value) => toml_edit::Value::Boolean(Formatted::new(*value)),
28            TomlValue::String(value) => toml_edit::Value::String(Formatted::new(value.clone())),
29        }
30    }
31}