Skip to content

Commit

Permalink
View::Message takes AsRef<str>
Browse files Browse the repository at this point in the history
  • Loading branch information
sourcefrog committed Mar 23, 2022
1 parent ef5f78d commit 2921bf9
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
2 changes: 1 addition & 1 deletion examples/bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
14 changes: 11 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,14 @@ is welcome.
# Changelog
## 0.1.1
Released 2022-03-22
* API change: [View::message] takes the message as an `AsRef<str>`, 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
Expand Down Expand Up @@ -567,14 +575,14 @@ impl<M: Model> View<M> {
/// ```
/// 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<S: AsRef<str>>(&self, message: S) {
self.inner
.lock()
.as_mut()
.unwrap()
.write(message.as_bytes())
.write(message.as_ref().as_bytes())
.expect("writing message");
}
}
Expand Down

0 comments on commit 2921bf9

Please sign in to comment.