From ce6a4a2a2b2d8a6fb41f326f0ced22b38dc04b1d Mon Sep 17 00:00:00 2001 From: Georg Brandl Date: Mon, 12 Nov 2018 19:30:13 +0100 Subject: [PATCH] implement Display for String --- src/string.rs | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/src/string.rs b/src/string.rs index 7d8a01c2..943c86b3 100644 --- a/src/string.rs +++ b/src/string.rs @@ -407,7 +407,17 @@ where { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { let slice: &str = &**self; - slice.fmt(f) + fmt::Debug::fmt(slice, f) + } +} + +impl fmt::Display for String +where + N: ArrayLength, +{ + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + let slice: &str = &**self; + fmt::Display::fmt(slice, f) } } @@ -538,6 +548,18 @@ mod tests { assert_eq!("\"abcd\"", std_s); } + #[test] + fn display() { + extern crate std; + + use core::fmt::Write; + + let s: String = String::from("abcd"); + let mut std_s = std::string::String::new(); + write!(std_s, "{}", s).unwrap(); + assert_eq!("abcd", std_s); + } + #[test] fn empty() { let s: String = String::new();