From 2921bf91706ba0ed975d42b9f220a978cdecc8a6 Mon Sep 17 00:00:00 2001 From: Martin Pool Date: Tue, 22 Mar 2022 22:11:29 -0700 Subject: [PATCH] View::Message takes AsRef --- Cargo.toml | 2 +- examples/bench.rs | 2 +- src/lib.rs | 14 +++++++++++--- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index abe096c..dee9bd0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "nutmeg" -version = "0.1.0" +version = "0.1.1" edition = "2018" description = "An unopinionated progress bar library" license = "MIT" diff --git a/examples/bench.rs b/examples/bench.rs index d9d76a7..8164c28 100644 --- a/examples/bench.rs +++ b/examples/bench.rs @@ -11,7 +11,7 @@ fn main() { for i in 0..n { view.update(|model| *model = i); } - view.message(&format!( + view.message(format!( "{}ms to send {} updates; average {}ns/update", start.elapsed().as_millis(), n, diff --git a/src/lib.rs b/src/lib.rs index b739c49..e60bce1 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -162,6 +162,14 @@ is welcome. # Changelog +## 0.1.1 + +Released 2022-03-22 + +* API change: [View::message] takes the message as an `AsRef`, meaning + it may be either a `&str` or `String`. This makes the common case where + the message is the result of `format!` a little easier. + ## 0.1.0 Released 2022-03-22 @@ -567,14 +575,14 @@ impl View { /// ``` /// let view = nutmeg::View::new(0, nutmeg::Options::default()); /// // ... - /// view.message(&format!("{} splines reticulated\n", 42)); + /// view.message(format!("{} splines reticulated\n", 42)); /// ``` - pub fn message(&self, message: &str) { + pub fn message>(&self, message: S) { self.inner .lock() .as_mut() .unwrap() - .write(message.as_bytes()) + .write(message.as_ref().as_bytes()) .expect("writing message"); } }