# OptionExtensions

Version: 0.5.0
Framework commit: d503df2befa756e681fcdc6250e9552dc7388bea
Canonical URL: /docs/0.5.0/api/ferroui-dynamic-data/kernel/trait-optionextensions/

**trait** · [`ferroui-dynamic-data`](/docs/0.5.0/api/ferroui-dynamic-data/) · v0.5.0

```rust
trait OptionExtensions<T>: Sized
```

The extensions of an option (`OptionExtensions` on `Optional<T>`).

[View source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.DynamicData/kernel/option_extensions.rs#L14)

## Members

- [`convert`](#function-convert)
- [`convert_optional`](#function-convert_optional)
- [`convert_or`](#function-convert_or)
- [`if_has_value`](#function-if_has_value)
- [`value_or`](#function-value_or)
- [`value_or_default`](#function-value_or_default)
- [`value_or_throw`](#function-value_or_throw)

<a id="function-convert"></a>

### convert

```rust
fn convert<U>(self: Self, converter: impl FnOnce(T) -> U) -> Option<U>
```

The value converted by `converter`, or none (`Convert(Func<TSource, TDestination>)`).

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.DynamicData/kernel/option_extensions.rs#L16)

<a id="function-convert_optional"></a>

### convert_optional

```rust
fn convert_optional<U>(self: Self, converter: impl FnOnce(T) -> Option<U>) -> Option<U>
```

The option that `converter` makes of the value, or none
(`Convert(Func<TSource, Optional<TDestination>>)`).

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.DynamicData/kernel/option_extensions.rs#L20)

<a id="function-convert_or"></a>

### convert_or

```rust
fn convert_or<U>(self: Self, converter: impl FnOnce(T) -> U, fallback_converter: impl FnOnce() -> U) -> U
```

The value converted by `converter`, or what `fallback_converter` makes when there is none
(`ConvertOr`).

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.DynamicData/kernel/option_extensions.rs#L24)

<a id="function-if_has_value"></a>

### if_has_value

```rust
fn if_has_value(self: Self, action: impl FnOnce(T) -> ()) -> OptionElse
```

Runs `action` with the value; the result runs its `else_` action when there is none
(`IfHasValue(Action<T>)`).

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.DynamicData/kernel/option_extensions.rs#L28)

<a id="function-value_or"></a>

### value_or

```rust
fn value_or(self: Self, value_selector: impl FnOnce() -> T) -> T
```

The value, or what `value_selector` makes when there is none (`ValueOr(Func<T>)`).

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.DynamicData/kernel/option_extensions.rs#L31)

<a id="function-value_or_default"></a>

### value_or_default

```rust
fn value_or_default(self: Self) -> T
where T: Default
```

The value, or the default value of `T` (`ValueOrDefault`).

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.DynamicData/kernel/option_extensions.rs#L34)

<a id="function-value_or_throw"></a>

### value_or_throw

```rust
fn value_or_throw<E>(self: Self, exception_generator: impl FnOnce() -> E) -> Result<T, E>
```

The value, or the error that `exception_generator` makes when there is none
(`ValueOrThrow`).

Deviation (DEVIATIONS.md, DynamicData): upstream throws the exception; the port returns it
as the `Err` of the result.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.DynamicData/kernel/option_extensions.rs#L43)

## Trait implementations

- [`OptionExtensions<T>`](/docs/0.5.0/api/ferroui-dynamic-data/kernel/trait-optionextensions/)

## Availability

Extracted for `aarch64-apple-darwin`. Cargo features are listed in the [crate index](/docs/0.5.0/api/).
