tyson/
value.rs

1use std::fmt;
2
3#[derive(Debug, Eq, PartialEq)]
4pub struct Primitive(pub String, pub String);
5
6
7impl fmt::Display for Primitive {
8    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
9        if self.1.is_empty() {
10            write!(f, "{}", self.0)
11        } else {
12            write!(f, "{}|{}|", self.0, self.1) // TODO escape
13        }
14    }
15}
16
17#[derive(Debug, Eq, PartialEq)]
18pub enum TySONValue {
19    Primitive(Primitive),
20    Map(String, Vec<(Primitive, TySONValue)>),
21    Vector(String, Vec<TySONValue>),
22}
23
24#[derive(Debug)]
25pub struct TySONDocument(Vec<(Primitive, TySONValue)>);
26
27impl TySONDocument {
28    pub fn new() -> Self{
29        Self(vec![])
30    }
31
32    pub fn push(&mut self, item: (Primitive, TySONValue)){
33        self.0.push(item);
34    }
35
36    pub fn items(&self) -> &Vec<(Primitive, TySONValue)>{
37        &self.0
38    }
39}