> ## Documentation Index
> Fetch the complete documentation index at: https://docs.starknet.io/llms.txt
> Use this file to discover all available pages before exploring further.

# core::nullable::NullableTrait

## Signature

```rust theme={null}
pub trait NullableTrait
```

## Trait functions

### deref

Wrapper for `Deref::deref`. Prefer using `Deref::deref` directly.
This function exists for backwards compatibility.

#### Signature

```rust theme={null}
fn deref(nullable: Nullable) -> T
```

#### Examples

Preferred way:

```rust theme={null}
let value: Nullable = NullableTrait::new(42);
let unwrapped = value.deref();
```

This function method does the same thing:

```rust theme={null}
use core::nullable::NullableTrait;
let also_unwrapped = NullableTrait::deref(value);
```

### deref\_or

Returns the contained value if not null, or returns the provided default value.

#### Signature

```rust theme={null}
fn deref_or>(self: Nullable, default: T) -> T
```

#### Examples

```rust theme={null}
let value: Nullable = NullableTrait::new(42);
assert!(value.deref_or(0) == 42);

let null_value: Nullable = Default::default();
assert!(null_value.deref_or(0) == 0);
```

### deref\_or\_else

Returns the contained value if not null, or computes it from a closure.

#### Signature

```rust theme={null}
fn deref_or_else, impl func: FnOnce, +Drop>(
    self: Nullable, f: F,
) -> T
```

#### Examples

```rust theme={null}
let value: Nullable = NullableTrait::new(42);
assert!(value.deref_or_else(|| 0) == 42);

let null_value: Nullable = Default::default();
assert!(null_value.deref_or_else(|| 0) == 0);
```

### new

Creates a new non-null `Nullable` with the given value.

#### Signature

```rust theme={null}
fn new(value: T) -> Nullable
```

#### Examples

```rust theme={null}
let value: Nullable = NullableTrait::new(42);
assert!(!value.is_null());
```

### is\_null

Returns `true` if the value is null.

#### Signature

```rust theme={null}
fn is_null(self: @Nullable) -> bool
```

#### Examples

```rust theme={null}
let value: Nullable = NullableTrait::new(42);
assert!(!value.is_null());

let null_value: Nullable = Default::default();
assert!(null_value.is_null());
```

### as\_snapshot

Creates a new `Nullable` containing a snapshot of the value.
This is useful when working with non-copyable types inside a `Nullable`.
This allows you to keep using the original value while also having access to a
snapshot of it, preventing the original value from being moved.

#### Signature

```rust theme={null}
fn as_snapshot(self: @Nullable) -> Nullable
```

#### Examples

```rust theme={null}
let value: Nullable> = NullableTrait::new(array![1, 2, 3]);
let res = (@value).as_snapshot();
assert!(res.deref() == @array![1, 2, 3]);
assert!(value.deref() == array![1, 2, 3]);
```
