Skip to main content
The Noir standard library provides several generic container types for storing and retrieving data. Because Noir targets fixed-circuit compilation, most containers have compile-time or explicitly bounded sizes.

Option<T>

Option<T> expresses the presence (Some(value)) or absence (None) of a value. It is automatically in scope — no import required.

Constructing values

Methods

Returns true if the option is Some or None respectively.
Asserts self.is_some() and returns the wrapped value. Fails if the option is None.
Returns the wrapped value when Some, or default when None.
Returns the wrapped value when Some, or calls default() when None.
Returns the inner value without asserting is_some(). When the option is None, the return value is unspecified (zeroed memory). Use only when you have already verified the option is Some through another path.
Asserts is_some() with a custom error message, then returns the value.
Applies f to the value if Some(x), returning Some(f(x)). Returns None if the option is None.
Like map, but returns a default value instead of None when the option is None.
and returns None if self is None, otherwise returns other.
and_then (flat_map) calls f with the Some value, returning its result; returns None if self is None.
Returns self if it is Some, otherwise returns other / default().
Returns Some(x) if self is Some(x) and predicate(x) is true. Otherwise returns None.
Flattens Option<Option<T>> into Option<T>. Returns None if the outer option is None.

BoundedVec<T, MaxLen>

A growable array bounded by a compile-time maximum length MaxLen. Internally backed by a fixed-size array, so element access is always O(1).
Always specify the maximum length via a type annotation. Omitting it defaults MaxLen to zero, which will cause a constraint failure at runtime when you push an element.

Construction

Element access

get performs a bounds check and fails the constraint if index >= len. get_unchecked skips the check — only use it when you have already verified the index is in range.

Mutation

Length and capacity

max_len() always returns MaxLen. storage() gives direct access to the backing array — note that elements at indices >= len may be zeroed.

Bulk operations

Both methods append all elements; they panic if the resulting length would exceed MaxLen.

Functional methods


HashMap<K, V, MaxLen, B>

A bounded, compile-time-sized hash map using open addressing with quadratic probing. It stores up to MaxLen entries, but due to hash collisions the practical maximum may be lower. The load factor is capped at 0.75 — inserting beyond this limit causes a constraint failure. K must implement Hash + Eq. B is a BuildHasher. The recommended hasher is BuildHasherDefault<Poseidon2Hasher>.

Construction

Insertion and removal

insert overrides the previous value if the key already exists. remove is a no-op if the key is absent.

Lookup

Size and capacity

capacity() always returns MaxLen. clear() removes all entries.

Iteration

iter_mut and iter_keys_mut rebuild the internal hash table as they run because keys affect slot positions. Prefer iter_values_mut when only values need to change.

UHashMap<K, V, B>

UHashMap is an unbounded, dynamically-growing hash map for use in unconstrained or comptime code. Most operations on UHashMap are unconstrained — their results are not constrained when returned into constrained code.
UHashMap exposes the same method surface as HashMap:
UHashMap results are not constrained. If you return values from a UHashMap into constrained Noir code, you must manually add the necessary constraints to ensure correctness.