diff options
| author | Alex Crichton <alex@alexcrichton.com> | 2013-08-14 16:47:14 -0700 |
|---|---|---|
| committer | Alex Crichton <alex@alexcrichton.com> | 2013-08-16 16:09:33 -0700 |
| commit | 109274426a7cd676b9aa1bb06afd9f86b44f6e9b (patch) | |
| tree | c2be5999e3be9619d9df6952511b6a1ee59fc34e | |
| parent | 680eb71564ebba5e76ce1e1a8287b30042332cc5 (diff) | |
| download | rust-109274426a7cd676b9aa1bb06afd9f86b44f6e9b.tar.gz rust-109274426a7cd676b9aa1bb06afd9f86b44f6e9b.zip | |
Implement `{:s}` for ~str and @str as well
| -rw-r--r-- | src/libstd/fmt/mod.rs | 6 | ||||
| -rw-r--r-- | src/test/run-pass/ifmt.rs | 2 |
2 files changed, 5 insertions, 3 deletions
diff --git a/src/libstd/fmt/mod.rs b/src/libstd/fmt/mod.rs index 70ec5d93199..cd3f85e83fa 100644 --- a/src/libstd/fmt/mod.rs +++ b/src/libstd/fmt/mod.rs @@ -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()); } } diff --git a/src/test/run-pass/ifmt.rs b/src/test/run-pass/ifmt.rs index a0d3eb7d803..8076c081e87 100644 --- a/src/test/run-pass/ifmt.rs +++ b/src/test/run-pass/ifmt.rs @@ -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"); |
