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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
use leo_gadgets::signed_integer::*;
use snarkvm_models::gadgets::utilities::{boolean::Boolean, uint::*};
use std::fmt;
#[derive(Clone)]
pub enum Value {
Boolean(Boolean),
U8(UInt8),
U16(UInt16),
U32(UInt32),
U64(UInt64),
U128(UInt128),
I8(Int8),
I16(Int16),
I32(Int32),
I64(Int64),
I128(Int128),
Array(Vec<Value>),
Tuple(Vec<Value>),
}
impl fmt::Display for Value {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
let string_option = match self {
Value::Boolean(value) => value.get_value().map(|v| v.to_string()),
Value::U8(value) => value.value.map(|v| v.to_string()),
Value::U16(value) => value.value.map(|v| v.to_string()),
Value::U32(value) => value.value.map(|v| v.to_string()),
Value::U64(value) => value.value.map(|v| v.to_string()),
Value::U128(value) => value.value.map(|v| v.to_string()),
Value::I8(value) => value.value.map(|v| v.to_string()),
Value::I16(value) => value.value.map(|v| v.to_string()),
Value::I32(value) => value.value.map(|v| v.to_string()),
Value::I64(value) => value.value.map(|v| v.to_string()),
Value::I128(value) => value.value.map(|v| v.to_string()),
Value::Array(values) => {
let string = values.iter().map(|v| v.to_string()).collect::<Vec<_>>().join(", ");
write!(f, "[{}]", string)?;
Some("".to_owned())
}
Value::Tuple(values) => {
let string = values.iter().map(|v| v.to_string()).collect::<Vec<_>>().join(", ");
write!(f, "[{}]", string)?;
Some("".to_owned())
}
};
let string = string_option.unwrap_or_else(|| "[input]".to_owned());
write!(f, "{}", string)
}
}