# IBuilderExtensions

Version: 0.5.0
Framework commit: d503df2befa756e681fcdc6250e9552dc7388bea
Canonical URL: /docs/0.5.0/api/ferroui-reactiveui-testing/trait-ibuilderextensions/

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

```rust
trait IBuilderExtensions: IBuilder + Sized
```

The fluent setters of a builder of test data (`IBuilderExtensions`): each sets or fills a field
of the builder and returns the builder.

Deviation (DEVIATIONS.md, ReactiveUI): upstream passes the field by reference (`out` or `ref`)
next to the builder, which is a reference type; a Rust builder is moved through the chain, so
the field is named by an accessor, a closure that gives the field of the builder:

```
use ferroui_reactiveui_testing::{IBuilder, IBuilderExtensions};

#[derive(Default)]
struct PersonBuilder {
    name: String,
    tags: Vec<String>,
}

impl IBuilder for PersonBuilder {}

impl PersonBuilder {
    fn with_name(self, name: &str) -> Self {
        self.with(|builder| &mut builder.name, name.to_string())
    }

    fn with_tag(self, tag: &str) -> Self {
        self.with_value(|builder| &mut builder.tags, tag.to_string())
    }
}

let builder = PersonBuilder::default().with_name("Ada").with_tag("first");
assert_eq!(builder.name, "Ada");
assert_eq!(builder.tags, ["first"]);
```

The overloads get names of their own: `with` (`With<TField>(out TField, TField)`),
`with_values` and `with_value` for a list, `with_pair`, `with_key_value` and `with_dictionary`
for a dictionary. Upstream declares the last one for every type, not only builders; here it
is a method of builders as the others are.

Not ported: the `ArgumentException` of a list or dictionary field that is null - argument
validation (the fields cannot be null).

[View source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.ReactiveUI.Testing/i_builder_extensions.rs#L47)

## Members

- [`with`](#function-with)
- [`with_values`](#function-with_values)
- [`with_value`](#function-with_value)
- [`with_pair`](#function-with_pair)
- [`with_key_value`](#function-with_key_value)
- [`with_dictionary`](#function-with_dictionary)

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

### with

```rust
fn with<F>(self: Self, field: impl FnOnce(&mut Self) -> &mut F, value: F) -> Self
```

Sets the field to `value` (`With<TField>(out TField field, TField value)`).

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.ReactiveUI.Testing/i_builder_extensions.rs#L49)

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

### with_values

```rust
fn with_values<F>(self: Self, field: impl FnOnce(&mut Self) -> &mut Vec<F>, values: impl IntoIterator<Item = F>) -> Self
```

Adds `values` to the list (`With<TField>(ref List<TField>? field, IEnumerable<TField>
values)`).

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.ReactiveUI.Testing/i_builder_extensions.rs#L56)

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

### with_value

```rust
fn with_value<F>(self: Self, field: impl FnOnce(&mut Self) -> &mut Vec<F>, value: F) -> Self
```

Adds `value` to the list (`With<TField>(ref List<TField>? field, TField value)`).

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.ReactiveUI.Testing/i_builder_extensions.rs#L62)

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

### with_pair

```rust
fn with_pair<K: Eq + Hash, F>(self: Self, dictionary: impl FnOnce(&mut Self) -> &mut HashMap<K, F>, key_value_pair: (K, F)) -> Self
```

Adds the key and value of `key_value_pair` to the dictionary
(`With<TKey, TField>(ref Dictionary<TKey, TField>, KeyValuePair<TKey, TField>)`).
## Panics
When the dictionary holds the key, as `Dictionary.Add` throws.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.ReactiveUI.Testing/i_builder_extensions.rs#L72)

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

### with_key_value

```rust
fn with_key_value<K: Eq + Hash, F>(self: Self, dictionary: impl FnOnce(&mut Self) -> &mut HashMap<K, F>, key: K, value: F) -> Self
```

Adds `key` with `value` to the dictionary
(`With<TKey, TField>(ref Dictionary<TKey, TField>, TKey, TField)`).
## Panics
When the dictionary holds the key, as `Dictionary.Add` throws.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.ReactiveUI.Testing/i_builder_extensions.rs#L82)

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

### with_dictionary

```rust
fn with_dictionary<K: Eq + Hash + Clone, F: Clone>(self: Self, dictionary: impl FnOnce(&mut Self) -> &mut HashMap<K, F>, values: &HashMap<K, F>) -> Self
```

Replaces the dictionary with a copy of `values`
(`With<TKey, TField>(ref Dictionary<TKey, TField>, IDictionary<TKey, TField>)`).

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.ReactiveUI.Testing/i_builder_extensions.rs#L91)

## Trait implementations

- [`IBuilderExtensions`](/docs/0.5.0/api/ferroui-reactiveui-testing/trait-ibuilderextensions/)

## Availability

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