Let ToString work with unsized types, importantly, str
.
This commit is contained in:
parent
5b3cd3900c
commit
3155b31011
@ -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();
|
||||
|
Loading…
Reference in New Issue
Block a user