Use this file to discover all available pages before exploring further.
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.
Returns true if the option is Some or None respectively.
let x = Option::some(3);assert(x.is_some());assert(!x.is_none());
unwrap
pub fn unwrap(self) -> T
Asserts self.is_some() and returns the wrapped value. Fails if the option is None.
let x = Option::some(10);let value = x.unwrap(); // 10
unwrap_or
pub fn unwrap_or(self, default: T) -> T
Returns the wrapped value when Some, or default when None.
let x: Option<u32> = Option::none();let value = x.unwrap_or(99); // 99
unwrap_or_else
pub fn unwrap_or_else<Env>(self, default: fn[Env]() -> T) -> T
Returns the wrapped value when Some, or calls default() when None.
let x: Option<u32> = Option::none();let value = x.unwrap_or_else(|| 0);
unwrap_unchecked
pub fn unwrap_unchecked(self) -> T
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.
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.
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).
let mut vec: BoundedVec<Field, 10> = BoundedVec::new();for i in 0..5 { vec.push(i as Field);}assert(vec.len() == 5);assert(vec.max_len() == 10);
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.
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.
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>.
// Creates an empty map using the type's default hasherpub fn default() -> Selfwhere B: BuildHasher + Default// Creates a map with an existing hasher instancepub fn with_hasher(_build_hasher: B) -> Selfwhere B: BuildHasher
// Double every value in the mapmap.iter_values_mut(|v| v * 2);// Remove entries where the key is zeromap.retain(|k, _v| k != 0);// Iterate over all entrieslet entries = map.entries();for i in 0..map.capacity() { if i < entries.len() { let (k, v) = entries.get(i); println(f"{k} -> {v}"); }}
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 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:
Method
Description
default() / with_hasher(b)
Construct an empty map
insert(key, value)
Insert or update a key
get(key) -> Option<V>
Look up a key
remove(key)
Delete a key
contains_key(key) -> bool
Check for presence
len() -> u32
Current number of entries
is_empty() -> bool
True when empty
clear()
Remove all entries
entries()
All (K, V) pairs as a vector
keys() / values()
All keys or values as vectors
iter_mut(f)
Mutate keys and values
iter_keys_mut(f)
Mutate keys only
iter_values_mut(f)
Mutate values only
retain(f)
Keep only matching entries
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.