puffin_build/utils/
value.rs1use itertools::Itertools;
2use serde::{Deserialize, Serialize};
3
4pub type Array = Vec<Value>;
5
6#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7#[serde(untagged)]
8pub enum Value {
9 Boolean(bool),
10 Integer(i64),
11 String(String),
12 Array(Array),
13}
14
15impl Value {
16 pub fn to_cmake_value(&self) -> String {
17 match self {
18 Value::Boolean(b) => b.to_string().to_uppercase(),
19 Value::Integer(i) => i.to_string(),
20 Value::String(s) => s.clone(),
21 Value::Array(a) => a.iter().map(Value::to_cmake_value).join(","),
22 }
23 }
24}
25
26impl From<Array> for Value {
27 fn from(value: Array) -> Self {
28 Self::Array(value)
29 }
30}
31
32impl From<bool> for Value {
33 fn from(value: bool) -> Self {
34 Self::Boolean(value)
35 }
36}
37
38impl From<i64> for Value {
39 fn from(value: i64) -> Self {
40 Self::Integer(value)
41 }
42}
43
44impl From<String> for Value {
45 fn from(value: String) -> Self {
46 Self::String(value)
47 }
48}
49
50impl From<Vec<String>> for Value {
51 fn from(value: Vec<String>) -> Self {
52 Self::Array(value.into_iter().map(Value::from).collect())
53 }
54}