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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
use core::cmp::Ordering;

use rapira::Rapira;
use rust_decimal::Decimal;
use serde::{Deserialize, Serialize};

#[derive(Clone, Serialize, Deserialize, Debug, PartialEq, Eq, Rapira)]
pub struct ValueWithId {
    #[rapira(with = "rapira::byte_rapira")]
    pub id: u8,
    pub value: Value,
}

impl PartialOrd for ValueWithId {
    fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
        Some(self.id.cmp(&other.id))
    }
}

impl From<(u8, Value)> for ValueWithId {
    fn from(value: (u8, Value)) -> Self {
        ValueWithId {
            id: value.0,
            value: value.1,
        }
    }
}

#[derive(PartialEq, Clone, Serialize, Deserialize, Debug, Eq, Rapira)]
#[repr(u8)]
pub enum List {
    Bool(Vec<bool>),
    U64(Vec<u64>),
    I64(Vec<i64>),
    Decimal(Vec<Decimal>),
    Str(Vec<String>),
    Pair(Vec<ValueWithId>),
    List(Vec<List>),
}

#[derive(PartialEq, Clone, Serialize, Deserialize, Debug, Eq, Rapira)]
#[rapira(static_size = "None")]
#[repr(u8)]
pub enum Value {
    Void,
    Bool(bool),
    U64(u64),
    I64(i64),
    Decimal(Decimal),
    Str(String),
    Pair(Box<ValueWithId>),
    List(List),
}