Skip to main content

armour/dyn_types/
value.rs

1use core::cmp::Ordering;
2
3use rapira::Rapira;
4use serde::{Deserialize, Serialize};
5
6#[derive(Clone, Serialize, Deserialize, Debug, PartialEq, Eq, Rapira)]
7pub struct ValueWithId {
8    #[rapira(with = rapira::byte_rapira)]
9    pub id: u8,
10    pub value: Value,
11}
12
13impl PartialOrd for ValueWithId {
14    fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
15        Some(self.id.cmp(&other.id))
16    }
17}
18
19impl From<(u8, Value)> for ValueWithId {
20    fn from(value: (u8, Value)) -> Self {
21        ValueWithId {
22            id: value.0,
23            value: value.1,
24        }
25    }
26}
27
28#[derive(PartialEq, Clone, Serialize, Deserialize, Debug, Eq, Rapira)]
29#[repr(u8)]
30pub enum List {
31    Bool(Vec<bool>),
32    U64(Vec<u64>),
33    I64(Vec<i64>),
34    // Decimal(Vec<Decimal>),
35    Str(Vec<String>),
36    Pair(Vec<ValueWithId>),
37    List(Vec<List>),
38}
39
40#[derive(PartialEq, Clone, Serialize, Deserialize, Debug, Eq, Rapira)]
41#[rapira(static_size = None)]
42#[rapira(min_size = 1)]
43#[repr(u8)]
44pub enum Value {
45    Void,
46    Bool(bool),
47    U64(u64),
48    I64(i64),
49    // Decimal(Decimal),
50    Str(String),
51    Pair(Box<ValueWithId>),
52    List(List),
53}