arcis_interface/
types.rs

1#[derive(Debug, Clone, PartialEq, Eq)]
2pub enum Value {
3    MScalar { size_in_bits: usize },
4    MFloat { size_in_bits: usize },
5    MBool,
6    Scalar { size_in_bits: usize },
7    Float { size_in_bits: usize },
8    Bool,
9    Ciphertext { size_in_bits: usize },
10    PublicKey { size_in_bits: usize },
11    Array(Vec<Value>),
12    Tuple(Vec<Value>),
13    Struct(Vec<Value>),
14}
15
16impl Value {
17    pub fn size_in_scalars(&self) -> usize {
18        match self {
19            Self::MScalar { .. } => 1,
20            Self::MFloat { .. } => 1,
21            Self::Scalar { .. } => 1,
22            Self::Float { .. } => 1,
23            Self::MBool { .. } => 1,
24            Self::Bool { .. } => 1,
25            Self::Ciphertext { .. } => 1,
26            Self::PublicKey { .. } => 1,
27            Self::Array(c) | Self::Tuple(c) | Self::Struct(c) => {
28                c.iter().fold(0, |acc, x| acc + x.size_in_scalars())
29            }
30        }
31    }
32
33    pub fn flatten(&self) -> Vec<Value> {
34        match self {
35            Self::Array(c) | Self::Tuple(c) | Self::Struct(c) => {
36                let mut v = Vec::new();
37                for a in c {
38                    v.extend(a.flatten());
39                }
40                v
41            }
42            _ => vec![self.clone()],
43        }
44    }
45}
46
47#[derive(Debug, serde::Serialize)]
48pub struct CircuitInterface {
49    pub name: String,
50    pub inputs: Vec<Value>,
51    pub outputs: Vec<Value>,
52}
53
54impl CircuitInterface {
55    pub fn new(name: String, inputs: Vec<Value>, outputs: Vec<Value>) -> Self {
56        Self {
57            name,
58            inputs,
59            outputs,
60        }
61    }
62
63    pub fn serialize(&self) -> Result<String, serde_json::Error> {
64        serde_json::to_string(self)
65    }
66
67    pub fn from_json(input: &str) -> Result<Self, serde_json::Error> {
68        serde_json::from_str(input)
69    }
70}