pub trait Binding<S>:
Clone
+ Copy
+ 'static {
// Required methods
fn get<'a>(&self, cx: &'a Context) -> &'a S;
fn get_mut<'a>(&self, cx: &'a mut Context) -> &'a mut S;
// Provided methods
fn with<T>(&self, cx: &Context, f: impl FnOnce(&S) -> T) -> T { ... }
fn with_mut<T>(&self, cx: &mut Context, f: impl FnOnce(&mut S) -> T) -> T { ... }
}Expand description
Reads or writes a value owned by a source-of-truth.
Required Methods§
fn get<'a>(&self, cx: &'a Context) -> &'a S
fn get_mut<'a>(&self, cx: &'a mut Context) -> &'a mut S
Provided Methods§
Sourcefn with_mut<T>(&self, cx: &mut Context, f: impl FnOnce(&mut S) -> T) -> T
fn with_mut<T>(&self, cx: &mut Context, f: impl FnOnce(&mut S) -> T) -> T
Examples found in repository?
examples/todo_list.rs (line 9)
3fn add_button(todos: impl Binding<Vec<String>>) -> impl View {
4 state(String::new, move |name, _| {
5 hstack((
6 text_editor(name),
7 button(text("Add Item"), move |cx| {
8 let name_str = cx[name].clone();
9 todos.with_mut(cx, |todos| todos.push(name_str));
10 // Gotta fix a bug in text_editor!
11 // cx[name] = String::new();
12 }),
13 ))
14 })
15}Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.