Implement {:s} for ~str and @str as well

This commit is contained in:
Alex Crichton 2013-08-14 16:47:14 -07:00
parent 680eb71564
commit 109274426a
2 changed files with 5 additions and 3 deletions

View File

@ -726,9 +726,9 @@ impl Bool for bool {
}
}
impl<'self> String for &'self str {
fn fmt(s: & &'self str, f: &mut Formatter) {
f.pad(*s);
impl<'self, T: str::Str> String for T {
fn fmt(s: &T, f: &mut Formatter) {
f.pad(s.as_slice());
}
}

View File

@ -45,6 +45,8 @@ pub fn main() {
t!(ifmt!("{:x}", 10u), "a");
t!(ifmt!("{:X}", 10u), "A");
t!(ifmt!("{:s}", "foo"), "foo");
t!(ifmt!("{:s}", ~"foo"), "foo");
t!(ifmt!("{:s}", @"foo"), "foo");
t!(ifmt!("{:p}", 0x1234 as *int), "0x1234");
t!(ifmt!("{:p}", 0x1234 as *mut int), "0x1234");
t!(ifmt!("{:d}", A), "aloha");