devalang_core/core/shared/
value.rs

1use std::collections::HashMap;
2use serde::{ Deserialize, Serialize };
3
4use crate::core::{parser::statement::{Statement, StatementKind}, shared::duration::Duration};
5
6#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
7pub enum Value {
8    Boolean(bool),
9    Number(f32),
10    Duration(Duration),
11    Identifier(String),
12    String(String),
13    Array(Vec<Value>),
14    Map(HashMap<String, Value>),
15    Block(Vec<Statement>),
16    Sample(String),
17    Beat(String),
18    Statement(Box<Statement>),
19    StatementKind(Box<StatementKind>),
20    Unknown,
21    Null,
22}
23
24impl Value {
25    pub fn get(&self, key: &str) -> Option<&Value> {
26        if let Value::Map(map) = self {
27            map.get(key)
28        } else {
29            None
30        }
31    }
32}