From 961791864a33d275e56baa36f6152d6d847f6baa Mon Sep 17 00:00:00 2001 From: "Augusto F. Hack" Date: Fri, 1 Dec 2023 15:02:45 +0100 Subject: [PATCH] stackinputs: constructor accepting iterator --- core/src/stack/inputs.rs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/core/src/stack/inputs.rs b/core/src/stack/inputs.rs index b5ca987581..9f0b9560c7 100644 --- a/core/src/stack/inputs.rs +++ b/core/src/stack/inputs.rs @@ -6,7 +6,7 @@ use core::slice; // STACK INPUTS // ================================================================================================ -const MAX_STACK_INPUTS_SIZE: usize = u32::MAX as usize; +const MAX_STACK_INPUTS_SIZE: usize = u16::MAX as usize; /// Initial state of the stack to support program execution. /// @@ -22,7 +22,12 @@ impl StackInputs { // -------------------------------------------------------------------------------------------- /// Returns `[StackInputs]` from a list of values, reversing them into a stack. - pub fn new(mut values: Vec) -> Result { + pub fn new(values: I) -> Result + where + I: IntoIterator, + { + let mut values: Vec = values.into_iter().collect(); + if values.len() > MAX_STACK_INPUTS_SIZE { Err(InputError::StackTooBig(values.len())) } else { @@ -37,8 +42,7 @@ impl StackInputs { where I: IntoIterator, { - let values: Vec = iter.into_iter().map(Felt::from).collect(); - Self::new(values) + Self::new(iter.into_iter().map(Felt::from)) } // PUBLIC ACCESSORS