Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add new Vec type to frontend #1103

Merged
merged 4 commits into from
Apr 6, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions noir_stdlib/src/collections/vec.nr
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,22 @@
// For a similar reason, no constructor for Vec is exposed yet since the type
// is still in-progress.
impl<T> Vec<T> {
/// Get an element from the vector at the given index.
/// Fails with a constraint error if the given index is
/// less than the length of the vector.
jfecher marked this conversation as resolved.
Show resolved Hide resolved
#[builtin(vec_get)]
kevaundray marked this conversation as resolved.
Show resolved Hide resolved
fn get(_self: Self, _index: Field) -> T { }

/// Push a new element to the end of the vector, returning a
/// new vector with a length one greater than the
/// original unmodified vector.
#[builtin(vec_push)]
fn push(_self: Self, _elem: T) -> Self { }

/// Pop an element from the end of the given vector, returning
/// a new vector with a length of one less than the given vector,
/// as well as the popped element.
/// Fails with a constraint error if the given vector's length is zero.
#[builtin(vec_pop)]
fn pop(_self: Self) -> (Self, T) { }
}