]> git.lizzy.rs Git - rust.git/commitdiff
Let ToString work with unsized types, importantly, `str`.
authorHuon Wilson <dbau.pp+github@gmail.com>
Thu, 8 Jan 2015 11:48:32 +0000 (22:48 +1100)
committerHuon Wilson <dbau.pp+github@gmail.com>
Thu, 8 Jan 2015 11:48:32 +0000 (22:48 +1100)
src/libcollections/string.rs

index 1bb0be05b1e82e51b956aa6542e9ec19db0f880d..317f03e1b7d52d966e34752a33d47f40a92d6a87 100644 (file)
@@ -932,7 +932,7 @@ pub trait ToString {
     fn to_string(&self) -> String;
 }
 
-impl<T: fmt::String> ToString for T {
+impl<T: fmt::String + ?Sized> ToString for T {
     fn to_string(&self) -> String {
         use core::fmt::Writer;
         let mut buf = String::new();
@@ -994,6 +994,12 @@ fn test_from_str() {
       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();