Repository: ergoplatform/sigma-rust (language: rust)

Issue:
Unbox Value variants



Discussion / hints:

Fix patch:
diff --git a/ergo-lib/src/ast/calc_blake2b256.rs b/ergo-lib/src/ast/calc_blake2b256.rs
index 73fe0c1e8..ac28854f4 100644
--- a/ergo-lib/src/ast/calc_blake2b256.rs
+++ b/ergo-lib/src/ast/calc_blake2b256.rs
@@ -43,7 +43,7 @@ impl Evaluable for CalcBlake2b256 {
     fn eval(&self, env: &Env, ctx: &mut EvalContext) -> Result<Value, EvalError> {
         let input_v = self.input.eval(env, ctx)?;
         match input_v.clone() {
-            Value::Coll(coll) => match *coll {
+            Value::Coll(coll) => match coll {
                 Coll::Primitive(CollPrim::CollByte(coll_byte)) => {
                     let expected_hash: Vec<u8> =
                         blake2b256_hash(coll_byte.as_vec_u8().as_slice()).0.to_vec();
diff --git a/ergo-lib/src/ast/coll_fold.rs b/ergo-lib/src/ast/coll_fold.rs
index 6cbf8d792..1573ffd58 100644
--- a/ergo-lib/src/ast/coll_fold.rs
+++ b/ergo-lib/src/ast/coll_fold.rs
@@ -103,7 +103,7 @@ impl Evaluable for Fold {
             ))),
         };
         match input_v {
-            Value::Coll(coll) => match *coll {
+            Value::Coll(coll) => match coll {
                 Primitive(CollPrim::CollByte(coll_byte)) => {
                     coll_byte.iter().try_fold(zero_v, |acc, byte| {
                         let tup_arg = Value::Tup(TupleItems::pair(acc, Value::Byte(*byte)));
diff --git a/ergo-lib/src/ast/constant.rs b/ergo-lib/src/ast/constant.rs
index 018bed009..9d252af46 100644
--- a/ergo-lib/src/ast/constant.rs
+++ b/ergo-lib/src/ast/constant.rs
@@ -143,9 +143,9 @@ impl From<Vec<u8>> for Constant {
     fn from(v: Vec<u8>) -> Self {
         Constant {
             tpe: SType::SColl(Box::new(SType::SByte)),
-            v: Value::Coll(Box::new(Coll::Primitive(CollPrim::CollByte(
+            v: Value::Coll(Coll::Primitive(CollPrim::CollByte(
                 v.into_iter().map(|b| b as i8).collect(),
-            )))),
+            ))),
         }
     }
 }
@@ -248,7 +248,7 @@ mod tests {
     fn coll_from_constant(c: Constant, length: usize) -> Constant {
         Constant {
             tpe: SType::SColl(Box::new(c.tpe.clone())),
-            v: Value::Coll(Box::new(if c.tpe == SType::SByte {
+            v: Value::Coll(if c.tpe == SType::SByte {
                 let mut values: Vec<i8> = Vec::with_capacity(length);
                 let byte: i8 = c.v.try_extract_into().unwrap();
                 for _ in 0..length {
@@ -264,7 +264,7 @@ mod tests {
                     elem_tpe: c.tpe,
                     v: values,
                 }
-            })),
+            }),
         }
     }
 
diff --git a/ergo-lib/src/ast/func_value.rs b/ergo-lib/src/ast/func_value.rs
index 0af9e69db..e69f4bf46 100644
--- a/ergo-lib/src/ast/func_value.rs
+++ b/ergo-lib/src/ast/func_value.rs
@@ -81,7 +81,7 @@ impl FuncValue {
 
 impl Evaluable for FuncValue {
     fn eval(&self, _env: &Env, _ctx: &mut EvalContext) -> Result<Value, EvalError> {
-        Ok(Value::FuncValue(Box::new(self.clone())))
+        Ok(Value::FuncValue(self.clone()))
     }
 }
 
diff --git a/ergo-lib/src/ast/value.rs b/ergo-lib/src/ast/value.rs
index ebdb8543f..7bcc55eb8 100644
--- a/ergo-lib/src/ast/value.rs
+++ b/ergo-lib/src/ast/value.rs
@@ -86,7 +86,7 @@ pub enum Value {
     /// AVL tree
     AvlTree,
     /// Collection of values of the same type
-    Coll(Box<Coll>),
+    Coll(Coll),
     /// Tuple (arbitrary type values)
     Tup(TupleItems<Value>),
     /// Transaction(and blockchain) context info
@@ -94,7 +94,7 @@ pub enum Value {
     /// Optional value
     Opt(Box<Option<Value>>),
     /// lambda
-    FuncValue(Box<FuncValue>),
+    FuncValue(FuncValue),
 }
 
 impl Value {
@@ -154,13 +154,13 @@ impl From<ErgoBox> for Value {
 
 impl From<Vec<i8>> for Value {
     fn from(v: Vec<i8>) -> Self {
-        Value::Coll(Box::new(Coll::Primitive(CollPrim::CollByte(v))))
+        Value::Coll(Coll::Primitive(CollPrim::CollByte(v)))
     }
 }
 
 impl From<Vec<u8>> for Value {
     fn from(v: Vec<u8>) -> Self {
-        Value::Coll(Box::new(Coll::Primitive(CollPrim::CollByte(v.as_vec_i8()))))
+        Value::Coll(Coll::Primitive(CollPrim::CollByte(v.as_vec_i8())))
     }
 }
 
@@ -187,10 +187,10 @@ impl StoredNonPrimitive for Tuple {}
 
 impl<T: LiftIntoSType + StoredNonPrimitive + Into<Value>> From<Vec<T>> for Value {
     fn from(v: Vec<T>) -> Self {
-        Value::Coll(Box::new(Coll::NonPrimitive {
+        Value::Coll(Coll::NonPrimitive {
             elem_tpe: T::stype(),
             v: v.into_iter().map(|i| i.into()).collect(),
-        }))
+        })
     }
 }
 
@@ -289,7 +289,7 @@ impl TryExtractFrom<Value> for ErgoBox {
 impl<T: TryExtractFrom<Value> + StoredNonPrimitive> TryExtractFrom<Value> for Vec<T> {
     fn try_extract_from(c: Value) -> Result<Self, TryExtractFromError> {
         match c {
-            Value::Coll(coll) => match *coll {
+            Value::Coll(coll) => match coll {
                 Coll::NonPrimitive { elem_tpe: _, v } => {
                     v.into_iter().map(T::try_extract_from).collect()
                 }
@@ -311,7 +311,7 @@ impl<T: TryExtractFrom<Value> + StoredNonPrimitive> TryExtractFrom<Value> for Ve
 impl TryExtractFrom<Value> for Vec<i8> {
     fn try_extract_from(v: Value) -> Result<Self, TryExtractFromError> {
         match v {
-            Value::Coll(v) => match *v {
+            Value::Coll(v) => match v {
                 Coll::Primitive(CollPrim::CollByte(bs)) => Ok(bs),
                 _ => Err(TryExtractFromError(format!(
                     "expected {:?}, found {:?}",
diff --git a/ergo-lib/src/serialization/data.rs b/ergo-lib/src/serialization/data.rs
index 81dc88035..796b9a47f 100644
--- a/ergo-lib/src/serialization/data.rs
+++ b/ergo-lib/src/serialization/data.rs
@@ -31,7 +31,7 @@ impl DataSerializer {
             Value::SigmaProp(s) => s.value().sigma_serialize(w),
             Value::CBox(_) => todo!(),
             Value::AvlTree => todo!(),
-            Value::Coll(ct) => match &**ct {
+            Value::Coll(ct) => match ct {
                 Coll::Primitive(CollPrim::CollByte(b)) => {
                     w.put_usize_as_u16(b.len())?;
                     w.write_all(b.clone().as_vec_u8().as_slice())
@@ -68,9 +68,9 @@ impl DataSerializer {
                 let len = r.get_u16()? as usize;
                 let mut buf = vec![0u8; len];
                 r.read_exact(&mut buf)?;
-                Value::Coll(Box::new(Coll::Primitive(CollPrim::CollByte(
+                Value::Coll(Coll::Primitive(CollPrim::CollByte(
                     buf.into_iter().map(|v| v as i8).collect(),
-                ))))
+                )))
             }
             SColl(elem_type) => {
                 let len = r.get_u16()? as usize;
@@ -78,10 +78,10 @@ impl DataSerializer {
                 for _ in 0..len {
                     elems.push(DataSerializer::sigma_parse(elem_type, r)?);
                 }
-                Value::Coll(Box::new(Coll::NonPrimitive {
+                Value::Coll(Coll::NonPrimitive {
                     elem_tpe: *elem_type.clone(),
                     v: elems,
-                }))
+                })
             }
             STuple(stuple::STuple { items: types }) => {
                 let mut items = Vec::new();
diff --git a/ergo-lib/src/types/scontext.rs b/ergo-lib/src/types/scontext.rs
index 46b472875..f73db543b 100644
--- a/ergo-lib/src/types/scontext.rs
+++ b/ergo-lib/src/types/scontext.rs
@@ -25,7 +25,7 @@ static S_CONTEXT_TYPE_COMPANION_HEAD: STypeCompanionHead = STypeCompanionHead {
 };
 
 static DATA_INPUTS_EVAL_FN: EvalFn = |obj, _args| {
-    Ok(Value::Coll(Box::new(Coll::NonPrimitive {
+    Ok(Value::Coll(Coll::NonPrimitive {
         v: obj
             .try_extract_into::<Rc<Context>>()?
             .data_inputs
@@ -34,7 +34,7 @@ static DATA_INPUTS_EVAL_FN: EvalFn = |obj, _args| {
             .map(|b| Value::CBox(Box::new(b)))
             .collect(),
         elem_tpe: SType::SBox,
-    })))
+    }))
 };
 
 lazy_static! {


Test patch: