> Aztec.nr API reference, v6.0.0 (mainnet and testnet). Index: https://docs.aztec.network/aztec-nr-api/v6.0.0/llms.txt

# Struct UnconstrainedArray

Module: `noir_aztec::unconstrained_array`

```rust
pub struct UnconstrainedArray<T, Oracle>
{ /* private fields */ }
```

A dynamically sized array backed by PXE-side in-memory storage via an \[`ArrayOracles`] backend.

Arrays are identified by a slot, and each logical operation (push, pop, get, etc.) is a single oracle call. The `Oracle` backend determines the array's lifetime and visibility; contracts should not use this type directly but rather one of its aliases: [`EphemeralArray`](/aztec-nr-api/v6.0.0/noir_aztec/ephemeral/type.EphemeralArray.md) (scoped to a single contract call frame) or [`TransientArray`](/aztec-nr-api/v6.0.0/noir_aztec/transient/type.TransientArray.md) (shared across all frames of the same contract within one top-level PXE call).

## Implementations

```rust
impl<T, Oracle> UnconstrainedArray<T, Oracle>
where
    Oracle: ArrayOracles
```

```rust
pub unconstrained fn at(slot: Field) -> Self
```

Returns a handle to the array at the given slot, which may already contain data (e.g. populated by an oracle or by an earlier frame, depending on the backend's visibility).

```rust
pub unconstrained fn empty_at(slot: Field) -> Self
```

Returns an empty array at the given slot, clearing any pre-existing data.

For backends whose arrays are visible beyond a single call frame (e.g. transient arrays), this wipes data other frames of the same contract may have written at the slot.

```rust
pub unconstrained fn empty() -> Self
```

Returns an empty array at a fresh, randomly allocated slot.

Use this when the caller does not need a specific slot: the random slot is isolated from every other array of the same backend with overwhelming probability. Prefer [`UnconstrainedArray::empty_at`](/aztec-nr-api/v6.0.0/noir_aztec/unconstrained_array/struct.UnconstrainedArray.md#empty_at) when the slot must be a known value (e.g. one shared with an oracle or another call frame).

```rust
pub unconstrained fn from_array<let N: u32>(values: [T; N]) -> Self
where
    T: Serialize
```

Returns an array at a fresh, randomly allocated slot holding `values` in order.

```rust
pub unconstrained fn len(self) -> u32
```

Returns the number of elements stored in the array.

```rust
pub unconstrained fn push(self, value: T)
where
    T: Serialize
```

Stores a value at the end of the array.

```rust
pub unconstrained fn pop(self) -> T
where
    T: Deserialize
```

Removes and returns the last element. Implementors are required to panic if the array is empty.

```rust
pub unconstrained fn get(self, index: u32) -> T
where
    T: Deserialize
```

Retrieves the value stored at `index`. Implementors are required to panic if the index is out of bounds.

```rust
pub unconstrained fn set(self, index: u32, value: T)
where
    T: Serialize
```

Overwrites the value stored at `index`. Implementors are required to panic if the index is out of bounds.

```rust
pub unconstrained fn remove(self, index: u32)
```

Removes the element at `index`, shifting subsequent elements backward. Implementors are required to panic if the index is out of bounds.

```rust
pub unconstrained fn clear(self) -> Self
```

Removes all elements from the array and returns self for chaining.

```rust
pub unconstrained fn for_each<Env>(self, f: unconstrained fn[Env](u32, T))
where
    T: Deserialize
```

Calls a function on each element of the array.

The function `f` is called once with each array value and its corresponding index, in order (from the first element to the last).

Structurally mutating the array from inside the callback (e.g. via `push`, `pop`, `remove` or `clear`) is **not** supported: it can cause elements to be skipped, visited more than once, or read out of bounds.

```rust
pub unconstrained fn map<U, Env>(
    self,
    f: unconstrained fn[Env](T) -> U,
) -> UnconstrainedArray<U, Oracle>
where
    T: Deserialize,
    U: Serialize
```

Applies `f` to every element and collects the results into a fresh array.

```rust
pub unconstrained fn filter<Env>(self, f: unconstrained fn[Env](T) -> bool) -> Self
where
    T: Serialize,
    T: Deserialize
```

Collects every element satisfying the predicate `f` into a fresh array.

```rust
pub unconstrained fn any<Env>(self, f: unconstrained fn[Env](T) -> bool) -> bool
where
    T: Serialize,
    T: Deserialize
```

Returns `true` if at least one element satisfies the predicate `f`.

```rust
pub unconstrained fn all<Env>(self, f: unconstrained fn[Env](T) -> bool) -> bool
where
    T: Serialize,
    T: Deserialize
```

Returns `true` if every element satisfies the predicate `f` (vacuously `true` for an empty array).

```rust
pub unconstrained fn find<Env>(self, f: unconstrained fn[Env](T) -> bool) -> Option<T>
where
    T: Deserialize
```

Returns the first element satisfying the predicate `f`, or `Option::none` if none do.

## Trait implementations

```rust
impl<T> Deserialize for UnconstrainedArray<T, EphemeralOracles>
```

```rust
pub fn deserialize(fields: [Field; 1]) -> Self
```

```rust
pub fn stream_deserialize<let K: u32>(reader: &mut Reader<K>) -> Self
```

```rust
impl<T> Serialize for UnconstrainedArray<T, EphemeralOracles>
```

```rust
pub fn serialize(self) -> [Field; 1]
```

```rust
pub fn stream_serialize<let K: u32>(self, writer: &mut Writer<K>)
```
