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

# Struct Option

Module: `std::option`

```rust
pub struct Option<T>
{ /* private fields */ }
```

Represents a value of type T or its absence. Use `Option::some(value)` to construct a value or `Option::none()` to record the absence of one.

## Implementations

```rust
impl<T> Option<T>
```

```rust
pub fn none() -> Self
```

Constructs a None value

```rust
pub fn some(_value: T) -> Self
```

Constructs a Some wrapper around the given value

```rust
pub fn is_none(&self) -> bool
```

True if this Option is None

```rust
pub fn is_some(&self) -> bool
```

True if this Option is Some

```rust
pub fn unwrap(self) -> T
```

Asserts `self.is_some()` and returns the wrapped value.

```rust
pub fn unwrap_unchecked(self) -> T
```

Returns the inner value without asserting `self.is_some()` Note that if `self` is `None`, there is no guarantee what value will be returned, only that it will be of type `T`.

```rust
pub fn unwrap_or(self, default: T) -> T
```

Returns the wrapped value if `self.is_some()`. Otherwise, returns the given default value.

```rust
pub fn unwrap_or_else<Env>(self, default: fn[Env]() -> T) -> T
```

Returns the wrapped value if `self.is_some()`. Otherwise, calls the given function to return a default value.

```rust
pub fn expect<let N: u32, MessageTypes>(
    self,
    message: fmtstr<N, MessageTypes>,
) -> T
```

Asserts `self.is_some()` with a provided custom message and returns the contained `Some` value

```rust
pub fn map<U, Env>(self, f: fn[Env](T) -> U) -> Option<U>
```

If self is `Some(x)`, this returns `Some(f(x))`. Otherwise, this returns `None`.

```rust
pub fn map_or<U, Env>(self, default: U, f: fn[Env](T) -> U) -> U
```

If self is `Some(x)`, this returns `f(x)`. Otherwise, this returns the given default value.

```rust
pub fn map_or_else<U, Env1, Env2>(
    self,
    default: fn[Env1]() -> U,
    f: fn[Env2](T) -> U,
) -> U
```

If self is `Some(x)`, this returns `f(x)`. Otherwise, this returns `default()`.

```rust
pub fn and(self, other: Self) -> Self
```

Returns None if self is None. Otherwise, this returns `other`.

```rust
pub fn and_then<U, Env>(self, f: fn[Env](T) -> Option<U>) -> Option<U>
```

If self is None, this returns None. Otherwise, this calls the given function with the Some value contained within self, and returns the result of that call.

In some languages this function is called `flat_map` or `bind`.

```rust
pub fn or(self, other: Self) -> Self
```

If self is Some, return self. Otherwise, return `other`.

```rust
pub fn or_else<Env>(self, default: fn[Env]() -> Self) -> Self
```

If self is Some, return self. Otherwise, return `default()`.

```rust
pub fn xor(self, other: Self) -> Self
```

```rust
pub fn filter<Env>(self, predicate: fn[Env](T) -> bool) -> Self
```

Returns `Some(x)` if self is `Some(x)` and `predicate(x)` is true. Otherwise, this returns `None`

```rust
pub fn flatten(option: Option<Self>) -> Self
```

Flattens an Option\<Option> into a Option. This returns None if the outer Option is None. Otherwise, this returns the inner Option.

## Trait implementations

```rust
impl<T> Default for Option<T>
```

```rust
pub fn default() -> Self
```

```rust
impl<T> Eq for Option<T>
where
    T: Eq
```

```rust
pub fn eq(self, other: Self) -> bool
```

```rust
impl<T> Hash for Option<T>
where
    T: Hash
```

```rust
pub fn hash<H>(self, state: &mut H)
where
    H: Hasher
```

```rust
impl<T> Ord for Option<T>
where
    T: Ord
```

```rust
pub fn cmp(self, other: Self) -> Ordering
```
