Skip to content

Commit e811f88

Browse files
committed
refactor: Simplify Display implementation
use Display::fmt instead write macro. Add assertion in format_test
1 parent feca88a commit e811f88

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/lib.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ mod test_readme {
1010
mod something {}
1111
}
1212

13+
use std::fmt::Display;
1314
use delegate::delegate;
1415

1516
#[cfg(feature = "serde")]
@@ -147,9 +148,9 @@ impl TryFrom<String> for NonEmptyString {
147148
}
148149
}
149150

150-
impl std::fmt::Display for NonEmptyString {
151+
impl Display for NonEmptyString {
151152
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
152-
write!(f, "{}", self.0)
153+
Display::fmt(&self.0, f)
153154
}
154155
}
155156

@@ -202,7 +203,6 @@ mod tests {
202203
fn format_test() {
203204
let str = NonEmptyString::new("string".to_owned()).unwrap();
204205
println!("{}", &str);
205-
206-
let _str: String = str.to_string();
206+
assert_eq!(String::from("string"), str.to_string())
207207
}
208208
}

0 commit comments

Comments
 (0)