pub trait BackingField<T> {
// Required methods
fn equals(&self, value: &T, comparer: &dyn Fn(&T, &T) -> bool) -> bool;
fn store(&self, value: T);
}Expand description
A backing field that AbstractNotifyPropertyChanged::set_and_raise reads and assigns: a
Cell for a value that is Copy, a RefCell for the others (ref T backingField). It is
ferroui-system’s, which the reactive objects of ferroui-reactiveui share.
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");Required Methods§
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".