Skip to content

Commit

Permalink
stackinputs: constructor accepting iterator
Browse files Browse the repository at this point in the history
  • Loading branch information
hackaugusto committed Dec 2, 2023
1 parent d358ce3 commit 9617918
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions core/src/stack/inputs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
///
Expand All @@ -22,7 +22,12 @@ impl StackInputs {
// --------------------------------------------------------------------------------------------

/// Returns `[StackInputs]` from a list of values, reversing them into a stack.
pub fn new(mut values: Vec<Felt>) -> Result<Self, InputError> {
pub fn new<I>(values: I) -> Result<Self, InputError>
where
I: IntoIterator<Item = Felt>,
{
let mut values: Vec<Felt> = values.into_iter().collect();

if values.len() > MAX_STACK_INPUTS_SIZE {
Err(InputError::StackTooBig(values.len()))
} else {
Expand All @@ -37,8 +42,7 @@ impl StackInputs {
where
I: IntoIterator<Item = u64>,
{
let values: Vec<Felt> = iter.into_iter().map(Felt::from).collect();
Self::new(values)
Self::new(iter.into_iter().map(Felt::from))
}

// PUBLIC ACCESSORS
Expand Down

0 comments on commit 9617918

Please sign in to comment.