diff --git a/NEWS.md b/NEWS.md index f285354..8f5d903 100644 --- a/NEWS.md +++ b/NEWS.md @@ -2,6 +2,10 @@ ## Unreleased +- **Breaking change:** `Render` no longer has a blanket implementation for `Display`: you can no longer use a string, integer, or some object that implements `Display` as a model directly. You must instead implement `Render` explicitly. + + It seems that the `Display` implementation is often not a very satisfactory progress bar, and the presence of the blanket implementation causes confusing error messages when `Render` is not implemented correctly. + - Change back to `std::sync::Mutex` from `parking_lot`, to keep dependencies smaller. ## 0.1.4 diff --git a/examples/string_as_model.rs b/examples/string_as_model.rs deleted file mode 100644 index 67f5eb0..0000000 --- a/examples/string_as_model.rs +++ /dev/null @@ -1,17 +0,0 @@ -//! Use a simple String as a Model, with no need to `impl Model`. - -use std::fs::read_dir; -use std::io; -use std::thread::sleep; -use std::time::Duration; - -fn main() -> io::Result<()> { - let options = nutmeg::Options::default(); - let view = nutmeg::View::new(String::new(), options); - for p in read_dir(".")? { - let dir_entry = p?; - view.update(|model| *model = dir_entry.path().display().to_string()); - sleep(Duration::from_millis(300)); - } - Ok(()) -} diff --git a/src/lib.rs b/src/lib.rs index 4e1df26..e256062 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -20,12 +20,11 @@ processed, the amount of data transmitted or received, the currently active task The Model can be any of these things, from simplest to most powerful: -1. Any type that implements [std::fmt::Display], such as a String or integer. -2. One of the provided [models]. -3. An application-defined struct (or enum or other type) that implements [Model]. +1. One of the provided [models]. +2. An application-defined struct (or enum or other type) that implements [Model]. The model is responsible for rendering itself into a String, optionally with ANSI styling, -by implementing [Model::render] (or [std::fmt::Display]). Applications might +by implementing [Model::render]. Applications might choose to use any of the Rust crates that can render ANSI control codes into a string, such as yansi. @@ -211,7 +210,6 @@ is welcome. #![warn(missing_docs)] -use std::fmt::Display; use std::io::{self, Write}; use std::sync::{Arc, Mutex}; use std::time::Instant; @@ -292,29 +290,6 @@ pub trait Model { } } -/// Blanket implementation of Model for Display. -/// -/// `self` is converted to a display string without regard for -/// the terminal width. -/// -/// This allows direct use of e.g. a String or integer as a model -/// for very basic progress indications. -/// -/// ``` -/// use nutmeg::{Options, View}; -/// -/// let view = View::new(0, Options::default()); -/// view.update(|model| *model += 1); -/// ``` -impl Model for T -where - T: Display, -{ - fn render(&mut self, _width: usize) -> String { - self.to_string() - } -} - /// A view that draws and coordinates a progress bar on the terminal. /// /// There should be only one `View` active on a terminal at any time, and