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
use std::convert::TryFrom;
use engine_shared::stored_value::StoredValue;
use types::{
bytesrepr::{FromBytes, ToBytes},
CLTyped, CLValue,
};
use crate::Result;
#[derive(Eq, PartialEq, Clone, Debug)]
pub struct Value {
inner: StoredValue,
}
impl Value {
pub(crate) fn new(stored_value: StoredValue) -> Self {
Value {
inner: stored_value,
}
}
pub fn from_t<T: CLTyped + ToBytes>(t: T) -> Result<Value> {
let cl_value = CLValue::from_t(t)?;
let inner = StoredValue::CLValue(cl_value);
Ok(Value { inner })
}
pub fn into_t<T: CLTyped + FromBytes>(self) -> Result<T> {
let cl_value = CLValue::try_from(self.inner)?;
Ok(cl_value.into_t()?)
}
}