Skip to content

Commit 2921bf9

Browse files
committed
View::Message takes AsRef<str>
1 parent ef5f78d commit 2921bf9

File tree

3 files changed

+13
-5
lines changed

3 files changed

+13
-5
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "nutmeg"
3-
version = "0.1.0"
3+
version = "0.1.1"
44
edition = "2018"
55
description = "An unopinionated progress bar library"
66
license = "MIT"

examples/bench.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ fn main() {
1111
for i in 0..n {
1212
view.update(|model| *model = i);
1313
}
14-
view.message(&format!(
14+
view.message(format!(
1515
"{}ms to send {} updates; average {}ns/update",
1616
start.elapsed().as_millis(),
1717
n,

src/lib.rs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,14 @@ is welcome.
162162
163163
# Changelog
164164
165+
## 0.1.1
166+
167+
Released 2022-03-22
168+
169+
* API change: [View::message] takes the message as an `AsRef<str>`, meaning
170+
it may be either a `&str` or `String`. This makes the common case where
171+
the message is the result of `format!` a little easier.
172+
165173
## 0.1.0
166174
167175
Released 2022-03-22
@@ -567,14 +575,14 @@ impl<M: Model> View<M> {
567575
/// ```
568576
/// let view = nutmeg::View::new(0, nutmeg::Options::default());
569577
/// // ...
570-
/// view.message(&format!("{} splines reticulated\n", 42));
578+
/// view.message(format!("{} splines reticulated\n", 42));
571579
/// ```
572-
pub fn message(&self, message: &str) {
580+
pub fn message<S: AsRef<str>>(&self, message: S) {
573581
self.inner
574582
.lock()
575583
.as_mut()
576584
.unwrap()
577-
.write(message.as_bytes())
585+
.write(message.as_ref().as_bytes())
578586
.expect("writing message");
579587
}
580588
}

0 commit comments

Comments
 (0)