Struct BasicModel

Source
pub struct BasicModel<T, R>
where R: FnMut(&mut T) -> String,
{ 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>
where R: FnMut(&mut T) -> String,

Source

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.

Trait Implementations§

Source§

impl<T, R> Model for BasicModel<T, R>
where R: FnMut(&mut T) -> String,

Source§

fn render(&mut self, _width: usize) -> String

Render this model into a string to draw on the console. Read more
Source§

fn final_message(&mut self) -> String

Optionally render a final message when the view is finished. Read more

Auto Trait Implementations§

§

impl<T, R> Freeze for BasicModel<T, R>
where T: Freeze, R: Freeze,

§

impl<T, R> RefUnwindSafe for BasicModel<T, R>

§

impl<T, R> Send for BasicModel<T, R>
where T: Send, R: Send,

§

impl<T, R> Sync for BasicModel<T, R>
where T: Sync, R: Sync,

§

impl<T, R> Unpin for BasicModel<T, R>
where T: Unpin, R: Unpin,

§

impl<T, R> UnwindSafe for BasicModel<T, R>
where T: UnwindSafe, R: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.