1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
use crate::unit::Unit;

use serde::{Deserialize, Serialize};

#[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub struct Variable {
    pub symbol: SymbolRaw,
    pub unit: Option<Unit>,
    pub fields: Vec<Field>,
}

#[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub struct Field {
    pub name: String,
    pub unit: Option<Unit>,
}

impl Variable {
    pub fn full_symbol(&self) -> SymbolRaw {
        let fields = self.fields.iter().map(|f| f.name.clone());
        self.symbol
            .iter()
            .map(|s| s.clone())
            .chain(fields)
            .collect()
    }
}

pub type SymbolRef<'s> = &'s [String];
pub type SymbolRaw = Vec<String>;