Function kobold::stateful::stateful

source ·
pub fn stateful<'a, S, F, V>(
    state: S,
    render: F
) -> Stateful<S, impl Fn(*const Hook<S::State>) -> V + 'static>where
    S: IntoState,
    F: Fn(&'a Hook<S::State>) -> V + 'static,
    V: View + 'a,
Expand description

Create a stateful View over some mutable state. The state needs to be created using the IntoState trait.

// `IntoState` is implemented for primitive values
let int_view = stateful(0, |count: &Hook<i32>| { "TODO" });

// Another easy way to create arbitrary state is using a closure...
let string_view = stateful(|| String::from("foo"), |text: &Hook<String>| { "TODO" });

// ...or a function with no parameters
let vec_view = stateful(Vec::new, |counts: &Hook<Vec<i32>>| { "TODO" });