From 3155b3101108dc9a3be32b6cb3cf33b9e1c45a0c Mon Sep 17 00:00:00 2001 From: Huon Wilson Date: Thu, 8 Jan 2015 22:48:32 +1100 Subject: [PATCH] Let ToString work with unsized types, importantly, `str`. --- src/libcollections/string.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/libcollections/string.rs b/src/libcollections/string.rs index 1bb0be05b1e82..317f03e1b7d52 100644 --- a/src/libcollections/string.rs +++ b/src/libcollections/string.rs @@ -932,7 +932,7 @@ pub trait ToString { fn to_string(&self) -> String; } -impl ToString for T { +impl ToString for T { fn to_string(&self) -> String { use core::fmt::Writer; let mut buf = String::new(); @@ -994,6 +994,12 @@ mod tests { assert_eq!(owned.as_ref().map(|s| s.as_slice()), Some("string")); } + #[test] + fn test_unsized_to_string() { + let s: &str = "abc"; + let _: String = (*s).to_string(); + } + #[test] fn test_from_utf8() { let xs = b"hello".to_vec();