pub struct BasicModel<T, R>{
pub value: T,
/* private fields */
}
Expand description
A model that stores any user-provided type, and renders by calling a function provided in the constructor.
For many simple cases this avoids any need to explicitly declare a model class: instead the View::new call can, in-line, construct a BasicView giving an initial value and a render function.
§Example
let view = nutmeg::View::new(
nutmeg::models::BasicModel::new((0, 10), |(a, b)| format!("{}/{} complete", a, b)),
nutmeg::Options::default(),
);
for _i in 0..10 {
// Note that the callback should update `model.value`, which is the user-defined
// type.
view.update(|model| model.value.0 += 1);
// ...
}
Fields§
§value: T
The current inner value of the model.
The type T
and initial value are set by the first parameter to
BasicModel::new.
The functions passed to View::update take a model
as a parameter
and should typically act on model.value
.
Implementations§
Source§impl<T, R> BasicModel<T, R>
impl<T, R> BasicModel<T, R>
Sourcepub fn new(value: T, render_fn: R) -> BasicModel<T, R>
pub fn new(value: T, render_fn: R) -> BasicModel<T, R>
Construct a new BasicModel.
value
is the initial inner value of the model. It may be any type
but might typically be an integer, a string, or a tuple of simple
values.
render_fn
takes an &mut T
and renders it to a string to be
drawn in the progress bar.