BackingField
trait · ferroui-system · v0.5.0
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");
Members
equals
fn equals(self: &Self, value: &T, comparer: &dyn Fn(&T, &T) -> bool) -> bool
Whether the value of the field equals value by comparer.
store
fn store(self: &Self, value: T)
Assigns value to the field.
Trait implementations
Availability
Extracted for aarch64-apple-darwin. Cargo features are listed in the crate index.