# BackingField

Version: 0.5.0
Framework commit: d503df2befa756e681fcdc6250e9552dc7388bea
Canonical URL: /docs/0.5.0/api/ferroui-system/component_model/trait-backingfield/

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

```rust
trait BackingField<T>
```

A backing field that a setter reads and assigns through a shared reference: a `Cell` for a
value that is `Copy`, a `RefCell` for the others (`ref T backingField`).

The setters of the reactive libraries take `&impl BackingField<T>`, so that one setter serves
both kinds of field.

```
use ferroui_system::component_model::BackingField;
use std::cell::{Cell, RefCell};

fn set<T: PartialEq>(field: &impl BackingField<T>, value: T) -> bool {
    if field.equals(&value, &|a, b| a == b) {
        return false;
    }
    field.store(value);
    true
}

let age = Cell::new(3);
assert!(set(&age, 4));
assert!(!set(&age, 4));
let name = RefCell::new(String::from("a"));
assert!(set(&name, String::from("b")));
assert_eq!(*name.borrow(), "b");
```

[View source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.System/component_model/backing_field.rs#L31)

## Members

- [`equals`](#function-equals)
- [`store`](#function-store)

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

### equals

```rust
fn equals(self: &Self, value: &T, comparer: &dyn Fn(&T, &T) -> bool) -> bool
```

Whether the value of the field equals `value` by `comparer`.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.System/component_model/backing_field.rs#L33)

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

### store

```rust
fn store(self: &Self, value: T)
```

Assigns `value` to the field.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.System/component_model/backing_field.rs#L35)

## Trait implementations

- [`BackingField<T>`](/docs/0.5.0/api/ferroui-dynamic-data/binding/use-backingfield/)

## Availability

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